mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Merge pull request #172 from akretion/8.0-fix-bug-111-add-initiating_party_identifier
Fix bug #111 New field initiating_party_identifier on res.companyi
This commit is contained in:
@@ -21,3 +21,4 @@
|
||||
##############################################################################
|
||||
|
||||
from . import models
|
||||
from .post_install import set_default_initiating_party
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
{
|
||||
'name': 'Account Banking PAIN Base Module',
|
||||
'summary': 'Base module for PAIN file generation',
|
||||
'version': '0.1',
|
||||
'version': '0.2',
|
||||
'license': 'AGPL-3',
|
||||
'author': "Akretion, "
|
||||
"Noviat, "
|
||||
@@ -40,6 +40,7 @@
|
||||
'views/payment_mode_view.xml',
|
||||
'views/res_company_view.xml',
|
||||
],
|
||||
'post_init_hook': 'set_default_initiating_party',
|
||||
'description': '''
|
||||
Base module for PAIN file generation
|
||||
====================================
|
||||
|
||||
@@ -6,8 +6,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 8.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2014-10-31 22:52+0000\n"
|
||||
"PO-Revision-Date: 2014-10-31 22:52+0000\n"
|
||||
"POT-Creation-Date: 2015-06-01 17:20+0000\n"
|
||||
"PO-Revision-Date: 2015-06-01 17:20+0000\n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
@@ -16,13 +16,18 @@ msgstr ""
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:74
|
||||
#: model:ir.model,name:account_banking_pain_base.model_res_partner_bank
|
||||
msgid "Bank Accounts"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:79
|
||||
#, python-format
|
||||
msgid "Cannot compute the '%s' of the Payment Line with reference '%s'."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:80
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:85
|
||||
#, python-format
|
||||
msgid "Cannot compute the '%s'."
|
||||
msgstr ""
|
||||
@@ -38,19 +43,19 @@ msgid "Convert to ASCII"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:47
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:73
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:79
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:89
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:124
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:303
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:385
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:52
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:78
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:84
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:94
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:129
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:313
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:395
|
||||
#, python-format
|
||||
msgid "Error:"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:83
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:88
|
||||
#, python-format
|
||||
msgid "Field type error:"
|
||||
msgstr ""
|
||||
@@ -70,13 +75,18 @@ msgstr ""
|
||||
msgid "If active, Odoo will convert each accented caracter to the corresponding unaccented caracter, so that only ASCII caracters are used in the generated PAIN file."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: field:res.company,initiating_party_identifier:0
|
||||
msgid "Initiating Party Identifier"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: field:res.company,initiating_party_issuer:0
|
||||
msgid "Initiating Party Issuer"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:386
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:396
|
||||
#, python-format
|
||||
msgid "Missing 'Structured Communication Type' on payment line with reference '%s'."
|
||||
msgstr ""
|
||||
@@ -112,31 +122,31 @@ msgid "Structured Communication Type"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:90
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:95
|
||||
#, python-format
|
||||
msgid "The '%s' is empty or 0. It should have a non-null value."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:304
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:314
|
||||
#, python-format
|
||||
msgid "The bank account with IBAN '%s' of partner '%s' must have an associated BIC because it is a cross-border SEPA operation."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:125
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:130
|
||||
#, python-format
|
||||
msgid "The generated XML file is not valid against the official XML Schema Definition. The generated XML file and the full error have been written in the server logs. Here is the error, which may give you an idea on the cause of the problem : %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:84
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:89
|
||||
#, python-format
|
||||
msgid "The type of the field '%s' is %s. It should be a string or unicode."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:47
|
||||
#: code:addons/account_banking_pain_base/models/banking_export_pain.py:52
|
||||
#, python-format
|
||||
msgid "This IBAN is not valid : %s"
|
||||
msgstr ""
|
||||
@@ -146,6 +156,11 @@ msgstr ""
|
||||
msgid "This field will be used as the 'Instruction Priority' in the generated PAIN file."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: help:res.company,initiating_party_identifier:0
|
||||
msgid "This will be used as the 'Initiating Party Identifier' in the PAIN files generated by Odoo."
|
||||
msgstr ""
|
||||
|
||||
#. module: account_banking_pain_base
|
||||
#: help:res.company,initiating_party_issuer:0
|
||||
msgid "This will be used as the 'Initiating Party Issuer' in the PAIN files generated by Odoo."
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.addons.account_banking_pain_base.post_install\
|
||||
import set_default_initiating_party
|
||||
from openerp import pooler
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
set_default_initiating_party(cr, pool)
|
||||
@@ -246,6 +246,11 @@ class BankingExportPain(orm.AbstractModel):
|
||||
requested_date_2_17.text = requested_date
|
||||
return payment_info_2_0, nb_of_transactions_2_4, control_sum_2_5
|
||||
|
||||
def _must_have_initiating_party(self, cr, uid, gen_args, context=None):
|
||||
'''This method is designed to be inherited in localization modules for
|
||||
countries in which the initiating party is required'''
|
||||
return False
|
||||
|
||||
def generate_initiating_party_block(
|
||||
self, cr, uid, parent_node, gen_args, context=None):
|
||||
my_company_name = self._prepare_field(
|
||||
@@ -256,13 +261,12 @@ class BankingExportPain(orm.AbstractModel):
|
||||
initiating_party_1_8 = etree.SubElement(parent_node, 'InitgPty')
|
||||
initiating_party_name = etree.SubElement(initiating_party_1_8, 'Nm')
|
||||
initiating_party_name.text = my_company_name
|
||||
initiating_party_identifier = self.pool['res.company'].\
|
||||
_get_initiating_party_identifier(
|
||||
cr, uid,
|
||||
gen_args['sepa_export'].payment_order_ids[0].company_id.id,
|
||||
context=context)
|
||||
initiating_party_issuer = gen_args['sepa_export'].\
|
||||
payment_order_ids[0].company_id.initiating_party_issuer
|
||||
initiating_party_identifier =\
|
||||
gen_args['sepa_export'].payment_order_ids[0].company_id.\
|
||||
initiating_party_identifier
|
||||
initiating_party_issuer =\
|
||||
gen_args['sepa_export'].payment_order_ids[0].company_id.\
|
||||
initiating_party_issuer
|
||||
if initiating_party_identifier and initiating_party_issuer:
|
||||
iniparty_id = etree.SubElement(initiating_party_1_8, 'Id')
|
||||
iniparty_org_id = etree.SubElement(iniparty_id, 'OrgId')
|
||||
@@ -272,6 +276,14 @@ class BankingExportPain(orm.AbstractModel):
|
||||
iniparty_org_other_issuer = etree.SubElement(
|
||||
iniparty_org_other, 'Issr')
|
||||
iniparty_org_other_issuer.text = initiating_party_issuer
|
||||
elif self._must_have_initiating_party(cr, uid, gen_args,
|
||||
context=context):
|
||||
raise orm.except_orm(
|
||||
_('Error:'),
|
||||
_("Missing 'Initiating Party Issuer' and/or "
|
||||
"'Initiating Party Identifier' for the company '%s'. "
|
||||
"Both fields must have a value.")
|
||||
% gen_args['sepa_export'].payment_order_ids[0].company_id.name)
|
||||
return True
|
||||
|
||||
def generate_party_agent(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# PAIN Base module for OpenERP
|
||||
# Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
# Copyright (C) 2013-2015 Akretion (http://www.akretion.com)
|
||||
# Copyright (C) 2013 Noviat (http://www.noviat.com)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# @author: Luc de Meyer (Noviat)
|
||||
@@ -22,59 +22,50 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import orm, fields
|
||||
from openerp import models, fields, api
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ResCompany(orm.Model):
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
_columns = {
|
||||
'initiating_party_issuer': fields.char(
|
||||
'Initiating Party Issuer', size=35,
|
||||
help="This will be used as the 'Initiating Party Issuer' in the "
|
||||
"PAIN files generated by Odoo."),
|
||||
}
|
||||
initiating_party_issuer = fields.Char(
|
||||
string='Initiating Party Issuer', size=35,
|
||||
help="This will be used as the 'Initiating Party Issuer' in the "
|
||||
"PAIN files generated by Odoo.")
|
||||
initiating_party_identifier = fields.Char(
|
||||
string='Initiating Party Identifier', size=35,
|
||||
help="This will be used as the 'Initiating Party Identifier' in "
|
||||
"the PAIN files generated by Odoo.")
|
||||
|
||||
def _get_initiating_party_identifier(
|
||||
self, cr, uid, company_id, context=None):
|
||||
"""The code here may be different from one country to another.
|
||||
If you need to add support for an additionnal country, you can
|
||||
contribute your code here or inherit this function in the
|
||||
localization modules for your country"""
|
||||
assert isinstance(company_id, int), 'Only one company ID'
|
||||
company = self.browse(cr, uid, company_id, context=context)
|
||||
company_vat = company.vat
|
||||
party_identifier = company.sepa_creditor_identifier
|
||||
if not party_identifier and company_vat:
|
||||
country_code = company_vat[0:2].upper()
|
||||
if country_code == 'BE':
|
||||
party_identifier = company_vat[2:].replace(' ', '')
|
||||
return party_identifier
|
||||
|
||||
def _initiating_party_issuer_default(self, cr, uid, context=None):
|
||||
"""If you need to add support for an additionnal country, you can
|
||||
add an entry in the dict "party_issuer_per_country" here
|
||||
or inherit this function in the localization modules for
|
||||
your country"""
|
||||
initiating_party_issuer = ''
|
||||
# If your country require the 'Initiating Party Issuer', you should
|
||||
# contribute the entry for your country in the dict below
|
||||
@api.model
|
||||
def _default_initiating_party(self, company):
|
||||
'''This method is called from post_install.py, which itself is also
|
||||
called from migrations/8.0.0.2/post-migration.py'''
|
||||
party_issuer_per_country = {
|
||||
'BE': 'KBO-BCE', # KBO-BCE = the registry of companies in Belgium
|
||||
}
|
||||
company_id = self._company_default_get(
|
||||
cr, uid, 'res.company', context=context)
|
||||
if company_id:
|
||||
company = self.browse(cr, uid, company_id, context=context)
|
||||
country_code = company.country_id.code
|
||||
initiating_party_issuer = party_issuer_per_country.get(
|
||||
country_code, '')
|
||||
return initiating_party_issuer
|
||||
|
||||
def _initiating_party_issuer_def(self, cr, uid, context=None):
|
||||
return self._initiating_party_issuer_default(
|
||||
cr, uid, context=context)
|
||||
|
||||
_defaults = {
|
||||
'initiating_party_issuer': _initiating_party_issuer_def,
|
||||
}
|
||||
logger.debug(
|
||||
'Calling _default_initiating_party on company %s', company.name)
|
||||
country_code = company.country_id.code
|
||||
if not company.initiating_party_issuer:
|
||||
if country_code and country_code in party_issuer_per_country:
|
||||
company.write({
|
||||
'initiating_party_issuer':
|
||||
party_issuer_per_country[country_code]})
|
||||
logger.info(
|
||||
'Updated initiating_party_issuer on company %s',
|
||||
company.name)
|
||||
party_identifier = False
|
||||
if not company.initiating_party_identifier:
|
||||
if company.vat and country_code:
|
||||
if country_code == 'BE':
|
||||
party_identifier = company.vat[2:].replace(' ', '')
|
||||
if party_identifier:
|
||||
company.write({
|
||||
'initiating_party_identifier': party_identifier})
|
||||
logger.info(
|
||||
'Updated initiating_party_identifier on company %s',
|
||||
company.name)
|
||||
|
||||
32
account_banking_pain_base/post_install.py
Normal file
32
account_banking_pain_base/post_install.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# PAIN Base module for Odoo
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
|
||||
def set_default_initiating_party(cr, pool):
|
||||
company_ids = pool['res.company'].search(cr, SUPERUSER_ID, [])
|
||||
companies = pool['res.company'].browse(cr, SUPERUSER_ID, company_ids)
|
||||
for company in companies:
|
||||
pool['res.company']._default_initiating_party(
|
||||
cr, SUPERUSER_ID, company)
|
||||
return
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
Copyright (C) 2013-2015 Akretion (http://www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
@@ -14,6 +14,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<group name="account_grp" position="after">
|
||||
<group name="pain" string="Payment Initiation">
|
||||
<field name="initiating_party_identifier"/>
|
||||
<field name="initiating_party_issuer"/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user