issue12823.diff [account] Use 0 as fallback for missing debit or credit in on_change functions

#163599
This commit is contained in:
Raimon Esteve 2023-12-13 15:03:35 +01:00
parent b5a3b00fb9
commit b4f4c0dd2a
2 changed files with 25 additions and 0 deletions

23
issue12823.diff Normal file
View File

@ -0,0 +1,23 @@
diff --git a/tryton/modules/account/move.py b/tryton/modules/account/move.py
index 123755b2e9..564a9dc7db 100644
--- a/tryton/modules/account/move.py
+++ b/tryton/modules/account/move.py
@@ -946,7 +946,7 @@ class Line(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)
@@ -1014,7 +1014,8 @@ class Line(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):

2
series
View File

@ -139,3 +139,5 @@ issue7707.diff # [sao] Improve tree view #163452
issue12799.diff # [sao] Convert negative id value as None when set by the client
issue12547.diff # [stock_lot] Check lot required only when changing move to done
issue12823.diff # [account] Use 0 as fallback for missing debit or credit in on_change functions