line: selection of digits for quantity
This commit is contained in:
parent
e96aa6fad7
commit
f7109b013f
2 changed files with 41 additions and 18 deletions
57
line.py
57
line.py
|
@ -622,18 +622,31 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
return self.booktransf.quantity_uom.id
|
||||
|
||||
@fields.depends('feature', 'cashbook', '_parent_cashbook.quantity_digits', \
|
||||
'booktransf', '_parent_booktransf.quantity_digits', '_parent_booktransf.feature')
|
||||
'booktransf', '_parent_booktransf.quantity_digits',\
|
||||
'_parent_booktransf.feature', 'bookingtype')
|
||||
def on_change_with_quantity_digits(self, name=None):
|
||||
""" get digits from cashbook
|
||||
"""
|
||||
digits = 0
|
||||
if self.feature == 'asset':
|
||||
if self.cashbook:
|
||||
return self.cashbook.quantity_digits
|
||||
else :
|
||||
if self.booktransf:
|
||||
if self.booktransf.feature == 'asset':
|
||||
return self.booktransf.quantity_digits
|
||||
return 4
|
||||
digits = self.cashbook.quantity_digits \
|
||||
if self.cashbook.quantity_digits > digits else digits
|
||||
else:
|
||||
if self.bookingtype in ['mvin', 'mvout']:
|
||||
if self.booktransf:
|
||||
if self.booktransf.feature == 'asset':
|
||||
digits = self.booktransf.quantity_digits \
|
||||
if self.booktransf.quantity_digits > digits \
|
||||
else digits
|
||||
elif self.bookingtype in ['spin', 'spout']:
|
||||
for spline in self.splitlines:
|
||||
if spline.booktransf:
|
||||
if spline.booktransf.feature == 'asset':
|
||||
digits = spline.booktransf.quantity_digits \
|
||||
if spline.booktransf.quantity_digits > digits \
|
||||
else digits
|
||||
return digits
|
||||
|
||||
@classmethod
|
||||
def validate(cls, lines):
|
||||
|
@ -649,20 +662,21 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
# quantity must be set
|
||||
if (line.quantity is None) or \
|
||||
(line.quantity_credit is None) or \
|
||||
(line.quantity_debit is None):
|
||||
(line.quantity_debit is None):
|
||||
raise UserError(gettext(
|
||||
'cashbook_investment.msg_line_quantity_not_set',
|
||||
linetxt = line.rec_name,
|
||||
linetxt=line.rec_name,
|
||||
))
|
||||
|
||||
# quantity and amount must with same sign
|
||||
if (line.amount != Decimal('0.0')) and (line.quantity != Decimal('0.0')):
|
||||
if (line.amount != Decimal('0.0')) and \
|
||||
(line.quantity != Decimal('0.0')):
|
||||
(amount_sign, a_dig, a_exp) = line.amount.as_tuple()
|
||||
(quantity_sign, q_dig, q_exp) = line.quantity.as_tuple()
|
||||
if amount_sign != quantity_sign:
|
||||
raise UserError(gettext(
|
||||
'cashbook_investment.msg_line_sign_mismatch',
|
||||
linetxt = line.rec_name,
|
||||
linetxt=line.rec_name,
|
||||
))
|
||||
|
||||
@classmethod
|
||||
|
@ -673,9 +687,10 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
|
||||
for line in lines:
|
||||
cnt1 = sum([1 for x in line.splitlines if x.quantity is not None])
|
||||
quantity = sum([x.quantity or Decimal('0.0') for x in line.splitlines])
|
||||
quantity = sum([
|
||||
x.quantity or Decimal('0.0') for x in line.splitlines])
|
||||
if (cnt1 > 0) and (quantity != line.quantity):
|
||||
to_write.extend([ [line], {'quantity': quantity,} ])
|
||||
to_write.extend([[line], {'quantity': quantity, }])
|
||||
return to_write
|
||||
|
||||
@classmethod
|
||||
|
@ -684,12 +699,18 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
"""
|
||||
values = super(Line, cls).add_values_from_splitlines(values)
|
||||
|
||||
if ('splitlines' in values.keys()) and ('quantity' not in values.keys()):
|
||||
if ('splitlines' in values.keys()) and \
|
||||
('quantity' not in values.keys()):
|
||||
for action in values['splitlines']:
|
||||
quantity = None
|
||||
if action[0] == 'create':
|
||||
cnt1 = sum([1 for x in action[1] if x.get('quantity', None) is not None])
|
||||
quantity = sum([x.get('quantity', Decimal('0.0')) for x in action[1]])
|
||||
cnt1 = sum([
|
||||
1 for x in action[1]
|
||||
if x.get('quantity', None) is not None
|
||||
])
|
||||
quantity = sum([
|
||||
x.get('quantity', Decimal('0.0')) for x in action[1]
|
||||
])
|
||||
if cnt1 > 0:
|
||||
values['quantity'] = quantity
|
||||
return values
|
||||
|
@ -704,7 +725,9 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
cashbook = values.get('cashbook', None)
|
||||
|
||||
if cashbook:
|
||||
values.update(cls.add_2nd_quantity(values, Cashbook(cashbook).quantity_uom))
|
||||
values.update(cls.add_2nd_quantity(
|
||||
values,
|
||||
Cashbook(cashbook).quantity_uom))
|
||||
return values
|
||||
|
||||
# end Line
|
||||
|
|
|
@ -658,7 +658,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
|||
}])
|
||||
self.assertEqual(books[1].lines[0].rec_name,
|
||||
'05/01/2022|Rev|1.00 usd|- [Cat1]')
|
||||
self.assertEqual(books[1].lines[0].quantity_digits, 4)
|
||||
self.assertEqual(books[1].lines[0].quantity_digits, 0)
|
||||
|
||||
Book.write(*[
|
||||
[books[1]],
|
||||
|
|
Loading…
Reference in a new issue