Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
4496c3d2 by Cédric Krier at 2023-03-30T23:56:59+02:00
Compute deferral remainder using balance of income account

Closes #12168
- - - - -


1 changed file:

- modules/account_invoice_defer/account.py


Changes:

=====================================
modules/account_invoice_defer/account.py
=====================================
@@ -284,15 +284,9 @@
                 last_move = deferral.moves[-1]
                 if last_move.period.end_date >= deferral.end_date:
                     remainder = deferral.amount_remainder
-                    if remainder > 0:
-                        for line in last_move.lines:
-                            if line.debit:
-                                line.debit += remainder
-                            else:
-                                line.credit += remainder
-                    elif remainder < 0:
+                    if remainder:
                         for line in last_move.lines:
                             if line.debit:
                                 line.debit -= remainder
                             else:
                                 line.credit -= remainder
@@ -294,9 +288,9 @@
                         for line in last_move.lines:
                             if line.debit:
                                 line.debit -= remainder
                             else:
                                 line.credit -= remainder
-                    if remainder:
+                        last_move.lines = last_move.lines
                         to_save.append(last_move)
         Move.save(to_save)
         Move.post(moves)
@@ -308,10 +302,13 @@
 
     @property
     def amount_remainder(self):
-        period = self.invoice_line.invoice.move.period
-        return abs(self.amount) - sum(
-            l.credit for m in self.moves for l in m.lines
-            if m.period != period)
+        balance = 0
+        for move in self.moves:
+            income_account = self.invoice_line.account.current(move.date)
+            for line in move.lines:
+                if line.account == income_account:
+                    balance += line.debit - line.credit
+        return balance
 
     def get_move(self, period=None):
         pool = Pool()



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/4496c3d2f4d8220ca2daeb6747473545e40df430

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/4496c3d2f4d8220ca2daeb6747473545e40df430
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to