From 4716c0c219d5dbdf4084414eb6b728ee73cf62a8 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sat, 30 Apr 2016 01:46:34 +0200 Subject: [PATCH] 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 This port to v9 is not finished... there is still a lot of work: - finish the code of account_payment_order/wizard/account_payment_line_create.py - port account_banking_payment_transfer and integrate it inside account_payment_order - fix bugs - clean-up code, remove dead code - test in several complex scenarios --- account_payment_mode/README.rst | 58 ++++++++++ account_payment_mode/__init__.py | 3 + account_payment_mode/__openerp__.py | 21 ++++ account_payment_mode/demo/payment_demo.xml | 108 ++++++++++++++++++ account_payment_mode/models/__init__.py | 5 + .../models/account_payment_method.py | 34 ++++++ .../models/account_payment_mode.py | 100 ++++++++++++++++ .../models/res_partner_bank.py | 13 +++ .../security/ir.model.access.csv | 5 + .../views/account_payment_method.xml | 62 ++++++++++ .../views/account_payment_mode.xml | 71 ++++++++++++ .../views/res_partner_bank.xml | 44 +++++++ 12 files changed, 524 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_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_payment_method.xml create mode 100644 account_payment_mode/views/account_payment_mode.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..c45ad9156 --- /dev/null +++ b/account_payment_mode/README.rst @@ -0,0 +1,58 @@ +.. 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..2b229ea39 --- /dev/null +++ b/account_payment_mode/__openerp__.py @@ -0,0 +1,21 @@ +# -*- 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', + ], + '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..b105d8c9b --- /dev/null +++ b/account_payment_mode/demo/payment_demo.xml @@ -0,0 +1,108 @@ + + + + + + Fortuneo Banque + FTNOFRP1XXX + 26 avenue des Champs Elysées + 75008 + Paris + + + + + 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..a40aa5c9e --- /dev/null +++ b/account_payment_mode/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from . import account_payment_method +from . import account_payment_mode +from . import res_partner_bank 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..5387f3843 --- /dev/null +++ b/account_payment_mode/models/account_payment_method.py @@ -0,0 +1,34 @@ +# -*- 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) + # In the pain_base module, we will add a default_pain_version + 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..f001eefe8 --- /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) + 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..1f70f9f81 --- /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' + + # TODO: It doesn't work, I don't understand why + # So I change the label of the field in the view + acc_type = fields.Char(string='Bank Account Type') 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_payment_method.xml b/account_payment_mode/views/account_payment_method.xml new file mode 100644 index 000000000..f912e45e9 --- /dev/null +++ b/account_payment_mode/views/account_payment_method.xml @@ -0,0 +1,62 @@ + + + + + + + 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..8ea6332a2 --- /dev/null +++ b/account_payment_mode/views/account_payment_mode.xml @@ -0,0 +1,71 @@ + + + + + + account.payment.mode.form + account.payment.mode + +
+ + + + + + + + + + + + +
+
+
+ + + account.payment.mode.tree + account.payment.mode + + + + + + + + + + + + + account.payment.mode.search + account.payment.mode + + + + + + + + + + + + + + Payment Mode + account.payment.mode + tree,form + + + + +
+
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..da8984ac5 --- /dev/null +++ b/account_payment_mode/views/res_partner_bank.xml @@ -0,0 +1,44 @@ + + + + + + + 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 + + + + + + + + + + + + +