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
parent 99d2403b8f
commit 0e64b0295a
19 changed files with 54 additions and 97 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>

View File

@@ -15,12 +15,10 @@ class AccountPaymentOrder(models.Model):
def generate_payment_file(self):
"""Creates the SEPA Credit Transfer file. That's the important code!"""
self.ensure_one()
if (
self.payment_mode_id.payment_method_id.code !=
'sepa_credit_transfer'):
if self.payment_method_id.code != 'sepa_credit_transfer':
return super(AccountPaymentOrder, self).generate_payment_file()
pain_flavor = self.payment_mode_id.payment_method_id.pain_version
pain_flavor = self.payment_method_id.pain_version
if not pain_flavor:
pain_flavor = 'pain.001.001.03'
# We use pain_flavor.startswith('pain.001.001.xx')
@@ -60,12 +58,11 @@ class AccountPaymentOrder(models.Model):
else:
raise UserError(
_("PAIN version '%s' is not supported.") % pain_flavor)
pay_method = self.payment_mode_id.payment_method_id
xsd_file = pay_method.get_xsd_file_path()
xsd_file = self.payment_method_id.get_xsd_file_path()
gen_args = {
'bic_xml_tag': bic_xml_tag,
'name_maxsize': name_maxsize,
'convert_to_ascii': pay_method.convert_to_ascii,
'convert_to_ascii': self.payment_method_id.convert_to_ascii,
'payment_method': 'TRF',
'file_prefix': 'sct_',
'pain_flavor': pain_flavor,

View File

@@ -7,6 +7,7 @@
<field name="name">SEPA Direct Debit for customers</field>
<field name="code">sepa_direct_debit</field>
<field name="payment_type">inbound</field>
<field name="bank_account_required" eval="True"/>
<field name="mandate_required" eval="True"/>
<field name="pain_version">pain.008.001.02</field>
</record>

View File

@@ -36,10 +36,10 @@ class AccountPaymentOrder(models.Model):
"""Creates the SEPA Direct Debit file. That's the important code !"""
self.ensure_one()
if (
self.payment_mode_id.payment_method_id.code !=
self.payment_method_id.code !=
'sepa_direct_debit'):
return super(AccountPaymentOrder, self).generate_payment_file()
pain_flavor = self.payment_mode_id.payment_method_id.pain_version
pain_flavor = self.payment_method_id.pain_version
# We use pain_flavor.startswith('pain.008.001.xx')
# to support country-specific extensions such as
# pain.008.001.02.ch.01 (cf l10n_ch_sepa)

View File

@@ -15,7 +15,10 @@ class AccountPaymentMethod(models.Model):
"this payment method. Therefore, if you change it, "
"the generation of the payment file may fail.")
active = fields.Boolean(string='Active', default=True)
# In the pain_base module, we will add a default_pain_version
bank_account_required = fields.Boolean(
string='Bank Account Required',
help="Activate this option if this payment method requires you to "
"know the bank account number of your customer or supplier.")
display_name = fields.Char(
compute='compute_display_name',
store=True, string='Display Name')

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>
<!-- The object account.payment.method is defined in the account module
@@ -14,6 +14,7 @@ here. I hate the objects that don't have a view... -->
<field name="name"/>
<field name="code"/>
<field name="payment_type"/>
<field name="bank_account_required"/>
<field name="active"/>
</group>
</form>
@@ -59,4 +60,4 @@ here. I hate the objects that don't have a view... -->
sequence="30" />
</data>
</openerp>
</odoo>

View File

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

View File

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

View File

@@ -18,7 +18,10 @@
<field name="amount_currency"/>
<field name="currency_id"/>
<field name="partner_id"/>
<field name="partner_bank_id" domain="[('partner_id', '=', partner_id)]"/>
<field name="partner_bank_id"
domain="[('partner_id', '=', partner_id)]"
attrs="{'required': [('bank_account_required', '=', True)]}"/>
<field name="bank_account_required" invisible="1"/>
<field name="communication_type"/>
<field name="communication"/>
</group>

View File

@@ -16,7 +16,6 @@
'depends': ['account_payment_mode'],
'data': [
'views/res_partner_view.xml',
'views/account_payment_method.xml',
'views/account_invoice_view.xml',
'views/account_move_line.xml',
'views/report_invoice.xml',

View File

@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from . import res_partner
from . import account_payment_method
from . import account_invoice
from . import account_move_line

View File

@@ -29,7 +29,8 @@ class AccountInvoice(models.Model):
pay_mode.payment_type == 'outbound' and
pay_mode.payment_method_id.bank_account_required and
self.commercial_partner_id.bank_ids):
self.partner_bank_id = self.commercial_partner_id.bank_ids[0]
self.partner_bank_id =\
self.commercial_partner_id.bank_ids[0]
elif self.type == 'out_invoice':
pay_mode = self.partner_id.customer_payment_mode_id
self.payment_mode_id = pay_mode
@@ -46,13 +47,11 @@ class AccountInvoice(models.Model):
if (
self.payment_mode_id and
self.payment_mode_id.payment_type == 'outbound' and
not self.payment_mode_id.payment_method_id.\
bank_account_required):
not self.payment_mode_id.payment_method_id.
bank_account_required):
self.partner_bank_id = False
print "false"
elif not self.payment_mode_id:
self.partner_bank_id = False
print "false"
@api.model
def line_get_convert(self, line, part):

View File

@@ -1,14 +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, fields
class AccountPaymentMethod(models.Model):
_inherit = "account.payment.method"
bank_account_required = fields.Boolean(
string='Bank Account Required',
help="Activate this option if this payment method requires to "
"set the bank account of your supplier on the vendor bills.")

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="account_payment_method_form" model="ir.ui.view">
<field name="name">account_payment_partner.account.payment.method.form</field>
<field name="model">account.payment.method</field>
<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"
attrs="{'invisible': [('payment_type', '!=', 'outbound')]}"/>
</field>
</field>
</record>
</data>
</odoo>