From b4c2521a67bda28c1c9e1389d03b6036f178b90d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 14 Jun 2016 22:25:23 +0200 Subject: [PATCH] Move field bank_account_required from module account_payment_partner to account_payment_mode Make the mandate a required field on payment line when the payment method has mandate_required=True Make the bank account a required field on payment line when the payment method has bank_account_required=True Minor code cleanup PEP8 --- .../models/account_payment_line.py | 14 ++++++++------ .../models/account_payment_order.py | 5 ++++- .../views/account_payment_line.xml | 5 ++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/account_payment_order/models/account_payment_line.py b/account_payment_order/models/account_payment_line.py index 2ac4fbfac..5df4c2644 100644 --- a/account_payment_order/models/account_payment_line.py +++ b/account_payment_order/models/account_payment_line.py @@ -20,6 +20,9 @@ class AccountPaymentLine(models.Model): related='order_id.company_currency_id', store=True, readonly=True) payment_type = fields.Selection( related='order_id.payment_type', store=True, readonly=True) + bank_account_required = fields.Boolean( + related='order_id.payment_method_id.bank_account_required', + readonly=True) state = fields.Selection( related='order_id.state', string='State', readonly=True, store=True) @@ -127,9 +130,8 @@ class AccountPaymentLine(models.Model): return res @api.multi - def check_payment_line(self): - for line in self: - if not line.partner_bank_id: - raise UserError(_( - 'Missing Partner Bank Account on payment line %s') - % line.name) + def draft2open_payment_line_check(self): + self.ensure_one() + if self.bank_account_required and not self.partner_bank_id: + raise UserError(_( + 'Missing Partner Bank Account on payment line %s') % self.name) diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index 37e7f4019..d5be6a1b3 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -25,6 +25,9 @@ class AccountPaymentOrder(models.Model): ('inbound', 'Inbound'), ('outbound', 'Outbound'), ], string='Payment Type', readonly=True, required=True) + payment_method_id = fields.Many2one( + 'account.payment.method', related='payment_mode_id.payment_method_id', + readonly=True, store=True) company_id = fields.Many2one( related='payment_mode_id.company_id', store=True, readonly=True) company_currency_id = fields.Many2one( @@ -210,7 +213,7 @@ class AccountPaymentOrder(models.Model): # Create the bank payment lines from the payment lines group_paylines = {} # key = hashcode for payline in order.payment_line_ids: - payline.check_payment_line() + payline.draft2open_payment_line_check() # Compute requested payment date if order.date_prefered == 'due': requested_date = payline.ml_maturity_date or today diff --git a/account_payment_order/views/account_payment_line.xml b/account_payment_order/views/account_payment_line.xml index 152c119d4..c1155ac03 100644 --- a/account_payment_order/views/account_payment_line.xml +++ b/account_payment_order/views/account_payment_line.xml @@ -18,7 +18,10 @@ - + +