Add option no_debit_before_maturity on payment mode

This commit is contained in:
Alexis de Lattre
2016-05-11 23:16:02 +02:00
committed by Enric Tobella
parent ed265873ce
commit 88dbbebe43
3 changed files with 23 additions and 0 deletions

View File

@@ -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'),

View File

@@ -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

View File

@@ -11,6 +11,8 @@
<group name="main" position="after">
<group name="payment_order_options" string="Options for Payment Orders">
<field name="payment_order_ok"/>
<field name="no_debit_before_maturity"
attrs="{'invisible': ['|', ('payment_type', '!=', 'inbound'), ('payment_order_ok', '!=', True)]}"/>
<field name="group_lines"/>
</group>
<group name="payment_order_create_defaults" string="Select Move Lines to Pay - Default Values">