From af9874054c9b1755b331e253cb6b002a81bedb17 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 --- .../__init__.py | 1 - .../__openerp__.py | 10 +- .../data/account_payment_method.xml | 15 ++ .../data/payment_type_sepa_sct.xml | 53 ------ .../demo/sepa_credit_transfer_demo.xml | 11 +- .../models/__init__.py | 3 +- .../models/account_payment_method.py | 28 +++ .../account_payment_order.py} | 161 ++++++------------ .../models/payment_mode.py | 16 -- .../wizard/__init__.py | 5 - .../wizard/export_sepa_view.xml | 36 ---- 11 files changed, 103 insertions(+), 236 deletions(-) create mode 100644 account_banking_sepa_credit_transfer/data/account_payment_method.xml delete mode 100644 account_banking_sepa_credit_transfer/data/payment_type_sepa_sct.xml create mode 100644 account_banking_sepa_credit_transfer/models/account_payment_method.py rename account_banking_sepa_credit_transfer/{wizard/export_sepa.py => models/account_payment_order.py} (52%) delete mode 100644 account_banking_sepa_credit_transfer/models/payment_mode.py delete mode 100644 account_banking_sepa_credit_transfer/wizard/__init__.py delete mode 100644 account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml diff --git a/account_banking_sepa_credit_transfer/__init__.py b/account_banking_sepa_credit_transfer/__init__.py index 31b508d85..711d83d4a 100644 --- a/account_banking_sepa_credit_transfer/__init__.py +++ b/account_banking_sepa_credit_transfer/__init__.py @@ -2,4 +2,3 @@ # © 2010-2013 Akretion (www.akretion.com) from . import models -from . import wizard diff --git a/account_banking_sepa_credit_transfer/__openerp__.py b/account_banking_sepa_credit_transfer/__openerp__.py index 8621dc6a2..e3adba80e 100644 --- a/account_banking_sepa_credit_transfer/__openerp__.py +++ b/account_banking_sepa_credit_transfer/__openerp__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2010-2015 Akretion (www.akretion.com) +# © 2010-2016 Akretion (www.akretion.com) # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2016 Antiun Ingenieria S.L. - Antonio Espinosa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -7,7 +7,7 @@ { 'name': 'Account Banking SEPA Credit Transfer', 'summary': 'Create SEPA XML files for Credit Transfers', - 'version': '8.0.0.5.0', + 'version': '9.0.1.0.0', 'license': 'AGPL-3', 'author': "Akretion, " "Serv. Tecnol. Avanzados - Pedro M. Baeza, " @@ -15,13 +15,13 @@ "Odoo Community Association (OCA)", 'website': 'https://github.com/OCA/bank-payment', 'category': 'Banking addons', + 'conflicts': ['account_sepa'], 'depends': ['account_banking_pain_base'], 'data': [ - 'wizard/export_sepa_view.xml', - 'data/payment_type_sepa_sct.xml', + 'data/account_payment_method.xml', ], 'demo': [ 'demo/sepa_credit_transfer_demo.xml' ], - 'installable': False, + 'installable': True, } diff --git a/account_banking_sepa_credit_transfer/data/account_payment_method.xml b/account_banking_sepa_credit_transfer/data/account_payment_method.xml new file mode 100644 index 000000000..36a8961c8 --- /dev/null +++ b/account_banking_sepa_credit_transfer/data/account_payment_method.xml @@ -0,0 +1,15 @@ + + + + + + + SEPA Credit Transfer to suppliers + sepa_credit_transfer + outbound + pain.001.001.03 + + + + + diff --git a/account_banking_sepa_credit_transfer/data/payment_type_sepa_sct.xml b/account_banking_sepa_credit_transfer/data/payment_type_sepa_sct.xml deleted file mode 100644 index dac1fffa7..000000000 --- a/account_banking_sepa_credit_transfer/data/payment_type_sepa_sct.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - SEPA Credit Transfer v05 - pain.001.001.05 - payment - - - - - - SEPA Credit Transfer v04 - pain.001.001.04 - payment - - - - - - SEPA Credit Transfer v03 (recommended) - pain.001.001.03 - payment - - - - - - SEPA Credit Transfer v02 - pain.001.001.02 - payment - - - - - - SEPA Credit Transfer pain 001.003.03 (used in Germany) - pain.001.003.03 - payment - - - - - - diff --git a/account_banking_sepa_credit_transfer/demo/sepa_credit_transfer_demo.xml b/account_banking_sepa_credit_transfer/demo/sepa_credit_transfer_demo.xml index 48e69a780..4b39a6779 100644 --- a/account_banking_sepa_credit_transfer/demo/sepa_credit_transfer_demo.xml +++ b/account_banking_sepa_credit_transfer/demo/sepa_credit_transfer_demo.xml @@ -3,13 +3,12 @@ - - SEPA Credit Transfer La Banque Postale - - + + SEPA Credit Transfer to suppliers - - + variable + + diff --git a/account_banking_sepa_credit_transfer/models/__init__.py b/account_banking_sepa_credit_transfer/models/__init__.py index b67eb49ee..105896fa3 100644 --- a/account_banking_sepa_credit_transfer/models/__init__.py +++ b/account_banking_sepa_credit_transfer/models/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- -from . import payment_mode +from . import account_payment_method +from . import account_payment_order diff --git a/account_banking_sepa_credit_transfer/models/account_payment_method.py b/account_banking_sepa_credit_transfer/models/account_payment_method.py new file mode 100644 index 000000000..d29411049 --- /dev/null +++ b/account_banking_sepa_credit_transfer/models/account_payment_method.py @@ -0,0 +1,28 @@ +# -*- 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' + + pain_version = fields.Selection(selection_add=[ + ('pain.001.001.02', 'pain.001.001.02'), + ('pain.001.001.03', 'pain.001.001.03 (recommended)'), + ('pain.001.001.04', 'pain.001.001.04'), + ('pain.001.001.05', 'pain.001.001.05'), + ('pain.001.003.03', 'pain.001.003.03 (used in Germany)'), + ]) + + @api.multi + def get_xsd_file_path(self): + self.ensure_one() + if self.pain_version in [ + 'pain.001.001.02', 'pain.001.001.03', 'pain.001.001.04', + 'pain.001.001.05', 'pain.001.003.03']: + path = 'account_banking_sepa_credit_transfer/data/%s.xsd'\ + % self.pain_version + return path + return super(AccountPaymentMethod, self).get_xsd_file_path() diff --git a/account_banking_sepa_credit_transfer/wizard/export_sepa.py b/account_banking_sepa_credit_transfer/models/account_payment_order.py similarity index 52% rename from account_banking_sepa_credit_transfer/wizard/export_sepa.py rename to account_banking_sepa_credit_transfer/models/account_payment_order.py index e0e475fb9..4babb602f 100644 --- a/account_banking_sepa_credit_transfer/wizard/export_sepa.py +++ b/account_banking_sepa_credit_transfer/models/account_payment_order.py @@ -1,67 +1,28 @@ # -*- coding: utf-8 -*- -# © 2010-2015 Akretion (www.akretion.com) +# © 2010-2016 Akretion (www.akretion.com) # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields, api, _ -from openerp.exceptions import Warning -from openerp import workflow +from openerp import models, api, _ +from openerp.exceptions import UserError from lxml import etree -class BankingExportSepaWizard(models.TransientModel): - _name = 'banking.export.sepa.wizard' - _inherit = ['banking.export.pain'] - _description = 'Export SEPA Credit Transfer File' - - state = fields.Selection([ - ('create', 'Create'), - ('finish', 'Finish')], - string='State', readonly=True, default='create') - batch_booking = fields.Boolean( - string='Batch Booking', - help="If true, the bank statement will display only one debit " - "line for all the wire transfers of the SEPA XML file ; if " - "false, the bank statement will display one debit line per wire " - "transfer of the SEPA XML file.") - charge_bearer = fields.Selection([ - ('SLEV', 'Following Service Level'), - ('SHAR', 'Shared'), - ('CRED', 'Borne by Creditor'), - ('DEBT', 'Borne by Debtor')], string='Charge Bearer', - default='SLEV', required=True, - help="Following service level : transaction charges are to be " - "applied following the rules agreed in the service level " - "and/or scheme (SEPA Core messages must use this). Shared : " - "transaction charges on the debtor side are to be borne by " - "the debtor, transaction charges on the creditor side are to " - "be borne by the creditor. Borne by creditor : all " - "transaction charges are to be borne by the creditor. Borne " - "by debtor : all transaction charges are to be borne by the " - "debtor.") - nb_transactions = fields.Integer( - string='Number of Transactions', readonly=True) - total_amount = fields.Float(string='Total Amount', readonly=True) - file = fields.Binary(string="File", readonly=True) - filename = fields.Char(string="Filename", readonly=True) - payment_order_ids = fields.Many2many( - 'payment.order', 'wiz_sepa_payorders_rel', 'wizard_id', - 'payment_order_id', string='Payment Orders', readonly=True) - - @api.model - def create(self, vals): - payment_order_ids = self._context.get('active_ids', []) - vals.update({ - 'payment_order_ids': [[6, 0, payment_order_ids]], - }) - return super(BankingExportSepaWizard, self).create(vals) +class AccountPaymentOrder(models.Model): + _inherit = 'account.payment.order' @api.multi - def create_sepa(self): + def generate_payment_file(self): """Creates the SEPA Credit Transfer file. That's the important code!""" - pain_flavor = self.payment_order_ids[0].mode.type.code - convert_to_ascii = \ - self.payment_order_ids[0].mode.convert_to_ascii + self.ensure_one() + if ( + self.payment_mode_id.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 + if not pain_flavor: + pain_flavor = 'pain.001.001.03' if pain_flavor == 'pain.001.001.02': bic_xml_tag = 'BIC' name_maxsize = 70 @@ -94,24 +55,19 @@ class BankingExportSepaWizard(models.TransientModel): name_maxsize = 70 root_xml_tag = 'CstmrCdtTrfInitn' else: - raise Warning( - _("Payment Type Code '%s' is not supported. The only " - "Payment Type Codes supported for SEPA Credit Transfers " - "are 'pain.001.001.02', 'pain.001.001.03', " - "'pain.001.001.04', 'pain.001.001.05'" - " and 'pain.001.003.03'.") % - pain_flavor) + raise UserError( + _("PAIN version '%s' is not supported.") % pain_flavor) + xsd_file = self.payment_mode_id.payment_method_id.get_xsd_file_path() gen_args = { 'bic_xml_tag': bic_xml_tag, 'name_maxsize': name_maxsize, - 'convert_to_ascii': convert_to_ascii, + 'convert_to_ascii': self.payment_mode_id.convert_to_ascii, 'payment_method': 'TRF', 'file_prefix': 'sct_', 'pain_flavor': pain_flavor, - 'pain_xsd_file': - 'account_banking_sepa_credit_transfer/data/%s.xsd' - % pain_flavor, + 'pain_xsd_file': xsd_file, } + # TODO: make it inheritable pain_ns = { 'xsi': 'http://www.w3.org/2001/XMLSchema-instance', None: 'urn:iso:std:iso:20022:tech:xsd:%s' % pain_flavor, @@ -128,30 +84,27 @@ class BankingExportSepaWizard(models.TransientModel): group_header_1_0, nb_of_transactions_1_6, control_sum_1_7 = \ self.generate_group_header_block(pain_root, gen_args) transactions_count_1_6 = 0 - total_amount = 0.0 amount_control_sum_1_7 = 0.0 lines_per_group = {} # key = (requested_date, priority) # values = list of lines as object - for payment_order in self.payment_order_ids: - total_amount = total_amount + payment_order.total - for line in payment_order.bank_line_ids: - priority = line.priority - # The field line.date is the requested payment date - # taking into account the 'date_prefered' setting - # cf account_banking_payment_export/models/account_payment.py - # in the inherit of action_open() - key = (line.date, priority) - if key in lines_per_group: - lines_per_group[key].append(line) - else: - lines_per_group[key] = [line] + for line in self.bank_line_ids: + priority = line.priority + # The field line.date is the requested payment date + # taking into account the 'date_prefered' setting + # cf account_banking_payment_export/models/account_payment.py + # in the inherit of action_open() + key = (line.date, priority) + if key in lines_per_group: + lines_per_group[key].append(line) + else: + lines_per_group[key] = [line] for (requested_date, priority), lines in lines_per_group.items(): # B. Payment info payment_info_2_0, nb_of_transactions_2_4, control_sum_2_5 = \ self.generate_start_payment_info_block( pain_root, - "self.payment_order_ids[0].reference + '-' " + "self.name + '-' " "+ requested_date.replace('-', '') + '-' + priority", priority, False, False, requested_date, { 'self': self, @@ -160,15 +113,17 @@ class BankingExportSepaWizard(models.TransientModel): }, gen_args) self.generate_party_block( payment_info_2_0, 'Dbtr', 'B', - 'self.payment_order_ids[0].mode.bank_id.partner_id.' - 'name', - 'self.payment_order_ids[0].mode.bank_id.acc_number', - 'self.payment_order_ids[0].mode.bank_id.bank.bic or ' - 'self.payment_order_ids[0].mode.bank_id.bank_bic', + 'self.company_partner_bank_id.partner_id.name', + 'self.company_partner_bank_id.sanitized_acc_number', + 'self.company_partner_bank_id.bank_bic', {'self': self}, gen_args) charge_bearer_2_24 = etree.SubElement(payment_info_2_0, 'ChrgBr') - charge_bearer_2_24.text = self.charge_bearer + if self.sepa: + charge_bearer = 'SLEV' + else: + charge_bearer = self.charge_bearer + charge_bearer_2_24.text = charge_bearer transactions_count_2_4 = 0 amount_control_sum_2_5 = 0.0 for line in lines: @@ -185,7 +140,7 @@ class BankingExportSepaWizard(models.TransientModel): 'End to End Identification', 'line.name', {'line': line}, 35, gen_args=gen_args) currency_name = self._prepare_field( - 'Currency Code', 'line.currency.name', + 'Currency Code', 'line.currency_id.name', {'line': line}, 3, gen_args=gen_args) amount_2_42 = etree.SubElement( credit_transfer_transaction_info_2_27, 'Amt') @@ -194,16 +149,16 @@ class BankingExportSepaWizard(models.TransientModel): instructed_amount_2_43.text = '%.2f' % line.amount_currency amount_control_sum_1_7 += line.amount_currency amount_control_sum_2_5 += line.amount_currency - if not line.bank_id: - raise Warning( + if not line.partner_bank_id: + raise UserError( _("Bank account is missing on the bank payment line " "of partner '%s' (reference '%s').") % (line.partner_id.name, line.name)) self.generate_party_block( credit_transfer_transaction_info_2_27, 'Cdtr', - 'C', 'line.partner_id.name', 'line.bank_id.acc_number', - 'line.bank_id.bank.bic or ' - 'line.bank_id.bank_bic', {'line': line}, gen_args) + 'C', 'line.partner_id.name', + 'line.partner_bank_id.sanitized_acc_number', + 'line.partner_bank_id.bank_bic', {'line': line}, gen_args) self.generate_remittance_info_block( credit_transfer_transaction_info_2_27, line, gen_args) if pain_flavor in pain_03_to_05: @@ -215,24 +170,4 @@ class BankingExportSepaWizard(models.TransientModel): else: nb_of_transactions_1_6.text = unicode(transactions_count_1_6) control_sum_1_7.text = '%.2f' % amount_control_sum_1_7 - return self.finalize_sepa_file_creation( - xml_root, total_amount, transactions_count_1_6, gen_args) - - @api.multi - def save_sepa(self): - """Save the SEPA file: send the done signal to all payment - orders in the file. With the default workflow, they will - transition to 'done', while with the advanced workflow in - account_banking_payment they will transition to 'sent' waiting - reconciliation. - """ - for order in self.payment_order_ids: - workflow.trg_validate( - self._uid, 'payment.order', order.id, 'done', self._cr) - self.env['ir.attachment'].create({ - 'res_model': 'payment.order', - 'res_id': order.id, - 'name': self.filename, - 'datas': self.file, - }) - return True + return self.finalize_sepa_file_creation(xml_root, gen_args) diff --git a/account_banking_sepa_credit_transfer/models/payment_mode.py b/account_banking_sepa_credit_transfer/models/payment_mode.py deleted file mode 100644 index 8308c5f8e..000000000 --- a/account_banking_sepa_credit_transfer/models/payment_mode.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openerp import models - - -class PaymentMode(models.Model): - _inherit = 'payment.mode' - - def _sepa_type_get(self): - res = super(PaymentMode, self)._sepa_type_get() - if not res: - if self.type.code and self.type.code.startswith('pain.001'): - res = 'sepa_credit_transfer' - return res diff --git a/account_banking_sepa_credit_transfer/wizard/__init__.py b/account_banking_sepa_credit_transfer/wizard/__init__.py deleted file mode 100644 index fb941b55c..000000000 --- a/account_banking_sepa_credit_transfer/wizard/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2010-2013 Akretion (www.akretion.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from . import export_sepa diff --git a/account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml b/account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml deleted file mode 100644 index 38ab4b7a1..000000000 --- a/account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - banking.export.sepa.wizard.view - banking.export.sepa.wizard - -
- - - - - - - - - - - - - -
-
- -
-