changeset 75da9fcb8533 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset;node=75da9fcb8533
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
diffstat:

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

diffs (67 lines):

diff -r 8d7d34ab4e48 -r 75da9fcb8533 tax.py
--- a/tax.py    Wed Oct 28 23:44:17 2020 +0100
+++ b/tax.py    Wed Oct 28 23:53:53 2020 +0100
@@ -390,9 +390,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
@@ -804,17 +822,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