changeset b36ff394e6a8 in modules/account:5.0
details: https://hg.tryton.org/modules/account?cmd=changeset;node=b36ff394e6a8
description:
        Reverse type of taxes from cancelled move

        A tax line from a cancelled move must be reported with the same type as 
the
        original move. For that we check of the debit or credit is negative to 
detect
        it is a cancelled move.

        issue9743
        review328531002
        (grafted from 75da9fcb853364e50013e625629fe911219cb79a)
diffstat:

 tax.py |  42 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 36 insertions(+), 6 deletions(-)

diffs (67 lines):

diff -r c73d8d1545e4 -r b36ff394e6a8 tax.py
--- a/tax.py    Sun Oct 25 11:02:23 2020 +0100
+++ b/tax.py    Wed Oct 28 23:53:53 2020 +0100
@@ -386,9 +386,27 @@
             ('type', '=', self.amount),
             ]
         if self.type == 'invoice':
-            domain.append(('amount', '>', 0))
+            domain.append(['OR',
+                    [('amount', '>', 0), ['OR',
+                            ('move_line.debit', '>', 0),
+                            ('move_line.credit', '>', 0),
+                            ]],
+                    [('amount', '<', 0), ['OR',
+                            ('move_line.debit', '<', 0),
+                            ('move_line.credit', '<', 0),
+                            ]],
+                    ])
         elif self.type == 'credit':
-            domain.append(('amount', '<', 0))
+            domain.append(['OR',
+                    [('amount', '<', 0), ['OR',
+                            ('move_line.debit', '>', 0),
+                            ('move_line.credit', '>', 0),
+                            ]],
+                    [('amount', '>', 0), ['OR',
+                            ('move_line.debit', '<', 0),
+                            ('move_line.credit', '<', 0),
+                            ]],
+                    ])
         return domain
 
     @classmethod
@@ -786,17 +804,29 @@
 
         columns = []
         amount = tax_line.amount
+        debit = move_line.debit
+        credit = move_line.credit
         if backend.name() == 'sqlite':
             amount = TaxLine.amount.sql_cast(tax_line.amount)
+            debit = MoveLine.debit.sql_cast(debit)
+            credit = MoveLine.credit.sql_cast(credit)
+        is_invoice = (
+            ((amount > 0) & ((debit > 0) | (credit > 0)))
+            | ((amount < 0) & ((debit < 0) | (credit < 0)))
+            )
+        is_credit = (
+            ((amount < 0) & ((debit > 0) | (credit > 0)))
+            | ((amount > 0) & ((debit < 0) | (credit < 0)))
+            )
         for name, clause in [
                 ('invoice_base_amount',
-                    (amount > 0) & (tax_line.type == 'base')),
+                    is_invoice & (tax_line.type == 'base')),
                 ('invoice_tax_amount',
-                    (amount > 0) & (tax_line.type == 'tax')),
+                    is_invoice & (tax_line.type == 'tax')),
                 ('credit_base_amount',
-                    (amount < 0) & (tax_line.type == 'base')),
+                    is_credit & (tax_line.type == 'base')),
                 ('credit_tax_amount',
-                    (amount < 0) & (tax_line.type == 'tax')),
+                    is_credit & (tax_line.type == 'tax')),
                 ]:
             if name not in names:
                 continue

Reply via email to