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
This commit is contained in:
Alexis de Lattre
2016-06-14 22:25:23 +02:00
committed by Enric Tobella
parent fa7d3e9169
commit e158ddf7ce
6 changed files with 20 additions and 36 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013-2016 Akretion (http://www.akretion.com)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
© 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<record id="account_payment_line_form" model="ir.ui.view">
@@ -13,9 +12,10 @@
<field name="inherit_id" ref="account_payment_order.account_payment_line_form"/>
<field name="arch" type="xml">
<field name="partner_bank_id" position="after">
<field name="mandate_required" invisible="1"/>
<field name="mandate_id"
domain="[('partner_bank_id', '=', partner_bank_id), ('state', '=', 'valid')]"
invisible="context.get('default_payment_type') != 'inbound'"
attrs="{'invisible': [('mandate_required', '=', False)], 'required': [('mandate_required', '=', True)]}"
context="{'default_partner_bank_id': partner_bank_id}"/>
</field>
</field>
@@ -34,4 +34,4 @@
</record>
</data>
</openerp>
</odoo>

View File

@@ -6,9 +6,9 @@
<record id="account_payment_method_form" model="ir.ui.view">
<field name="name">account_banking_mandate.account.payment.method.form</field>
<field name="model">account.payment.method</field>
<field name="inherit_id" ref="account_payment_partner.account_payment_method_form"/>
<field name="inherit_id" ref="account_payment_mode.account_payment_method_form"/>
<field name="arch" type="xml">
<field name="payment_type" position="after">
<field name="bank_account_required" position="after">
<field name="mandate_required"
attrs="{'invisible': [('payment_type', '!=', 'inbound')]}"/>
</field>