diff --git a/CHANGELOG b/CHANGELOG
index b7ceaae242..7eb3be652d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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 --git a/exceptions.py b/exceptions.py
index 55a0479288..7598e0ab02 100644
--- a/exceptions.py
+++ b/exceptions.py
@@ -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 InvoiceLineValidationError(ValidationError):
class PayInvoiceError(UserError):
pass
+
+
+class InvoicePaymentTermDateWarning(UserWarning):
+ pass
diff --git a/invoice.py b/invoice.py
index 9855c10998..2199c0c44c 100644
--- a/invoice.py
+++ b/invoice.py
@@ -29,7 +29,7 @@ from trytond.modules.product import price_digits
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 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
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 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
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 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
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 --git a/message.xml b/message.xml
index 2f76fe2409..be673fabc3 100644
--- a/message.xml
+++ b/message.xml
@@ -66,6 +66,9 @@ this repository contains the full copyright notices and license terms. -->
A payment line can be linked to only one invoice.
+
+ The invoice "%(invoice)s" generates a payment date "%(date)s" in the past.
+
diff --git a/view/invoice_form.xml b/view/invoice_form.xml
index 963a686dd1..eb4c7db662 100644
--- a/view/invoice_form.xml
+++ b/view/invoice_form.xml
@@ -66,6 +66,9 @@ this repository contains the full copyright notices and license terms. -->
+
+
+