line: rec_name with quantity, optimize get_counterpart_values(),

splitline: rec_name with quantity, optimize list/form, add tests
This commit is contained in:
Frederik Jaeckel 2023-01-21 18:46:00 +01:00
parent a397fe22a2
commit 03c552a29c
6 changed files with 927 additions and 22 deletions

29
line.py
View file

@ -90,9 +90,11 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
"""
recname = super(Line, self).get_rec_name(name)
if self.cashbook.feature == 'asset':
credit = self.quantity_credit if self.quantity_credit is not None else Decimal('0.0')
debit = self.quantity_debit if self.quantity_debit is not None else Decimal('0.0')
recname += '|%(quantity)s %(uom_symbol)s' % {
'quantity': Report.format_number(self.quantity or 0.0, None,
digits=self.quantity_digits),
'quantity': Report.format_number(credit - debit,
lang=None, digits=self.quantity_digits),
'uom_symbol': self.quantity_uom.symbol,
}
return recname
@ -109,13 +111,17 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
def get_debit_credit(cls, values, line=None):
""" compute quantity_debit/quantity_credit from quantity
"""
Cashbook = Pool().get('cashbook.book')
pool = Pool()
Cashbook = pool.get('cashbook.book')
Line2 = pool.get('cashbook.line')
result = super(Line, cls).get_debit_credit(values, line)
if line:
cashbook = line.cashbook
else:
id_cashbook = values.get('cashbook', None)
if id_cashbook is None:
id_cashbook = Line2.default_cashbook()
cashbook = None
if id_cashbook:
cashbook = Cashbook.browse([id_cashbook])[0]
@ -158,9 +164,22 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
if getattr(splitline, 'quantity', None) is not None:
# we add values to the counterpart of a splitbooking-line
asset_books = sum([
1 if splitline.feature == 'asset' else 0,
1 if getattr(splitline.booktransf, 'feature', '-') == 'asset' else 0,
])
diff_uom = False
if asset_books == 2:
diff_uom = (splitline.quantity_uom != splitline.booktransf.quantity_uom) and \
(splitline.quantity_uom is not None) and \
(splitline.booktransf.quantity_uom is not None)
result.update({
'quantity': splitline.quantity,
'quantity_2nd_uom': None,
'quantity': splitline.quantity_2nd_uom \
if (asset_books == 2) and (diff_uom == True) \
else splitline.quantity,
'quantity_2nd_uom': splitline.quantity \
if (asset_books == 2) and (diff_uom == True) else None,
})
elif booktransf_uom is None:
# counterpart-cashbook has no uom -> no quantity