Nicolas Évrard pushed to branch branch/default at Tryton / Tryton


Commits:
aae76984 by Nicolas Évrard at 2023-01-23T17:05:55+01:00
Reconcile the zero lines after saving moves
- - - - -
4b397c60 by Nicolas Évrard at 2023-01-29T01:08:22+01:00
Save moves before reconciling the lines

The previous organization of the code made it less efficient to save the move
before reconciling the lines which should the logical order.
- - - - -


2 changed files:

- modules/account/move.py
- modules/account/tests/test_module.py


Changes:

=====================================
modules/account/move.py
=====================================
@@ -479,8 +479,10 @@
                     move.post_date = Date.today()
                 move.post_number = move.period.post_move_sequence_used.get()
 
+        cls.save(moves)
+
         def keyfunc(line):
             return line.party, line.account
         to_reconcile = Line.browse(sorted(
                 [l for l in Line.browse(to_reconcile) if l.account.reconcile],
                 key=keyfunc))
@@ -482,12 +484,11 @@
         def keyfunc(line):
             return line.party, line.account
         to_reconcile = Line.browse(sorted(
                 [l for l in Line.browse(to_reconcile) if l.account.reconcile],
                 key=keyfunc))
-        for _, lines in groupby(to_reconcile, keyfunc):
-            Line.reconcile(list(lines))
-
-        cls.save(moves)
+        to_reconcile = [list(l) for _, l in groupby(to_reconcile, keyfunc)]
+        if to_reconcile:
+            Line.reconcile(*to_reconcile)
 
 
 class Reconciliation(ModelSQL, ModelView):


=====================================
modules/account/tests/test_module.py
=====================================
@@ -655,6 +655,22 @@
 
             self.assertEqual(move.state, 'posted')
 
+            # Move lines with debit = credit = 0 are automatically reconciled
+            move = Move()
+            move.period = period
+            move.journal = journal_revenue
+            move.date = period.start_date
+            move.lines = [
+                Line(account=revenue, credit=Decimal(0)),
+                Line(account=receivable, debit=Decimal(0), party=party),
+                ]
+            move.save()
+            Move.post([move])
+
+            lines = Line.browse([l.id for l in move.lines
+                    if l.account.reconcile])
+            self.assertTrue(all(bool(l.reconciliation) for l in lines))
+
             # Can not post an empty move
             with self.assertRaises(UserError):
                 move = Move()



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/5ae35a13f92c66ff0463a8af483dd7d342576235...4b397c60092aa03a1bb5147938ef872f052f94a9

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/5ae35a13f92c66ff0463a8af483dd7d342576235...4b397c60092aa03a1bb5147938ef872f052f94a9
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to