changeset 2816523d7ceb in modules/account_invoice:default
details: 
https://hg.tryton.org/modules/account_invoice?cmd=changeset;node=2816523d7ceb
description:
        Add payment term date in invoice

        issue9956
        review292961002
diffstat:

 CHANGELOG             |   2 ++
 exceptions.py         |   6 +++++-
 invoice.py            |  25 ++++++++++++++++++++++---
 message.xml           |   3 +++
 view/invoice_form.xml |   3 +++
 5 files changed, 35 insertions(+), 4 deletions(-)

diffs (115 lines):

diff -r 514ce8712485 -r 2816523d7ceb CHANGELOG
--- a/CHANGELOG Wed Jan 13 00:40:53 2021 +0100
+++ b/CHANGELOG Thu Jan 28 11:01:11 2021 +0100
@@ -1,3 +1,5 @@
+* Add payment term date in invoice
+* Raise warning on invoice with maturity dates on the past
 * Remove foreign key for sequence of Invoice
 * Add summary to invoice line list
 * Add default customer payment term configuration
diff -r 514ce8712485 -r 2816523d7ceb exceptions.py
--- a/exceptions.py     Wed Jan 13 00:40:53 2021 +0100
+++ b/exceptions.py     Thu Jan 28 11:01:11 2021 +0100
@@ -1,7 +1,7 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
 
-from trytond.exceptions import UserError
+from trytond.exceptions import UserError, UserWarning
 from trytond.model.exceptions import ValidationError
 
 
@@ -31,3 +31,7 @@
 
 class PayInvoiceError(UserError):
     pass
+
+
+class InvoicePaymentTermDateWarning(UserWarning):
+    pass
diff -r 514ce8712485 -r 2816523d7ceb invoice.py
--- a/invoice.py        Wed Jan 13 00:40:53 2021 +0100
+++ b/invoice.py        Thu Jan 28 11:01:11 2021 +0100
@@ -29,7 +29,7 @@
 
 from .exceptions import (
     InvoiceTaxValidationError, InvoiceNumberError, InvoiceValidationError,
-    InvoiceLineValidationError, PayInvoiceError)
+    InvoiceLineValidationError, PayInvoiceError, InvoicePaymentTermDateWarning)
 
 if config.getboolean('account_invoice', 'filestore', default=False):
     file_id = 'invoice_report_cache_id'
@@ -94,6 +94,10 @@
         depends=['state'])
     accounting_date = fields.Date('Accounting Date', states=_states,
         depends=_depends)
+    payment_term_date = fields.Date(
+        "Payment Term Date", states=_states, depends=_depends,
+        help="The date from which the payment term is calculated.\n"
+        "Leave empty to use the invoice date.")
     sequence = fields.Integer("Sequence", readonly=True)
     party = fields.Many2One('party.party', 'Party',
         required=True, states=_states, depends=_depends)
@@ -939,6 +943,10 @@
         Move = pool.get('account.move')
         Period = pool.get('account.period')
         Date = pool.get('ir.date')
+        Warning = pool.get('res.user.warning')
+        Lang = pool.get('ir.lang')
+
+        today = Date.today()
 
         if self.move:
             return self.move
@@ -956,12 +964,23 @@
             if line.amount_second_currency:
                 total_currency += line.amount_second_currency
 
-        term_lines = [(Date.today(), total)]
+        term_lines = [(self.payment_term_date or today, total)]
         if self.payment_term:
+            payment_date = self.payment_term_date or self.invoice_date
             term_lines = self.payment_term.compute(
-                total, self.company.currency, self.invoice_date)
+                total, self.company.currency, payment_date)
         remainder_total_currency = total_currency
         for date, amount in term_lines:
+            if date < today:
+                lang = Lang.get()
+                warning_key = 'invoice_payment_term_%d' % self.id
+                if Warning.check(warning_key):
+                    raise InvoicePaymentTermDateWarning(warning_key,
+                        gettext('account_invoice'
+                            '.msg_invoice_payment_term_date_past',
+                            invoice=self.rec_name,
+                            date=lang.strftime(date)))
+
             line = self._get_move_line(date, amount)
             if line.amount_second_currency:
                 remainder_total_currency += line.amount_second_currency
diff -r 514ce8712485 -r 2816523d7ceb message.xml
--- a/message.xml       Wed Jan 13 00:40:53 2021 +0100
+++ b/message.xml       Thu Jan 28 11:01:11 2021 +0100
@@ -66,6 +66,9 @@
         <record model="ir.message" id="msg_invoice_payment_line_unique">
             <field name="text">A payment line can be linked to only one 
invoice.</field>
         </record>
+        <record model="ir.message" id="msg_invoice_payment_term_date_past">
+            <field name="text">The invoice "%(invoice)s" generates a payment 
date "%(date)s" in the past.</field>
+        </record>
     </data>
 </tryton>
 
diff -r 514ce8712485 -r 2816523d7ceb view/invoice_form.xml
--- a/view/invoice_form.xml     Wed Jan 13 00:40:53 2021 +0100
+++ b/view/invoice_form.xml     Thu Jan 28 11:01:11 2021 +0100
@@ -66,6 +66,9 @@
             <field name="comment" colspan="4"/>
         </page>
         <page string="Payment" id="payment">
+            <label name="payment_term_date"/>
+            <field name="payment_term_date"/>
+            <newline/>
             <label name="amount_to_pay_today"/>
             <field name="amount_to_pay_today" symbol="currency"/>
             <label name="amount_to_pay"/>

Reply via email to