[ADD] acocunt_payment_mode: Start to port bank-payment to v9 (with a lot of improvements) during the Sorrento Code sprint 2016

Improvements include:

- full re-organisation of modules and big re-organisation of the code
- simplification of the code related to the fact that support for direct debit is now in t
he base module, not added by an optional module account_direct_debit (module was removed)
- new design of the wizard to select move lines to pay
- support for non-SEPA file transfer-
- support for German direct debit SEPA files (fixes bug #129)
- remove workflow of payment.order

- Finalise the wizard of selection of move lines to pay

  Add button "Add to payment/debit order" on invoice form view
  Started to integrate payment transfer in account_payment_order (not finished at all though)
  Various fixes/changes/improvements/...

- Update and re-enable demo data
- 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

- Enable the payment methods by default on bank journals (including existing bank journals via post_install scripts)
This commit is contained in:
Alexis de Lattre
2016-04-30 01:46:34 +02:00
committed by Thomas Binsfeld
parent 11eba772fb
commit 195cd6e284
15 changed files with 610 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
====================
Account Payment Mode
====================
This module adds a new object *account.payment.mode*. In Odoo v8, this object was part of the *account_payment* module from the official addons, but this module was dropped by the editor in Odoo v9. This object is also designed to replace the *payment.method* object of the *sale\_payment\_method* module of the `e-commerce <https://github.com/OCA/e-commerce>`_ OCA project in v9.
Configuration
=============
To configure this module, you need to go to the menu *Account > Configuration > Management > Payment Mode*.
Usage
=====
This module doesn't add any feature, but it is used by several other modules.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/173/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/bank-payment/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Alexis de Lattre <alexis.delattre@akretion.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

View File

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion (<http://www.akretion.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Account Payment Mode',
'version': '9.0.1.0.0',
'license': 'AGPL-3',
'author': "Akretion,Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/bank-payment',
'category': 'Banking addons',
'depends': ['account'],
'data': [
'security/ir.model.access.csv',
'views/account_payment_method.xml',
'views/account_payment_mode.xml',
'views/res_partner_bank.xml',
'views/res_partner.xml',
'views/account_journal.xml',
],
'demo': ['demo/payment_demo.xml'],
'installable': True,
}

View File

@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="bank_fiducial" model="res.bank">
<field name="name">Fiducial Banque</field>
<field name="bic">FIDCFR21XXX</field>
<field name="street">38 rue Sergent Michel Berthet</field>
<field name="zip">69009</field>
<field name="city">Lyon</field>
<field name="country" ref="base.fr"/>
</record>
<record id="bank_la_banque_postale" model="res.bank">
<field name="name">La Banque Postale</field>
<field name="bic">PSSTFRPPXXX</field>
<field name="street">115 rue de Sèvres</field>
<field name="zip">75007</field>
<field name="city">Paris</field>
<field name="country" ref="base.fr"/>
</record>
<record id="bank_societe_generale" model="res.bank">
<field name="name">Société Générale</field>
<field name="bic">SOGEFRPPXXX</field>
<field name="street">1 avenue du Roi Fabien 1er</field>
<field name="zip">75008</field>
<field name="city">Paris</field>
<field name="country" ref="base.fr"/>
</record>
<record id="bank_fortis" model="res.bank">
<field name="name">BNP Paribas Fortis Charleroi</field>
<field name="bic">GEBABEBB03A</field>
<field name="city">Charleroi</field>
<field name="country" ref="base.be"/>
</record>
<record id="main_company_iban" model="res.partner.bank">
<field name="acc_number">FR76 4242 4242 4242 4242 4242 424</field>
<field name="bank_id" ref="bank_la_banque_postale"/>
<field name="partner_id" ref="base.main_partner" />
</record>
<record id="main_company_iban2" model="res.partner.bank">
<field name="acc_number">FR20 1242 1242 1242 1242 1242 124</field>
<field name="bank_id" ref="bank_societe_generale"/>
<field name="partner_id" ref="base.main_partner" />
</record>
<record id="res_partner_12_iban" model="res.partner.bank">
<field name="acc_number">FR66 1212 1212 1212 1212 1212 121</field>
<field name="bank_id" ref="bank_fiducial"/>
<field name="partner_id" ref="base.res_partner_12" />
</record>
<record id="res_partner_2_iban" model="res.partner.bank">
<field name="acc_number">BE96 9988 7766 5544</field>
<field name="bank_id" ref="bank_fortis"/>
<field name="partner_id" ref="base.res_partner_2" />
</record>
<!-- Asustek already has a demo IBAN provided by base_iban -->
<record id="payment_mode_outbound_ct1" model="account.payment.mode">
<field name="name">Credit Transfer to Suppliers</field>
<field name="company_id" ref="base.main_company"/>
<field name="bank_account_link">variable</field>
<field name="payment_method_id" ref="account.account_payment_method_manual_out"/>
</record>
<record id="payment_mode_outbound_dd1" model="account.payment.mode">
<field name="name">Direct Debit of suppliers from Société Générale</field>
<field name="company_id" ref="base.main_company"/>
<field name="bank_account_link">variable</field>
<field name="payment_method_id" ref="account.account_payment_method_manual_out"/>
</record>
<record id="payment_mode_outbound_dd2" model="account.payment.mode">
<field name="name">Direct Debit of suppliers from La Banque Postale</field>
<field name="company_id" ref="base.main_company"/>
<field name="bank_account_link">variable</field>
<field name="payment_method_id" ref="account.account_payment_method_manual_out"/>
</record>
<record id="payment_mode_inbound_ct1" model="account.payment.mode">
<field name="name">Inbound Credit Trf Société Générale</field>
<field name="company_id" ref="base.main_company"/>
<field name="bank_account_link">variable</field> <!-- TODO: convert to fixed -->
<field name="payment_method_id" ref="account.account_payment_method_manual_in"/>
</record>
<record id="payment_mode_inbound_ct2" model="account.payment.mode">
<field name="name">Inbound Credit Trf La Banque Postale</field>
<field name="company_id" ref="base.main_company"/>
<field name="bank_account_link">variable</field> <!-- TODO: convert to fixed -->
<field name="payment_method_id" ref="account.account_payment_method_manual_in"/>
</record>
<record id="payment_mode_inbound_dd1" model="account.payment.mode">
<field name="name">Direct Debit of customers</field>
<field name="company_id" ref="base.main_company"/>
<field name="bank_account_link">variable</field>
<field name="payment_method_id" ref="account.account_payment_method_manual_in"/>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from . import account_payment_method
from . import account_payment_mode
from . import account_journal
from . import res_partner_bank

View File

@@ -0,0 +1,27 @@
# -*- 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 AccountJournal(models.Model):
_inherit = 'account.journal'
def _default_outbound_payment_methods(self):
all_out = self.env['account.payment.method'].search([
('payment_type', '=', 'outbound')])
return all_out
def _default_inbound_payment_methods(self):
all_in = self.env['account.payment.method'].search([
('payment_type', '=', 'inbound')])
return all_in
outbound_payment_method_ids = fields.Many2many(
default=_default_outbound_payment_methods)
inbound_payment_method_ids = fields.Many2many(
default=_default_inbound_payment_methods)
company_partner_id = fields.Many2one(
'res.partner', related='company_id.partner_id',
readonly=True) # Used in domain of field bank_account_id

View File

@@ -0,0 +1,37 @@
# -*- 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, api
class AccountPaymentMethod(models.Model):
_inherit = 'account.payment.method'
_rec_name = 'display_name'
code = fields.Char(
string='Code (Do Not Modify)',
help="This code is used in the code of the Odoo module that handle "
"this payment method. Therefore, if you change it, "
"the generation of the payment file may fail.")
active = fields.Boolean(string='Active', default=True)
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')
@api.multi
@api.depends('code', 'name', 'payment_type')
def compute_display_name(self):
for method in self:
method.display_name = u'[%s] %s (%s)' % (
method.code, method.name, method.payment_type)
_sql_constraints = [(
'code_payment_type_unique',
'unique(code, payment_type)',
'A payment method of the same type already exists with this code'
)]

View File

@@ -0,0 +1,100 @@
# -*- 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, api, _
from openerp.exceptions import ValidationError
class AccountPaymentMode(models.Model):
"""This corresponds to the object payment.mode of v8 with some
important changes. It also replaces the object payment.method
of the module sale_payment_method of OCA/e-commerce"""
_name = "account.payment.mode"
_description = 'Payment Modes'
_order = 'name'
name = fields.Char(string='Name', required=True, translate=True)
company_id = fields.Many2one(
'res.company', string='Company', required=True, ondelete='restrict',
default=lambda self: self.env['res.company']._company_default_get(
'account.payment.mode'))
bank_account_link = fields.Selection([
('fixed', 'Fixed'),
('variable', 'Variable'),
], string='Link to Bank Account', required=True,
help="For payment modes that are always attached to the same bank "
"account of your company (such as wire transfer from customers or "
"SEPA direct debit from suppliers), select "
"'Fixed'. For payment modes that are not always attached to the same "
"bank account (such as SEPA Direct debit for customers, wire transfer "
"to suppliers), you should choose 'Variable', which means that you "
"will select the bank account on the payment order. If your company "
"only has one bank account, you should always select 'Fixed'.")
fixed_journal_id = fields.Many2one(
'account.journal', string='Fixed Bank Journal',
domain=[('type', '=', 'bank')], ondelete='restrict')
# I need to use the old definition, because I have 2 M2M fields
# pointing to account.journal
variable_journal_ids = fields.Many2many(
'account.journal',
'account_payment_mode_variable_journal_rel',
'payment_mode_id', 'journal_id',
string='Allowed Bank Journals',
domain=[('type', '=', 'bank')])
payment_method_id = fields.Many2one(
'account.payment.method', string='Payment Method', required=True,
ondelete='restrict') # equivalent v8 field : type
payment_type = fields.Selection(
related='payment_method_id.payment_type', readonly=True, store=True,
string="Payment Type")
payment_method_code = fields.Char(
related='payment_method_id.code', readonly=True, store=True,
string='Payment Method Code')
active = fields.Boolean(string='Active', default=True)
# I dropped sale_ok and purchase_ok fields, because it is replaced by
# payment_type = 'inbound' or 'outbound'
# In fact, with the new v9 datamodel, you MUST create 2 payment modes
# for wire transfer : one for wire transfer from your customers (inbound)
# and one for wire transfer to your suppliers (outbound)
note = fields.Text(string="Note", translate=True)
@api.multi
@api.constrains(
'bank_account_link', 'fixed_journal_id', 'payment_method_id')
def bank_account_link_constrains(self):
for mode in self:
if mode.bank_account_link == 'fixed':
if not mode.fixed_journal_id:
raise ValidationError(_(
"On the payment mode '%s', the bank account link is "
"'Fixed' but the fixed bank journal is not set")
% mode.name)
else:
if mode.payment_method_id.payment_type == 'outbound':
if (
mode.payment_method_id.id not in
mode.fixed_journal_id.
outbound_payment_method_ids.ids):
raise ValidationError(_(
"On the payment mode '%s', the payment method "
"is '%s', but this payment method is not part "
"of the payment methods of the fixed bank "
"journal '%s'") % (
mode.name,
mode.payment_method_id.name,
mode.fixed_journal_id.name))
else:
if (
mode.payment_method_id.id not in
mode.fixed_journal_id.
inbound_payment_method_ids.ids):
raise ValidationError(_(
"On the payment mode '%s', the payment method "
"is '%s' (it is in fact a debit method), "
"but this debit method is not part "
"of the debit methods of the fixed bank "
"journal '%s'") % (
mode.name,
mode.payment_method_id.name,
mode.fixed_journal_id.name))

View File

@@ -0,0 +1,13 @@
# -*- 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 ResPartnerBank(models.Model):
_inherit = 'res.partner.bank'
# I also have to change the label of the field in the view
# I store the field, so that we can do groupby and search on it
acc_type = fields.Char(string='Bank Account Type', store=True)

View File

@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
account.access_account_payment_method,Read access on account.payment.method to Invoice user,account.model_account_payment_method,account.group_account_invoice,1,0,0,0
access_account_payment_method_full,Full access on account.payment.method to Financial Manager,account.model_account_payment_method,account.group_account_manager,1,1,1,1
access_account_payment_mode_read,Read access on account.payment.mode to Employees,model_account_payment_mode,base.group_user,1,0,0,0
access_account_payment_mode_full,Full access on account.payment.mode to Financial Manager,model_account_payment_mode,account.group_account_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 account.access_account_payment_method Read access on account.payment.method to Invoice user account.model_account_payment_method account.group_account_invoice 1 0 0 0
3 access_account_payment_method_full Full access on account.payment.method to Financial Manager account.model_account_payment_method account.group_account_manager 1 1 1 1
4 access_account_payment_mode_read Read access on account.payment.mode to Employees model_account_payment_mode base.group_user 1 0 0 0
5 access_account_payment_mode_full Full access on account.payment.mode to Financial Manager model_account_payment_mode account.group_account_manager 1 1 1 1

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- FIX of the 'account' module: on the form view of a bank journal,
allow to link to an existing bank account -->
<record id="view_account_journal_form" model="ir.ui.view">
<field name="name">fix_bank_account_selection.account_journal.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<field name="bank_acc_number" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="bank_acc_number" position="before">
<field name="company_partner_id" invisible="1"/>
<field name="bank_account_id" domain="[('partner_id', '=', company_partner_id)]"/>
</field>
<!-- better when related fields are readonly, otherwise the user
doesn't understand that he is changing the bank_id on the underlying
res.partner.bank object -->
<field name="bank_id" position="attributes">
<attribute name="readonly">1</attribute>
</field>
</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- The object account.payment.method is defined in the account module
but there are no view for this object in the account module... so we define it
here. I hate the objects that don't have a view... -->
<record id="account_payment_method_form" model="ir.ui.view">
<field name="name">account_payment_method.form</field>
<field name="model">account.payment.method</field>
<field name="arch" type="xml">
<form string="Payment Method">
<group name="main">
<field name="name"/>
<field name="code"/>
<field name="payment_type"/>
<field name="bank_account_required"/>
<field name="active"/>
</group>
</form>
</field>
</record>
<record id="account_payment_method_tree" model="ir.ui.view">
<field name="name">account_payment_method.tree</field>
<field name="model">account.payment.method</field>
<field name="arch" type="xml">
<tree string="Payment Methods">
<field name="name"/>
<field name="code"/>
<field name="payment_type"/>
</tree>
</field>
</record>
<record id="account_payment_method_search" model="ir.ui.view">
<field name="name">account_payment_method.search</field>
<field name="model">account.payment.method</field>
<field name="arch" type="xml">
<search string="Search Payment Methods">
<field name="name" filter_domain="['|', ('name', 'ilike', self), ('code', 'ilike', self)]" string="Name or Code"/>
<filter name="inbound" string="Inbound" domain="[('payment_type', '=', 'inbound')]" />
<filter name="outbound" string="Outbound" domain="[('payment_type', '=', 'outbound')]" />
<group string="Group By" name="groupby">
<filter string="Payment Type" name="payment_type_groupby" context="{'group_by': 'payment_type'}"/>
</group>
</search>
</field>
</record>
<record id="account_payment_method_action" model="ir.actions.act_window">
<field name="name">Payment Methods</field>
<field name="res_model">account.payment.method</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="account_payment_method_menu"
action="account_payment_method_action"
parent="account.account_management_menu"
sequence="30" />
</data>
</odoo>

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="account_payment_mode_form" model="ir.ui.view">
<field name="name">account.payment.mode.form</field>
<field name="model">account.payment.mode</field>
<field name="arch" type="xml">
<form string="Payment Mode">
<group name="main">
<field name="name"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="active"/>
<field name="payment_method_id" widget="selection"/>
<field name="payment_type"/>
<field name="bank_account_link"/>
<field name="fixed_journal_id"
attrs="{'invisible': [('bank_account_link', '!=', 'fixed')], 'required': [('bank_account_link', '=', 'fixed')]}"
widget="selection"/>
<field name="variable_journal_ids"
attrs="{'invisible': [('bank_account_link', '!=', 'variable')], 'required': [('bank_account_link', '=', 'variable')]}"
widget="many2many_tags"/>
</group>
<group string="Note" name="note">
<field name="note" nolabel="1"/>
</group>
</form>
</field>
</record>
<record id="account_payment_mode_tree" model="ir.ui.view">
<field name="name">account.payment.mode.tree</field>
<field name="model">account.payment.mode</field>
<field name="arch" type="xml">
<tree string="Payment Modes">
<field name="name"/>
<field name="payment_method_id"/>
<field name="payment_type"/>
<field name="bank_account_link"/>
<field name="company_id" groups="base.group_multi_company"/>
</tree>
</field>
</record>
<record id="account_payment_mode_search" model="ir.ui.view">
<field name="name">account.payment.mode.search</field>
<field name="model">account.payment.mode</field>
<field name="arch" type="xml">
<search string="Search Payment Modes">
<field name="name"/>
<filter name="inbound" string="Inbound" domain="[('payment_type', '=', 'inbound')]" />
<filter name="outbound" string="Outbound" domain="[('payment_type', '=', 'outbound')]" />
<group string="Group By" name="groupby">
<filter string="Payment Method" name="payment_method_groupby" context="{'group_by': 'payment_method_id'}"/>
</group>
</search>
</field>
</record>
<record id="account_payment_mode_action" model="ir.actions.act_window">
<field name="name">Payment Modes</field>
<field name="res_model">account.payment.mode</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="account_payment_mode_menu"
action="account_payment_mode_action"
parent="account.account_management_menu"
sequence="25" />
</data>
</openerp>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Avoid creation of bank accounts linked to contacts.
Note that, when you use the res.partner.bank menu entry,
there is a domain on the 'partner_id' field of res.partner.bank (base module)
which prevents the selection of a contact -->
<record id="partner_view_buttons" model="ir.ui.view">
<field name="name">account_payment_mode.res_partner_form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.partner_view_buttons"/>
<field name="arch" type="xml">
<group name="banks" position="attributes">
<attribute name="attrs">{'invisible': [('parent_id', '!=', False)]}</attribute>
</group>
</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Show acc_type on res.partner.bank in order to be able to
detect wrong IBANs -->
<record id="view_partner_bank_form" model="ir.ui.view">
<field name="name">account_payment_mode.res_partner_bank_form</field>
<field name="model">res.partner.bank</field>
<field name="inherit_id" ref="base.view_partner_bank_form"/>
<field name="arch" type="xml">
<field name="acc_number" position="after">
<field name="acc_type" string="Bank Account Type"/>
</field>
</field>
</record>
<record id="view_partner_bank_tree" model="ir.ui.view">
<field name="name">account_payment_mode.res_partner_bank_tree</field>
<field name="model">res.partner.bank</field>
<field name="inherit_id" ref="base.view_partner_bank_tree"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="acc_type" string="Bank Account Type"/>
</field>
</field>
</record>
<record id="view_partner_bank_search" model="ir.ui.view">
<field name="name">account_payment_mode.res_partner_bank_search</field>
<field name="model">res.partner.bank</field>
<field name="inherit_id" ref="base.view_partner_bank_search"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<group string="Group By" name="groupby">
<filter name="acc_type_groupby" string="Bank Account Type"
context="{'group_by': 'acc_type'}"/>
</group>
</field>
</field>
</record>
</data>
</openerp>