diff --git a/account_payment_order/models/account_payment_mode.py b/account_payment_order/models/account_payment_mode.py index 90770d679..1fd4d40a5 100644 --- a/account_payment_order/models/account_payment_mode.py +++ b/account_payment_order/models/account_payment_mode.py @@ -16,6 +16,12 @@ class AccountPaymentMode(models.Model): payment_order_ok = fields.Boolean( string='Selectable in Payment Orders', default=True) + no_debit_before_maturity = fields.Boolean( + string="Disallow Debit Before Maturity Date", + help="If you activate this option on an Inbound payment mode, " + "you will have an error message when you confirm a debit order " + "that has a payment line with a payment date before the maturity " + "date.") # Default options for the "payment.order.create" wizard default_payment_mode = fields.Selection([ ('same', 'Same'), diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index 85d14fdfc..b3ce326d4 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -221,6 +221,21 @@ class AccountPaymentOrder(models.Model): # No payment date in the past if requested_date < today: requested_date = today + # inbound: check option no_debit_before_maturity + if ( + order.payment_type == 'inbound' and + order.payment_mode_id.no_debit_before_maturity and + payline.ml_maturity_date and + requested_date < payline.ml_maturity_date): + raise UserError(_( + "The payment mode '%s' has the option " + "'Disallow Debit Before Maturity Date'. The " + "payment line %s has a maturity date %s " + "which is after the computed payment date %s.") % ( + order.payment_mode_id.name, + payline.name, + payline.ml_maturity_date, + requested_date)) # Write requested_date on 'date' field of payment line payline.date = requested_date # Group options diff --git a/account_payment_order/views/account_payment_mode.xml b/account_payment_order/views/account_payment_mode.xml index 6ba387602..951c59bf3 100644 --- a/account_payment_order/views/account_payment_mode.xml +++ b/account_payment_order/views/account_payment_mode.xml @@ -11,6 +11,8 @@ +