mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
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
This commit is contained in:
committed by
Enric Tobella
parent
ea338023f9
commit
af9874054c
@@ -2,4 +2,3 @@
|
||||
# © 2010-2013 Akretion (www.akretion.com)
|
||||
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
|
||||
|
||||
<record id="sepa_credit_transfer" model="account.payment.method">
|
||||
<field name="name">SEPA Credit Transfer to suppliers</field>
|
||||
<field name="code">sepa_credit_transfer</field>
|
||||
<field name="payment_type">outbound</field>
|
||||
<field name="pain_version">pain.001.001.03</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
|
||||
|
||||
<!-- TODO In the suitable_bank_types field, we should restrict to IBAN type and Rib+IBAN of l10n_fr_rib ? -->
|
||||
<record id="export_sepa_sct_001_001_05" model="payment.mode.type">
|
||||
<field name="name">SEPA Credit Transfer v05</field>
|
||||
<field name="code">pain.001.001.05</field>
|
||||
<field name="payment_order_type">payment</field>
|
||||
<field name="suitable_bank_types"
|
||||
eval="[(6,0,[ref('base_iban.bank_iban')])]" />
|
||||
<field name="ir_model_id" ref="model_banking_export_sepa_wizard"/>
|
||||
</record>
|
||||
|
||||
<record id="export_sepa_sct_001_001_04" model="payment.mode.type">
|
||||
<field name="name">SEPA Credit Transfer v04</field>
|
||||
<field name="code">pain.001.001.04</field>
|
||||
<field name="payment_order_type">payment</field>
|
||||
<field name="suitable_bank_types"
|
||||
eval="[(6,0,[ref('base_iban.bank_iban')])]" />
|
||||
<field name="ir_model_id" ref="model_banking_export_sepa_wizard"/>
|
||||
</record>
|
||||
|
||||
<record id="export_sepa_sct_001_001_03" model="payment.mode.type">
|
||||
<field name="name">SEPA Credit Transfer v03 (recommended)</field>
|
||||
<field name="code">pain.001.001.03</field>
|
||||
<field name="payment_order_type">payment</field>
|
||||
<field name="suitable_bank_types"
|
||||
eval="[(6,0,[ref('base_iban.bank_iban')])]" />
|
||||
<field name="ir_model_id" ref="model_banking_export_sepa_wizard"/>
|
||||
</record>
|
||||
|
||||
<record id="export_sepa_sct_001_001_02" model="payment.mode.type">
|
||||
<field name="name">SEPA Credit Transfer v02</field>
|
||||
<field name="code">pain.001.001.02</field>
|
||||
<field name="payment_order_type">payment</field>
|
||||
<field name="suitable_bank_types"
|
||||
eval="[(6,0,[ref('base_iban.bank_iban')])]" />
|
||||
<field name="ir_model_id" ref="model_banking_export_sepa_wizard"/>
|
||||
</record>
|
||||
|
||||
<record id="export_sepa_sct_001_003_03" model="payment.mode.type">
|
||||
<field name="name">SEPA Credit Transfer pain 001.003.03 (used in Germany)</field>
|
||||
<field name="code">pain.001.003.03</field>
|
||||
<field name="payment_order_type">payment</field>
|
||||
<field name="suitable_bank_types"
|
||||
eval="[(6,0,[ref('base_iban.bank_iban')])]" />
|
||||
<field name="ir_model_id" ref="model_banking_export_sepa_wizard"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -3,13 +3,12 @@
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="sepa_credit_transfer_mode" model="payment.mode">
|
||||
<field name="name">SEPA Credit Transfer La Banque Postale</field>
|
||||
<field name="journal" ref="account.bank_journal"/>
|
||||
<field name="bank_id" ref="account_banking_payment_export.main_company_iban"/>
|
||||
<record id="payment_mode_outbound_sepa_ct1" model="account.payment.mode">
|
||||
<field name="name">SEPA Credit Transfer to suppliers</field>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
<field name="type" ref="export_sepa_sct_001_001_03"/>
|
||||
<field name="sale_ok" eval="False"/>
|
||||
<field name="bank_account_link">variable</field>
|
||||
<field name="payment_method_id" ref="sepa_credit_transfer"/>
|
||||
<field name="default_journal_ids" search="[('type', 'in', ('purchase', 'purchase_refund'))]"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import payment_mode
|
||||
from . import account_payment_method
|
||||
from . import account_payment_order
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# -*- 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'
|
||||
|
||||
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()
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2010-2015 Akretion (http://www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="banking_export_sepa_wizard_view" model="ir.ui.view">
|
||||
<field name="name">banking.export.sepa.wizard.view</field>
|
||||
<field name="model">banking.export.sepa.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="SEPA File Generation">
|
||||
<field name="state" invisible="True"/>
|
||||
<group states="create">
|
||||
<field name="batch_booking" />
|
||||
<field name="charge_bearer" />
|
||||
</group>
|
||||
<group states="finish">
|
||||
<field name="total_amount" />
|
||||
<field name="nb_transactions" />
|
||||
<field name="file" filename="filename" />
|
||||
<field name="filename" invisible="True"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Generate" name="create_sepa" type="object" class="oe_highlight" states="create"/>
|
||||
<button string="Validate" name="save_sepa" type="object" class="oe_highlight" states="finish"/>
|
||||
<button string="Cancel" special="cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user