From 195cd6e284d1718786a44a808825fc53a786572c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sat, 30 Apr 2016 01:46:34 +0200 Subject: [PATCH] [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) --- account_payment_mode/README.rst | 54 +++++++++ account_payment_mode/__init__.py | 3 + account_payment_mode/__openerp__.py | 23 ++++ account_payment_mode/demo/payment_demo.xml | 110 ++++++++++++++++++ account_payment_mode/models/__init__.py | 6 + .../models/account_journal.py | 27 +++++ .../models/account_payment_method.py | 37 ++++++ .../models/account_payment_mode.py | 100 ++++++++++++++++ .../models/res_partner_bank.py | 13 +++ .../security/ir.model.access.csv | 5 + .../views/account_journal.xml | 29 +++++ .../views/account_payment_method.xml | 63 ++++++++++ .../views/account_payment_mode.xml | 72 ++++++++++++ account_payment_mode/views/res_partner.xml | 23 ++++ .../views/res_partner_bank.xml | 45 +++++++ 15 files changed, 610 insertions(+) create mode 100644 account_payment_mode/README.rst create mode 100644 account_payment_mode/__init__.py create mode 100644 account_payment_mode/__openerp__.py create mode 100644 account_payment_mode/demo/payment_demo.xml create mode 100644 account_payment_mode/models/__init__.py create mode 100644 account_payment_mode/models/account_journal.py create mode 100644 account_payment_mode/models/account_payment_method.py create mode 100644 account_payment_mode/models/account_payment_mode.py create mode 100644 account_payment_mode/models/res_partner_bank.py create mode 100644 account_payment_mode/security/ir.model.access.csv create mode 100644 account_payment_mode/views/account_journal.xml create mode 100644 account_payment_mode/views/account_payment_method.xml create mode 100644 account_payment_mode/views/account_payment_mode.xml create mode 100644 account_payment_mode/views/res_partner.xml create mode 100644 account_payment_mode/views/res_partner_bank.xml diff --git a/account_payment_mode/README.rst b/account_payment_mode/README.rst new file mode 100644 index 000000000..ac0f3a6e4 --- /dev/null +++ b/account_payment_mode/README.rst @@ -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 `_ 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 +`_. 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 + +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. diff --git a/account_payment_mode/__init__.py b/account_payment_mode/__init__.py new file mode 100644 index 000000000..cde864bae --- /dev/null +++ b/account_payment_mode/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/account_payment_mode/__openerp__.py b/account_payment_mode/__openerp__.py new file mode 100644 index 000000000..90c9e4378 --- /dev/null +++ b/account_payment_mode/__openerp__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (). +# 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, +} diff --git a/account_payment_mode/demo/payment_demo.xml b/account_payment_mode/demo/payment_demo.xml new file mode 100644 index 000000000..a00c13b34 --- /dev/null +++ b/account_payment_mode/demo/payment_demo.xml @@ -0,0 +1,110 @@ + + + + + + Fiducial Banque + FIDCFR21XXX + 38 rue Sergent Michel Berthet + 69009 + Lyon + + + + + La Banque Postale + PSSTFRPPXXX + 115 rue de Sèvres + 75007 + Paris + + + + + Société Générale + SOGEFRPPXXX + 1 avenue du Roi Fabien 1er + 75008 + Paris + + + + + BNP Paribas Fortis Charleroi + GEBABEBB03A + Charleroi + + + + + + FR76 4242 4242 4242 4242 4242 424 + + + + + + FR20 1242 1242 1242 1242 1242 124 + + + + + + FR66 1212 1212 1212 1212 1212 121 + + + + + + BE96 9988 7766 5544 + + + + + + + + Credit Transfer to Suppliers + + variable + + + + + Direct Debit of suppliers from Société Générale + + variable + + + + + Direct Debit of suppliers from La Banque Postale + + variable + + + + + Inbound Credit Trf Société Générale + + variable + + + + + Inbound Credit Trf La Banque Postale + + variable + + + + + Direct Debit of customers + + variable + + + + + + diff --git a/account_payment_mode/models/__init__.py b/account_payment_mode/models/__init__.py new file mode 100644 index 000000000..ae4c3c001 --- /dev/null +++ b/account_payment_mode/models/__init__.py @@ -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 diff --git a/account_payment_mode/models/account_journal.py b/account_payment_mode/models/account_journal.py new file mode 100644 index 000000000..6ba0b3626 --- /dev/null +++ b/account_payment_mode/models/account_journal.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# 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 diff --git a/account_payment_mode/models/account_payment_method.py b/account_payment_mode/models/account_payment_method.py new file mode 100644 index 000000000..748027a4d --- /dev/null +++ b/account_payment_mode/models/account_payment_method.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# 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' + )] diff --git a/account_payment_mode/models/account_payment_mode.py b/account_payment_mode/models/account_payment_mode.py new file mode 100644 index 000000000..a1d2e60eb --- /dev/null +++ b/account_payment_mode/models/account_payment_mode.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# 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)) diff --git a/account_payment_mode/models/res_partner_bank.py b/account_payment_mode/models/res_partner_bank.py new file mode 100644 index 000000000..4e9b0a2a5 --- /dev/null +++ b/account_payment_mode/models/res_partner_bank.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# 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) diff --git a/account_payment_mode/security/ir.model.access.csv b/account_payment_mode/security/ir.model.access.csv new file mode 100644 index 000000000..0ff4035ea --- /dev/null +++ b/account_payment_mode/security/ir.model.access.csv @@ -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 diff --git a/account_payment_mode/views/account_journal.xml b/account_payment_mode/views/account_journal.xml new file mode 100644 index 000000000..b7873ba5d --- /dev/null +++ b/account_payment_mode/views/account_journal.xml @@ -0,0 +1,29 @@ + + + + + + + fix_bank_account_selection.account_journal.form + account.journal + + + + 1 + + + + + + + + 1 + + + + + + diff --git a/account_payment_mode/views/account_payment_method.xml b/account_payment_mode/views/account_payment_method.xml new file mode 100644 index 000000000..f467f01f6 --- /dev/null +++ b/account_payment_mode/views/account_payment_method.xml @@ -0,0 +1,63 @@ + + + + + + + account_payment_method.form + account.payment.method + +
+ + + + + + + +
+
+
+ + + account_payment_method.tree + account.payment.method + + + + + + + + + + + account_payment_method.search + account.payment.method + + + + + + + + + + + + + + Payment Methods + account.payment.method + tree,form + + + + +
+
diff --git a/account_payment_mode/views/account_payment_mode.xml b/account_payment_mode/views/account_payment_mode.xml new file mode 100644 index 000000000..aa67cb2ec --- /dev/null +++ b/account_payment_mode/views/account_payment_mode.xml @@ -0,0 +1,72 @@ + + + + + + account.payment.mode.form + account.payment.mode + +
+ + + + + + + + + + + + + +
+
+
+ + + account.payment.mode.tree + account.payment.mode + + + + + + + + + + + + + account.payment.mode.search + account.payment.mode + + + + + + + + + + + + + + Payment Modes + account.payment.mode + tree,form + + + + +
+
diff --git a/account_payment_mode/views/res_partner.xml b/account_payment_mode/views/res_partner.xml new file mode 100644 index 000000000..b4e308840 --- /dev/null +++ b/account_payment_mode/views/res_partner.xml @@ -0,0 +1,23 @@ + + + + + + + + account_payment_mode.res_partner_form + res.partner + + + + {'invisible': [('parent_id', '!=', False)]} + + + + + + + diff --git a/account_payment_mode/views/res_partner_bank.xml b/account_payment_mode/views/res_partner_bank.xml new file mode 100644 index 000000000..ebdc48ec2 --- /dev/null +++ b/account_payment_mode/views/res_partner_bank.xml @@ -0,0 +1,45 @@ + + + + + + + account_payment_mode.res_partner_bank_form + res.partner.bank + + + + + + + + + + account_payment_mode.res_partner_bank_tree + res.partner.bank + + + + + + + + + + account_payment_mode.res_partner_bank_search + res.partner.bank + + + + + + + + + + + + +