diff --git a/account_banking_sepa_credit_transfer/README.rst b/account_banking_sepa_credit_transfer/README.rst index 27bddf6d1..6cdee145d 100644 --- a/account_banking_sepa_credit_transfer/README.rst +++ b/account_banking_sepa_credit_transfer/README.rst @@ -1,6 +1,7 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :alt: License: AGPL-3 +==================================== Account Banking SEPA Credit Transfer ==================================== @@ -32,16 +33,23 @@ This module is part of the OCA/bank-payment suite. Configuration ============= -No specific configuration. +* Create a Payment Mode dedicated to SEPA Credit Transfer. + +* Select the Payment Method *SEPA Credit Transfer to suppliers* (which is + automatically created upon module installation). + +* Check that this payment method uses the proper version of PAIN. Usage ===== -* You need to choose first an SEPA export type on a payment mode. +In the menu *Accounting > Payments > Payment Order*, create a new +payment order and select the Payment Mode dedicated to SEPA Credit +Transfer that you created during the configuration step. -For further information, please visit: - - * https://www.odoo.com/forum/help-1 +.. 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 Known issues / Roadmap ====================== @@ -51,10 +59,10 @@ Known issues / Roadmap 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 -`here `_. +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 ======= @@ -62,7 +70,7 @@ Credits Contributors ------------ -* Alexis de Lattre +* Alexis de Lattre * Pedro M. Baeza * Stéphane Bidoul * Stefan Rijnhart diff --git a/account_banking_sepa_credit_transfer/__init__.py b/account_banking_sepa_credit_transfer/__init__.py index 31b508d85..a1815ae51 100644 --- a/account_banking_sepa_credit_transfer/__init__.py +++ b/account_banking_sepa_credit_transfer/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -# © 2010-2013 Akretion (www.akretion.com) from . import models -from . import wizard +from .post_install import update_bank_journals diff --git a/account_banking_sepa_credit_transfer/__openerp__.py b/account_banking_sepa_credit_transfer/__openerp__.py index e070443b7..90f509f2d 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,14 @@ "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' ], + 'post_init_hook': 'update_bank_journals', '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..438346067 --- /dev/null +++ b/account_banking_sepa_credit_transfer/data/account_payment_method.xml @@ -0,0 +1,16 @@ + + + + + + + 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..224237ed1 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,22 @@ - - 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..13f8930db --- /dev/null +++ b/account_banking_sepa_credit_transfer/models/account_payment_method.py @@ -0,0 +1,29 @@ +# -*- 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 for credit transfer)'), + ('pain.001.001.04', 'pain.001.001.04'), + ('pain.001.001.05', 'pain.001.001.05'), + ('pain.001.003.03', 'pain.001.003.03 (credit transfer 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/models/account_payment_order.py b/account_banking_sepa_credit_transfer/models/account_payment_order.py new file mode 100644 index 000000000..85c94c724 --- /dev/null +++ b/account_banking_sepa_credit_transfer/models/account_payment_order.py @@ -0,0 +1,163 @@ +# -*- coding: utf-8 -*- +# © 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, api, _ +from openerp.exceptions import UserError +from lxml import etree + + +class AccountPaymentOrder(models.Model): + _inherit = 'account.payment.order' + + @api.multi + def generate_payment_file(self): + """Creates the SEPA Credit Transfer file. That's the important code!""" + self.ensure_one() + if self.payment_method_id.code != 'sepa_credit_transfer': + return super(AccountPaymentOrder, self).generate_payment_file() + + 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') + # to support country-specific extensions such as + # pain.001.001.03.ch.02 (cf l10n_ch_sepa) + if pain_flavor.startswith('pain.001.001.02'): + bic_xml_tag = 'BIC' + name_maxsize = 70 + root_xml_tag = 'pain.001.001.02' + elif pain_flavor.startswith('pain.001.001.03'): + bic_xml_tag = 'BIC' + # size 70 -> 140 for with pain.001.001.03 + # BUT the European Payment Council, in the document + # "SEPA Credit Transfer Scheme Customer-to-bank + # Implementation guidelines" v6.0 available on + # http://www.europeanpaymentscouncil.eu/knowledge_bank.cfm + # says that 'Nm' should be limited to 70 + # so we follow the "European Payment Council" + # and we put 70 and not 140 + name_maxsize = 70 + root_xml_tag = 'CstmrCdtTrfInitn' + elif pain_flavor.startswith('pain.001.001.04'): + bic_xml_tag = 'BICFI' + name_maxsize = 140 + root_xml_tag = 'CstmrCdtTrfInitn' + elif pain_flavor.startswith('pain.001.001.05'): + bic_xml_tag = 'BICFI' + name_maxsize = 140 + root_xml_tag = 'CstmrCdtTrfInitn' + # added pain.001.003.03 for German Banks + # it is not in the offical ISO 20022 documentations, but nearly all + # german banks are working with this instead 001.001.03 + elif pain_flavor == 'pain.001.003.03': + bic_xml_tag = 'BIC' + name_maxsize = 70 + root_xml_tag = 'CstmrCdtTrfInitn' + else: + raise UserError( + _("PAIN version '%s' is not supported.") % pain_flavor) + 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': self.payment_method_id.convert_to_ascii, + 'payment_method': 'TRF', + 'file_prefix': 'sct_', + 'pain_flavor': pain_flavor, + 'pain_xsd_file': xsd_file, + } + nsmap = self.generate_pain_nsmap() + attrib = self.generate_pain_attrib() + xml_root = etree.Element('Document', nsmap=nsmap, attrib=attrib) + pain_root = etree.SubElement(xml_root, root_xml_tag) + # A. Group header + group_header, nb_of_transactions_a, control_sum_a = \ + self.generate_group_header_block(pain_root, gen_args) + transactions_count_a = 0 + amount_control_sum_a = 0.0 + lines_per_group = {} + # key = (requested_date, priority, local_instrument) + # values = list of lines as object + for line in self.bank_line_ids: + priority = line.priority + local_instrument = line.local_instrument + # 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, local_instrument) + if key in lines_per_group: + lines_per_group[key].append(line) + else: + lines_per_group[key] = [line] + for (requested_date, priority, local_instrument), lines in\ + lines_per_group.items(): + # B. Payment info + payment_info, nb_of_transactions_b, control_sum_b = \ + self.generate_start_payment_info_block( + pain_root, + "self.name + '-' " + "+ requested_date.replace('-', '') + '-' + priority + " + "'-' + local_instrument", + priority, local_instrument, False, requested_date, { + 'self': self, + 'priority': priority, + 'requested_date': requested_date, + 'local_instrument': local_instrument or 'NOinstr', + }, gen_args) + self.generate_party_block( + payment_info, 'Dbtr', 'B', + self.company_partner_bank_id, gen_args) + charge_bearer = etree.SubElement(payment_info, 'ChrgBr') + if self.sepa: + charge_bearer_text = 'SLEV' + else: + charge_bearer_text = self.charge_bearer + charge_bearer.text = charge_bearer_text + transactions_count_b = 0 + amount_control_sum_b = 0.0 + for line in lines: + transactions_count_a += 1 + transactions_count_b += 1 + # C. Credit Transfer Transaction Info + credit_transfer_transaction_info = etree.SubElement( + payment_info, 'CdtTrfTxInf') + payment_identification = etree.SubElement( + credit_transfer_transaction_info, 'PmtId') + end2end_identification = etree.SubElement( + payment_identification, 'EndToEndId') + end2end_identification.text = self._prepare_field( + 'End to End Identification', 'line.name', + {'line': line}, 35, gen_args=gen_args) + currency_name = self._prepare_field( + 'Currency Code', 'line.currency_id.name', + {'line': line}, 3, gen_args=gen_args) + amount = etree.SubElement( + credit_transfer_transaction_info, 'Amt') + instructed_amount = etree.SubElement( + amount, 'InstdAmt', Ccy=currency_name) + instructed_amount.text = '%.2f' % line.amount_currency + amount_control_sum_a += line.amount_currency + amount_control_sum_b += line.amount_currency + 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, 'Cdtr', + 'C', line.partner_bank_id, gen_args, line) + self.generate_remittance_info_block( + credit_transfer_transaction_info, line, gen_args) + if not pain_flavor.startswith('pain.001.001.02'): + nb_of_transactions_b.text = unicode(transactions_count_b) + control_sum_b.text = '%.2f' % amount_control_sum_b + if not pain_flavor.startswith('pain.001.001.02'): + nb_of_transactions_a.text = unicode(transactions_count_a) + control_sum_a.text = '%.2f' % amount_control_sum_a + else: + nb_of_transactions_a.text = unicode(transactions_count_a) + control_sum_a.text = '%.2f' % amount_control_sum_a + 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/post_install.py b/account_banking_sepa_credit_transfer/post_install.py new file mode 100644 index 000000000..631bef653 --- /dev/null +++ b/account_banking_sepa_credit_transfer/post_install.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import SUPERUSER_ID + + +def update_bank_journals(cr, pool): + ajo = pool['account.journal'] + journal_ids = ajo.search( + cr, SUPERUSER_ID, [('type', '=', 'bank')]) + sct_id = pool['ir.model.data'].xmlid_to_res_id( + cr, SUPERUSER_ID, + 'account_banking_sepa_credit_transfer.sepa_credit_transfer') + if sct_id: + ajo.write(cr, SUPERUSER_ID, journal_ids, { + 'outbound_payment_method_ids': [(4, sct_id)], + }) + return diff --git a/account_banking_sepa_credit_transfer/tests/__init__.py b/account_banking_sepa_credit_transfer/tests/__init__.py new file mode 100644 index 000000000..97a8c4298 --- /dev/null +++ b/account_banking_sepa_credit_transfer/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_sct diff --git a/account_banking_sepa_credit_transfer/tests/test_sct.py b/account_banking_sepa_credit_transfer/tests/test_sct.py new file mode 100644 index 000000000..76cb72aab --- /dev/null +++ b/account_banking_sepa_credit_transfer/tests/test_sct.py @@ -0,0 +1,251 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.addons.account.tests.account_test_classes\ + import AccountingTestCase +from openerp.tools import float_compare +import time +from lxml import etree + + +class TestSCT(AccountingTestCase): + + def setUp(self): + super(TestSCT, self).setUp() + self.account_model = self.env['account.account'] + self.move_model = self.env['account.move'] + self.journal_model = self.env['account.journal'] + self.payment_order_model = self.env['account.payment.order'] + self.payment_line_model = self.env['account.payment.line'] + self.bank_line_model = self.env['bank.payment.line'] + self.partner_bank_model = self.env['res.partner.bank'] + self.attachment_model = self.env['ir.attachment'] + self.invoice_model = self.env['account.invoice'] + self.invoice_line_model = self.env['account.invoice.line'] + self.main_company = self.env.ref('base.main_company') + self.partner_agrolait = self.env.ref('base.res_partner_2') + self.partner_asus = self.env.ref('base.res_partner_1') + self.partner_c2c = self.env.ref('base.res_partner_12') + self.account_expense = self.account_model.search([( + 'user_type_id', + '=', + self.env.ref('account.data_account_type_expenses').id)], limit=1) + self.account_payable = self.account_model.search([( + 'user_type_id', + '=', + self.env.ref('account.data_account_type_payable').id)], limit=1) + # create journal + self.bank_journal = self.journal_model.create({ + 'name': 'Company Bank journal', + 'type': 'bank', + 'code': 'BNKFB', + 'bank_account_id': + self.env.ref('account_payment_mode.main_company_iban').id, + 'bank_id': + self.env.ref('account_payment_mode.bank_la_banque_postale').id, + }) + # update payment mode + self.payment_mode = self.env.ref( + 'account_banking_sepa_credit_transfer.' + 'payment_mode_outbound_sepa_ct1') + self.payment_mode.write({ + 'bank_account_link': 'fixed', + 'fixed_journal_id': self.bank_journal.id, + }) + self.eur_currency = self.env.ref('base.EUR') + self.usd_currency = self.env.ref('base.USD') + self.main_company.currency_id = self.eur_currency.id + + def test_eur_currency_sct(self): + invoice1 = self.create_invoice( + self.partner_agrolait.id, + 'account_payment_mode.res_partner_2_iban', self.eur_currency.id, + 42.0, 'F1341') + invoice2 = self.create_invoice( + self.partner_agrolait.id, + 'account_payment_mode.res_partner_2_iban', self.eur_currency.id, + 12.0, 'F1342') + invoice3 = self.create_invoice( + self.partner_agrolait.id, + 'account_payment_mode.res_partner_2_iban', self.eur_currency.id, + 5.0, 'A1301', 'in_refund') + invoice4 = self.create_invoice( + self.partner_c2c.id, + 'account_payment_mode.res_partner_12_iban', self.eur_currency.id, + 11.0, 'I1642') + invoice5 = self.create_invoice( + self.partner_c2c.id, + 'account_payment_mode.res_partner_12_iban', self.eur_currency.id, + 41.0, 'I1643') + for inv in [invoice1, invoice2, invoice3, invoice4, invoice5]: + action = inv.create_account_payment_line() + self.assertEquals(action['res_model'], 'account.payment.order') + self.payment_order = self.payment_order_model.browse(action['res_id']) + self.assertEquals( + self.payment_order.payment_type, 'outbound') + self.assertEquals( + self.payment_order.payment_mode_id, self.payment_mode) + self.assertEquals( + self.payment_order.journal_id, self.bank_journal) + pay_lines = self.payment_line_model.search([ + ('partner_id', '=', self.partner_agrolait.id), + ('order_id', '=', self.payment_order.id)]) + self.assertEquals(len(pay_lines), 3) + agrolait_pay_line1 = pay_lines[0] + accpre = self.env['decimal.precision'].precision_get('Account') + self.assertEquals(agrolait_pay_line1.currency_id, self.eur_currency) + self.assertEquals( + agrolait_pay_line1.partner_bank_id, invoice1.partner_bank_id) + self.assertEquals(float_compare( + agrolait_pay_line1.amount_currency, 42, precision_digits=accpre), + 0) + self.assertEquals(agrolait_pay_line1.communication_type, 'normal') + self.assertEquals(agrolait_pay_line1.communication, 'F1341') + self.payment_order.draft2open() + self.assertEquals(self.payment_order.state, 'open') + self.assertEquals(self.payment_order.sepa, True) + bank_lines = self.bank_line_model.search([ + ('partner_id', '=', self.partner_agrolait.id)]) + self.assertEquals(len(bank_lines), 1) + agrolait_bank_line = bank_lines[0] + self.assertEquals(agrolait_bank_line.currency_id, self.eur_currency) + self.assertEquals(float_compare( + agrolait_bank_line.amount_currency, 49.0, precision_digits=accpre), + 0) + self.assertEquals(agrolait_bank_line.communication_type, 'normal') + self.assertEquals( + agrolait_bank_line.communication, 'F1341-F1342-A1301') + self.assertEquals( + agrolait_bank_line.partner_bank_id, invoice1.partner_bank_id) + + action = self.payment_order.open2generated() + self.assertEquals(self.payment_order.state, 'generated') + self.assertEquals(action['res_model'], 'ir.attachment') + attachment = self.attachment_model.browse(action['res_id']) + self.assertEquals(attachment.datas_fname[-4:], '.xml') + xml_file = attachment.datas.decode('base64') + xml_root = etree.fromstring(xml_file) + # print "xml_file=", etree.tostring(xml_root, pretty_print=True) + namespaces = xml_root.nsmap + namespaces['p'] = xml_root.nsmap[None] + namespaces.pop(None) + pay_method_xpath = xml_root.xpath( + '//p:PmtInf/p:PmtMtd', namespaces=namespaces) + self.assertEquals(pay_method_xpath[0].text, 'TRF') + sepa_xpath = xml_root.xpath( + '//p:PmtInf/p:PmtTpInf/p:SvcLvl/p:Cd', namespaces=namespaces) + self.assertEquals(sepa_xpath[0].text, 'SEPA') + debtor_acc_xpath = xml_root.xpath( + '//p:PmtInf/p:DbtrAcct/p:Id/p:IBAN', namespaces=namespaces) + self.assertEquals( + debtor_acc_xpath[0].text, + self.payment_order.company_partner_bank_id.sanitized_acc_number) + self.payment_order.generated2uploaded() + self.assertEquals(self.payment_order.state, 'uploaded') + for inv in [invoice1, invoice2, invoice3, invoice4, invoice5]: + self.assertEquals(inv.state, 'paid') + return + + def test_usd_currency_sct(self): + invoice1 = self.create_invoice( + self.partner_asus.id, + 'account_payment_mode.res_partner_2_iban', self.usd_currency.id, + 2042.0, 'Inv9032') + invoice2 = self.create_invoice( + self.partner_asus.id, + 'account_payment_mode.res_partner_2_iban', self.usd_currency.id, + 1012.0, 'Inv9033') + for inv in [invoice1, invoice2]: + action = inv.create_account_payment_line() + self.assertEquals(action['res_model'], 'account.payment.order') + self.payment_order = self.payment_order_model.browse(action['res_id']) + self.assertEquals( + self.payment_order.payment_type, 'outbound') + self.assertEquals( + self.payment_order.payment_mode_id, self.payment_mode) + self.assertEquals( + self.payment_order.journal_id, self.bank_journal) + pay_lines = self.payment_line_model.search([ + ('partner_id', '=', self.partner_asus.id), + ('order_id', '=', self.payment_order.id)]) + self.assertEquals(len(pay_lines), 2) + asus_pay_line1 = pay_lines[0] + accpre = self.env['decimal.precision'].precision_get('Account') + self.assertEquals(asus_pay_line1.currency_id, self.usd_currency) + self.assertEquals( + asus_pay_line1.partner_bank_id, invoice1.partner_bank_id) + self.assertEquals(float_compare( + asus_pay_line1.amount_currency, 2042, precision_digits=accpre), + 0) + self.assertEquals(asus_pay_line1.communication_type, 'normal') + self.assertEquals(asus_pay_line1.communication, 'Inv9032') + self.payment_order.draft2open() + self.assertEquals(self.payment_order.state, 'open') + self.assertEquals(self.payment_order.sepa, False) + bank_lines = self.bank_line_model.search([ + ('partner_id', '=', self.partner_asus.id)]) + self.assertEquals(len(bank_lines), 1) + asus_bank_line = bank_lines[0] + self.assertEquals(asus_bank_line.currency_id, self.usd_currency) + self.assertEquals(float_compare( + asus_bank_line.amount_currency, 3054.0, precision_digits=accpre), + 0) + self.assertEquals(asus_bank_line.communication_type, 'normal') + self.assertEquals( + asus_bank_line.communication, 'Inv9032-Inv9033') + self.assertEquals( + asus_bank_line.partner_bank_id, invoice1.partner_bank_id) + + action = self.payment_order.open2generated() + self.assertEquals(self.payment_order.state, 'generated') + self.assertEquals(action['res_model'], 'ir.attachment') + attachment = self.attachment_model.browse(action['res_id']) + self.assertEquals(attachment.datas_fname[-4:], '.xml') + xml_file = attachment.datas.decode('base64') + xml_root = etree.fromstring(xml_file) + # print "xml_file=", etree.tostring(xml_root, pretty_print=True) + namespaces = xml_root.nsmap + namespaces['p'] = xml_root.nsmap[None] + namespaces.pop(None) + pay_method_xpath = xml_root.xpath( + '//p:PmtInf/p:PmtMtd', namespaces=namespaces) + self.assertEquals(pay_method_xpath[0].text, 'TRF') + sepa_xpath = xml_root.xpath( + '//p:PmtInf/p:PmtTpInf/p:SvcLvl/p:Cd', namespaces=namespaces) + self.assertEquals(len(sepa_xpath), 0) + debtor_acc_xpath = xml_root.xpath( + '//p:PmtInf/p:DbtrAcct/p:Id/p:IBAN', namespaces=namespaces) + self.assertEquals( + debtor_acc_xpath[0].text, + self.payment_order.company_partner_bank_id.sanitized_acc_number) + self.payment_order.generated2uploaded() + self.assertEquals(self.payment_order.state, 'uploaded') + for inv in [invoice1, invoice2]: + self.assertEquals(inv.state, 'paid') + return + + def create_invoice( + self, partner_id, partner_bank_xmlid, currency_id, + price_unit, reference, type='in_invoice'): + invoice = self.invoice_model.create({ + 'partner_id': partner_id, + 'reference_type': 'none', + 'reference': reference, + 'currency_id': currency_id, + 'name': 'test', + 'account_id': self.account_payable.id, + 'type': type, + 'date_invoice': time.strftime('%Y-%m-%d'), + 'payment_mode_id': self.payment_mode.id, + 'partner_bank_id': self.env.ref(partner_bank_xmlid).id, + }) + self.invoice_line_model.create({ + 'invoice_id': invoice.id, + 'price_unit': price_unit, + 'quantity': 1, + 'name': 'Great service', + 'account_id': self.account_expense.id, + }) + invoice.signal_workflow('invoice_open') + return invoice 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.py b/account_banking_sepa_credit_transfer/wizard/export_sepa.py deleted file mode 100644 index e0e475fb9..000000000 --- a/account_banking_sepa_credit_transfer/wizard/export_sepa.py +++ /dev/null @@ -1,238 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2010-2015 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 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) - - @api.multi - def create_sepa(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 - if pain_flavor == 'pain.001.001.02': - bic_xml_tag = 'BIC' - name_maxsize = 70 - root_xml_tag = 'pain.001.001.02' - elif pain_flavor == 'pain.001.001.03': - bic_xml_tag = 'BIC' - # size 70 -> 140 for with pain.001.001.03 - # BUT the European Payment Council, in the document - # "SEPA Credit Transfer Scheme Customer-to-bank - # Implementation guidelines" v6.0 available on - # http://www.europeanpaymentscouncil.eu/knowledge_bank.cfm - # says that 'Nm' should be limited to 70 - # so we follow the "European Payment Council" - # and we put 70 and not 140 - name_maxsize = 70 - root_xml_tag = 'CstmrCdtTrfInitn' - elif pain_flavor == 'pain.001.001.04': - bic_xml_tag = 'BICFI' - name_maxsize = 140 - root_xml_tag = 'CstmrCdtTrfInitn' - elif pain_flavor == 'pain.001.001.05': - bic_xml_tag = 'BICFI' - name_maxsize = 140 - root_xml_tag = 'CstmrCdtTrfInitn' - # added pain.001.003.03 for German Banks - # it is not in the offical ISO 20022 documentations, but nearly all - # german banks are working with this instead 001.001.03 - elif pain_flavor == 'pain.001.003.03': - bic_xml_tag = 'BIC' - 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) - gen_args = { - 'bic_xml_tag': bic_xml_tag, - 'name_maxsize': name_maxsize, - 'convert_to_ascii': 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_ns = { - 'xsi': 'http://www.w3.org/2001/XMLSchema-instance', - None: 'urn:iso:std:iso:20022:tech:xsd:%s' % pain_flavor, - } - xml_root = etree.Element('Document', nsmap=pain_ns) - pain_root = etree.SubElement(xml_root, root_xml_tag) - pain_03_to_05 = [ - 'pain.001.001.03', - 'pain.001.001.04', - 'pain.001.001.05', - 'pain.001.003.03' - ] - # A. Group header - 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 (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 + '-' " - "+ requested_date.replace('-', '') + '-' + priority", - priority, False, False, requested_date, { - 'self': self, - 'priority': priority, - 'requested_date': requested_date, - }, 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': self}, - gen_args) - charge_bearer_2_24 = etree.SubElement(payment_info_2_0, 'ChrgBr') - charge_bearer_2_24.text = self.charge_bearer - transactions_count_2_4 = 0 - amount_control_sum_2_5 = 0.0 - for line in lines: - transactions_count_1_6 += 1 - transactions_count_2_4 += 1 - # C. Credit Transfer Transaction Info - credit_transfer_transaction_info_2_27 = etree.SubElement( - payment_info_2_0, 'CdtTrfTxInf') - payment_identification_2_28 = etree.SubElement( - credit_transfer_transaction_info_2_27, 'PmtId') - end2end_identification_2_30 = etree.SubElement( - payment_identification_2_28, 'EndToEndId') - end2end_identification_2_30.text = self._prepare_field( - 'End to End Identification', 'line.name', - {'line': line}, 35, gen_args=gen_args) - currency_name = self._prepare_field( - 'Currency Code', 'line.currency.name', - {'line': line}, 3, gen_args=gen_args) - amount_2_42 = etree.SubElement( - credit_transfer_transaction_info_2_27, 'Amt') - instructed_amount_2_43 = etree.SubElement( - amount_2_42, 'InstdAmt', Ccy=currency_name) - 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( - _("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) - self.generate_remittance_info_block( - credit_transfer_transaction_info_2_27, line, gen_args) - if pain_flavor in pain_03_to_05: - nb_of_transactions_2_4.text = unicode(transactions_count_2_4) - control_sum_2_5.text = '%.2f' % amount_control_sum_2_5 - if pain_flavor in pain_03_to_05: - nb_of_transactions_1_6.text = unicode(transactions_count_1_6) - control_sum_1_7.text = '%.2f' % amount_control_sum_1_7 - 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 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 - -
- - - - - - - - - - - - - -
-
- -
-