line: calculate quantity on changes in splitlines + tests
todo: tests
This commit is contained in:
parent
bf84b092fc
commit
7ff631d850
4 changed files with 185 additions and 2 deletions
37
line.py
37
line.py
|
@ -30,6 +30,14 @@ STATESQ1 = {
|
|||
DEPENDSQ1 = ['feature', 'booktransf_feature', 'quantity_digits', 'bookingtype']
|
||||
DEPENDSQ1.extend(DEPENDS)
|
||||
|
||||
STATESQ1B = {}
|
||||
STATESQ1B.update(STATESQ1)
|
||||
STATESQ1B['invisible'] = And(
|
||||
Eval('feature', '') != 'asset',
|
||||
Eval('booktransf_feature', '') != 'asset',
|
||||
Eval('splitline_has_quantity', False) == False,
|
||||
)
|
||||
|
||||
|
||||
STATESQ2 = {
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
|
@ -43,7 +51,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
|
||||
quantity = fields.Numeric(string='Quantity',
|
||||
digits=(16, Eval('quantity_digits', 4)),
|
||||
states=STATESQ1, depends=DEPENDSQ1)
|
||||
states=STATESQ1B, depends=DEPENDSQ1+['splitline_has_quantity'])
|
||||
quantity_credit = fields.Numeric(string='Quantity Credit',
|
||||
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||
states=STATESQ2, depends=DEPENDSQ2)
|
||||
|
@ -73,6 +81,9 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['quantity_digits', 'feature']),
|
||||
'on_change_with_quantity_balance')
|
||||
splitline_has_quantity = fields.Function(fields.Boolean(
|
||||
string='has quantity', readonly=True, states={'invisible': True}),
|
||||
'on_change_with_splitline_has_quantity')
|
||||
|
||||
def get_rec_name(self, name):
|
||||
""" add quantities - if its a asset-cashbook
|
||||
|
@ -165,6 +176,30 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
})
|
||||
return result
|
||||
|
||||
@fields.depends('amount', 'splitlines', 'quantity')
|
||||
def on_change_splitlines(self):
|
||||
""" update amount if splitlines change
|
||||
"""
|
||||
super(Line, self).on_change_splitlines()
|
||||
quantity = sum([x.quantity for x in self.splitlines if x.quantity is not None])
|
||||
cnt1 = sum([1 for x in self.splitlines if x.quantity is not None])
|
||||
if cnt1 > 0:
|
||||
self.quantity = quantity
|
||||
|
||||
@fields.depends('splitlines')
|
||||
def on_change_with_splitline_has_quantity(self, name=None):
|
||||
""" get True if splitlines are linked to asset-cashbooks
|
||||
"""
|
||||
result = False
|
||||
for line in self.splitlines:
|
||||
if line.splittype != 'tr':
|
||||
continue
|
||||
if line.booktransf:
|
||||
if line.booktransf.feature == 'asset':
|
||||
result = True
|
||||
break
|
||||
return result
|
||||
|
||||
@fields.depends('id', 'date', 'cashbook', 'feature',\
|
||||
'_parent_cashbook.id', 'reconciliation', \
|
||||
'_parent_reconciliation.start_quantity',\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue