From e9f90b7944c138d856422be4789b798b0a913be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 12 Dec 2023 17:02:31 +0100 Subject: [PATCH] Use 0 as fallback for missing debit or credit in on_change functions Closes #12823 --- modules/account/move.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/account/move.py b/modules/account/move.py index 1ffafd8398..f5ba5eb2d1 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -1106,7 +1106,7 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): def on_change_move(self): if self.move: if not self.debit and not self.credit: - total = sum(l.debit - l.credit + total = sum((l.debit or 0) - (l.credit or 0) for l in getattr(self.move, 'lines', [])) self.debit = -total if total < 0 else Decimal(0) self.credit = total if total > 0 else Decimal(0) @@ -1177,7 +1177,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): 'Set correct sign to amount_second_currency' if self.amount_second_currency: self.amount_second_currency = \ - self.amount_second_currency.copy_sign(self.debit - self.credit) + self.amount_second_currency.copy_sign( + (self.debit or 0) - (self.credit or 0)) @fields.depends('account') def on_change_account(self): @@ -2455,9 +2456,11 @@ class ReconcileShow(ModelView): if self.currency: for line in self.lines: if line.second_currency == self.currency: - amount += line.amount_second_currency + amount += ( + line.amount_second_currency or 0) elif line.currency == self.currency: - amount += line.debit - line.credit + amount += ( + (line.debit or 0) - (line.credit or 0)) amount = self.currency.round(amount) self.write_off_amount = amount