From e158ddf7ce7aacf9805e4ef225f50c1625555467 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 --- account_banking_mandate/models/__init__.py | 1 - .../models/account_invoice.py | 4 ++-- .../models/account_payment_line.py | 15 +++++++++----- .../models/account_payment_order.py | 20 ------------------- .../views/account_payment_line.xml | 12 +++++------ .../views/account_payment_method.xml | 4 ++-- 6 files changed, 20 insertions(+), 36 deletions(-) delete mode 100644 account_banking_mandate/models/account_payment_order.py diff --git a/account_banking_mandate/models/__init__.py b/account_banking_mandate/models/__init__.py index 4ffd1831d..145c8921a 100644 --- a/account_banking_mandate/models/__init__.py +++ b/account_banking_mandate/models/__init__.py @@ -2,7 +2,6 @@ from . import account_banking_mandate from . import account_payment_method -from . import account_payment_order from . import account_invoice from . import res_partner_bank from . import res_partner diff --git a/account_banking_mandate/models/account_invoice.py b/account_banking_mandate/models/account_invoice.py index 46d884493..140a78229 100644 --- a/account_banking_mandate/models/account_invoice.py +++ b/account_banking_mandate/models/account_invoice.py @@ -50,9 +50,9 @@ class AccountInvoice(models.Model): super(AccountInvoice, self)._onchange_partner_id() if ( self.type == 'out_invoice' and - self.partner_id.customer_payment_mode_id.\ + self.partner_id.customer_payment_mode_id. payment_type == 'inbound' and - self.partner_id.customer_payment_mode_id.payment_method_id.\ + self.partner_id.customer_payment_mode_id.payment_method_id. mandate_required and self.commercial_partner_id): mandates = self.env['account.banking.mandate'].search([ diff --git a/account_banking_mandate/models/account_payment_line.py b/account_banking_mandate/models/account_payment_line.py index bb0a2cb43..4650b2f98 100644 --- a/account_banking_mandate/models/account_payment_line.py +++ b/account_banking_mandate/models/account_payment_line.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api, _ -from openerp.exceptions import ValidationError +from openerp.exceptions import ValidationError, UserError class AccountPaymentLine(models.Model): @@ -14,6 +14,8 @@ class AccountPaymentLine(models.Model): mandate_id = fields.Many2one( comodel_name='account.banking.mandate', string='Direct Debit Mandate', domain=[('state', '=', 'valid')]) + mandate_required = fields.Boolean( + related='order_id.payment_method_id.mandate_required', readonly=True) @api.multi @api.constrains('mandate_id', 'partner_bank_id') @@ -31,7 +33,10 @@ class AccountPaymentLine(models.Model): pline.mandate_id.unique_mandate_reference, pline.mandate_id.partner_bank_id.acc_number)) -# @api.multi -# def check_payment_line(self): -# TODO : i would like to block here is mandate is missing... -# but how do you know it's required ? => create option on payment order ? + @api.multi + def draft2open_payment_line_check(self): + res = super(AccountPaymentLine, self).draft2open_payment_line_check() + if self.mandate_required and not self.mandate_id: + raise UserError(_( + 'Missing Mandate on payment line %s') % self.name) + return res diff --git a/account_banking_mandate/models/account_payment_order.py b/account_banking_mandate/models/account_payment_order.py deleted file mode 100644 index 1d6ef8e7d..000000000 --- a/account_banking_mandate/models/account_payment_order.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Akretion (Alexis de Lattre - alexis.delattre@akretion.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openerp import models, api, _ -from openerp.exceptions import UserError - - -class AccountPaymentOrder(models.Model): - _inherit = 'account.payment.order' - - @api.multi - def draft2open(self): - for order in self: - if order.payment_mode_id.payment_method_id.mandate_required: - for line in order.payment_line_ids: - if not line.mandate_id: - raise UserError(_( - "Missing mandate in payment line %s") % line.name) - return super(AccountPaymentOrder, self).draft2open() diff --git a/account_banking_mandate/views/account_payment_line.xml b/account_banking_mandate/views/account_payment_line.xml index 48e6a753f..55f1c0297 100644 --- a/account_banking_mandate/views/account_payment_line.xml +++ b/account_banking_mandate/views/account_payment_line.xml @@ -1,10 +1,9 @@ - + @@ -13,9 +12,10 @@ + @@ -34,4 +34,4 @@ - + diff --git a/account_banking_mandate/views/account_payment_method.xml b/account_banking_mandate/views/account_payment_method.xml index c6067e150..66744a970 100644 --- a/account_banking_mandate/views/account_payment_method.xml +++ b/account_banking_mandate/views/account_payment_method.xml @@ -6,9 +6,9 @@ account_banking_mandate.account.payment.method.form account.payment.method - + - +