From cd5ce3c7dc84611ff42dc4e4bc89fbb85ff0ab10 Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Thu, 30 Nov 2017 15:45:28 +0100 Subject: [PATCH] [IMP] account: payment terms usability * Replace payment term lines options 'last_day_following_month' and 'last_day_current_month' by two new less specific ones allowing choosing the day directly, and thus not limited to the last one anymore (semantically different). * Rename payment term line option value 'fix_day_following_month' into 'after_invoice_month' for more clarity (no semantic change). Was task 24239. Was PR #15487 --- addons/account/demo/account_demo.xml | 12 ++++---- addons/account/models/account_invoice.py | 31 ++++++++++++------- addons/account/views/account_view.xml | 38 +++++++++++++++--------- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/addons/account/demo/account_demo.xml b/addons/account/demo/account_demo.xml index 8f2f139f4b9..47aecbe57a6 100644 --- a/addons/account/demo/account_demo.xml +++ b/addons/account/demo/account_demo.xml @@ -1,7 +1,7 @@ - + @@ -20,22 +20,22 @@ Demo Coffe Machine Account - + End of Following Month Payment terms: End of Following Month - + 30% Advance End of Following Month Payment terms: 30% Advance End of Following Month - + - + diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index bea828e3453..3b86572932f 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1752,13 +1752,16 @@ class AccountPaymentTerm(models.Model): next_date = fields.Date.from_string(date_ref) if line.option == 'day_after_invoice_date': next_date += relativedelta(days=line.days) - elif line.option == 'fix_day_following_month': + if line.day_of_the_month > 0: + months_delta = (line.day_of_the_month < next_date.day) and 1 or 0 + next_date += relativedelta(day=line.day_of_the_month, months=months_delta) + elif line.option == 'after_invoice_month': next_first_date = next_date + relativedelta(day=1, months=1) # Getting 1st of next month next_date = next_first_date + relativedelta(days=line.days - 1) - elif line.option == 'last_day_following_month': - next_date += relativedelta(day=31, months=1) # Getting last day of next month - elif line.option == 'last_day_current_month': - next_date += relativedelta(day=31, months=0) # Getting last day of next month + elif line.option == 'day_following_month': + next_date += relativedelta(day=line.days, months=1) + elif line.option == 'day_current_month': + next_date += relativedelta(day=line.days, months=0) result.append((fields.Date.to_string(next_date), amt)) amount -= amt amount = sum(amt for _, amt in result) @@ -1788,11 +1791,12 @@ class AccountPaymentTermLine(models.Model): help="Select here the kind of valuation related to this payment terms line.") value_amount = fields.Float(string='Value', digits=dp.get_precision('Payment Terms'), help="For percent enter a ratio between 0-100.") days = fields.Integer(string='Number of Days', required=True, default=0) + day_of_the_month = fields.Integer(string='Day of the month', help="Day of the month on which the invoice must come to its term. If zero or negative, this value will be ignored, and no specific day will be set. If greater than the last day of a month, this number will instead select the last day of this month.") option = fields.Selection([ - ('day_after_invoice_date', 'Day(s) after the invoice date'), - ('fix_day_following_month', 'Day(s) after the end of the invoice month (Net EOM)'), - ('last_day_following_month', 'Last day of following month'), - ('last_day_current_month', 'Last day of current month'), + ('day_after_invoice_date', "day(s) after the invoice date"), + ('after_invoice_month', "day(s) after the end of the invoice month"), + ('day_following_month', "of the following month"), + ('day_current_month', "of the current month"), ], default='day_after_invoice_date', required=True, string='Options' ) @@ -1805,7 +1809,14 @@ class AccountPaymentTermLine(models.Model): if self.value == 'percent' and (self.value_amount < 0.0 or self.value_amount > 100.0): raise ValidationError(_('Percentages for Payment Terms Line must be between 0 and 100.')) + @api.constrains('days') + def _check_days(self): + if self.option in ('day_following_month', 'day_current_month') and self.days <= 0: + raise ValidationError(_("The day of the month used for this term must be stricly positive.")) + elif self.days < 0: + raise ValidationError(_("The number of days used for a payment term cannot be negative.")) + @api.onchange('option') def _onchange_option(self): - if self.option in ('last_day_current_month', 'last_day_following_month'): + if self.option in ('day_current_month', 'day_following_month'): self.days = 0 diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index c125c1b1596..9c313a6697c 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -1600,6 +1600,7 @@ + @@ -1608,27 +1609,36 @@ account.payment.term.line
+

Term Type

- + -