changeset d2a32b625e72 in modules/account_invoice:default
details: 
https://hg.tryton.org/modules/account_invoice?cmd=changeset;node=d2a32b625e72
description:
        Allow setting the tax date on taxable lines

        We add a taxing date to the invoice line which allow overriding the 
value of
        the invoice.
        When crediting an invoice, the original tax date of each line is stored 
on the
        credit line so the tax are computed the same way.

        issue9520
        review323791002
diffstat:

 CHANGELOG                  |   1 +
 invoice.py                 |  36 +++++++++++++++++++++---------------
 tests/scenario_invoice.rst |   6 ++++++
 view/invoice_line_form.xml |   4 ++++
 4 files changed, 32 insertions(+), 15 deletions(-)

diffs (109 lines):

diff -r af9bc17b3972 -r d2a32b625e72 CHANGELOG
--- a/CHANGELOG Sat Sep 05 22:12:11 2020 +0200
+++ b/CHANGELOG Sat Sep 05 23:37:58 2020 +0200
@@ -1,3 +1,4 @@
+* Add optional taxes date on invoice line
 * Convert Invoice.update_taxes into dualmethod
 * Rename invoice state from cancel to cancelled
 
diff -r af9bc17b3972 -r d2a32b625e72 invoice.py
--- a/invoice.py        Sat Sep 05 22:12:11 2020 +0200
+++ b/invoice.py        Sat Sep 05 23:37:58 2020 +0200
@@ -820,20 +820,9 @@
     @property
     def taxable_lines(self):
         taxable_lines = []
-        # In case we're called from an on_change we have to use some sensible
-        # defaults
         for line in self.lines:
-            if getattr(line, 'type', None) != 'line':
-                continue
-            taxable_lines.append(tuple())
-            for attribute, default_value in [
-                    ('taxes', []),
-                    ('unit_price', Decimal(0)),
-                    ('quantity', 0.),
-                    ]:
-                value = getattr(line, attribute, None)
-                taxable_lines[-1] += (
-                    value if value is not None else default_value,)
+            if getattr(line, 'type', None) == 'line':
+                taxable_lines.extend(line.taxable_lines)
         return taxable_lines
 
     @property
@@ -1744,6 +1733,15 @@
             'readonly': _states['readonly'] | ~Bool(Eval('account')),
             },
         depends=['type', 'invoice_type', 'company', 'account'] + _depends)
+    taxes_date = fields.Date(
+        "Taxes Date",
+        states={
+            'invisible': Eval('type') != 'line',
+            'readonly': _states['readonly'],
+            },
+        depends=['type'] + _depends,
+        help="The date at which the taxes are computed.\n"
+        "Leave empty for the accounting date.")
     invoice_taxes = fields.Function(fields.Many2Many('account.invoice.tax',
         None, None, 'Invoice Taxes'), 'get_invoice_taxes')
     origin = fields.Reference('Origin', selection='get_origin', select=True,
@@ -1920,11 +1918,18 @@
 
     @property
     def taxable_lines(self):
-        return [(self.taxes, self.unit_price, self.quantity)]
+        # In case we're called from an on_change we have to use some sensible
+        # defaults
+        return [(
+                getattr(self, 'taxes', None) or [],
+                getattr(self, 'unit_price', None) or Decimal(0),
+                getattr(self, 'quantity', None) or 0,
+                getattr(self, 'tax_date', None),
+                )]
 
     @property
     def tax_date(self):
-        return self.invoice.tax_date
+        return self.taxes_date or self.invoice.tax_date
 
     def _get_tax_context(self):
         if self.invoice:
@@ -2254,6 +2259,7 @@
         for field in ('sequence', 'type', 'invoice_type', 'unit_price',
                 'description', 'unit', 'product', 'account'):
             setattr(line, field, getattr(self, field))
+        line.taxes_date = self.tax_date
         line.taxes = self.taxes
         return line
 
diff -r af9bc17b3972 -r d2a32b625e72 tests/scenario_invoice.rst
--- a/tests/scenario_invoice.rst        Sat Sep 05 22:12:11 2020 +0200
+++ b/tests/scenario_invoice.rst        Sat Sep 05 23:37:58 2020 +0200
@@ -220,6 +220,12 @@
     'cancelled'
     >>> invoice.reconciled == today
     True
+    >>> credit_note, = Invoice.find([
+    ...     ('type', '=', 'out'), ('id', '!=', invoice.id)])
+    >>> credit_note.state
+    'paid'
+    >>> all(line.taxes_date == today for line in credit_note.lines)
+    True
     >>> receivable.reload()
     >>> receivable.debit
     Decimal('240.00')
diff -r af9bc17b3972 -r d2a32b625e72 view/invoice_line_form.xml
--- a/view/invoice_line_form.xml        Sat Sep 05 22:12:11 2020 +0200
+++ b/view/invoice_line_form.xml        Sat Sep 05 23:37:58 2020 +0200
@@ -23,6 +23,10 @@
             <label name="amount"/>
             <field name="amount"/>
             <field name="taxes" colspan="4"/>
+            <label name="taxes_date"/>
+            <field name="taxes_date"/>
+            <newline/>
+
             <label name="origin"/>
             <field name="origin" colspan="3"/>
         </page>

Reply via email to