Fix bug #111 New field initiating_party_identifier on res.company (migration script included)

This commit is contained in:
Alexis de Lattre
2015-06-01 19:22:15 +02:00
committed by Enric Tobella
parent 66d2242a02
commit d2389709c3
8 changed files with 148 additions and 80 deletions

View File

@@ -21,3 +21,4 @@
##############################################################################
from . import models
from post_install import set_default_initiating_party

View File

@@ -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
====================================

View File

@@ -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."

View File

@@ -0,0 +1,30 @@
# -*- 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
def migrate(cr, version):
if not version:
return
set_default_initiating_party(cr, None)

View File

@@ -256,13 +256,18 @@ 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 = self._prepare_field(
cr, uid, 'Initiating Party Identifier',
'sepa_export.payment_order_ids[0].company_id.'
'initiating_party_identifier',
{'sepa_export': gen_args['sepa_export']},
35, gen_args=gen_args, context=context)
initiating_party_issuer = self._prepare_field(
cr, uid, 'Initiating Party Issuer',
'sepa_export.payment_order_ids[0].company_id.'
'initiating_party_issuer',
{'sepa_export': gen_args['sepa_export']},
35, gen_args=gen_args, context=context)
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')

View File

@@ -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,17 @@
#
##############################################################################
from openerp.osv import orm, fields
from openerp import models, fields
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."),
}
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
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,
}
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.")

View File

@@ -0,0 +1,57 @@
# -*- 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/>.
#
##############################################################################
def set_default_initiating_party(cr, registry):
party_issuer_per_country = {
'BE': 'KBO-BCE', # KBO-BCE = the registry of companies in Belgium
}
cr.execute('''
SELECT
res_company.id,
res_country.code AS country_code,
res_partner.vat,
res_company.initiating_party_identifier,
res_company.initiating_party_issuer
FROM res_company
LEFT JOIN res_partner ON res_partner.id = res_company.partner_id
LEFT JOIN res_country ON res_country.id = res_partner.country_id
''')
for company in cr.dictfetchall():
country_code = company['country_code']
if not company['initiating_party_issuer']:
if country_code and country_code in party_issuer_per_country:
cr.execute(
'UPDATE res_company SET initiating_party_issuer=%s '
'WHERE id=%s',
(party_issuer_per_country[country_code], company['id']))
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:
cr.execute(
'UPDATE res_company SET initiating_party_identifier=%s '
'WHERE id=%s',
(party_identifier, company['id']))
return

View File

@@ -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>