[IMP] code cleanup in l10n_fr_rib
bzr revid: ls@numerigraphe.fr-20111121134410-7l1qq9q11o2w55ty
This commit is contained in:
parent
068650b67a
commit
05afd356a2
|
@ -1,19 +1,20 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2009 Numérigraphe SARL.
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2011 OpenERP SA (<http://openerp.com>).
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU Affero General Public License as
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
# (at your option) any later version.
|
# License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2009 Numérigraphe SARL.
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2011 OpenERP SA (<http://openerp.com>).
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU Affero General Public License as
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
# (at your option) any later version.
|
# License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'RIB',
|
'name': 'French RIB Bank Details',
|
||||||
'version': '0.1',
|
'version': '1.0',
|
||||||
'category': 'Generic Modules/Base',
|
'category': 'Localization/Account Charts',
|
||||||
'description': """
|
'description': '''
|
||||||
This module install the base for RIB bank accounts (French standard for bank accounts).
|
This module installs the base for RIB bank accounts (French standard for bank accounts).
|
||||||
To make it easier to enter RIB data, it will also allow to search for banks by code.
|
To make it easier to enter RIB data, it will also allow to search for banks by code.''',
|
||||||
|
'author' : u'Numérigraphe SARL',
|
||||||
""",
|
|
||||||
"author" : "Numérigraphe SARL",
|
|
||||||
'depends': ['base', 'account'],
|
'depends': ['base', 'account'],
|
||||||
'init_xml': ['bank_data.xml', ],
|
'init_xml': ['bank_data.xml', ],
|
||||||
'update_xml': ['bank_view.xml', ],
|
'update_xml': ['bank_view.xml', ],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'active': False,
|
'active': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,19 +1,20 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2009 Numérigraphe SARL. All Rights Reserved
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2011 OpenERP SA (<http://openerp.com>).
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU Affero General Public License as
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
# (at your option) any later version.
|
# License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
@ -24,31 +25,36 @@ import unicodedata
|
||||||
import netsvc
|
import netsvc
|
||||||
from osv import fields, osv
|
from osv import fields, osv
|
||||||
|
|
||||||
# Add fields and behavior for French RIB
|
|
||||||
class res_partner_bank(osv.osv):
|
class res_partner_bank(osv.osv):
|
||||||
|
"""Add fields and behavior for French RIB"""
|
||||||
_inherit = "res.partner.bank"
|
_inherit = "res.partner.bank"
|
||||||
|
|
||||||
def _check_key(self, cr, uid, ids):
|
def _check_key(self, cr, uid, ids):
|
||||||
'''
|
"""Check the RIB key"""
|
||||||
Check the RIB key
|
|
||||||
'''
|
|
||||||
for bank_acc in self.browse(cr, uid, ids):
|
for bank_acc in self.browse(cr, uid, ids):
|
||||||
# ignore the accounts of type other than rib
|
# Ignore the accounts of type other than rib
|
||||||
if bank_acc.state !='rib':
|
if bank_acc.state !='rib':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Fail if the needed values are empty of too short
|
# Fail if the needed values are empty of too short
|
||||||
if (not bank_acc.bank or not bank_acc.bank.code or len(bank_acc.bank.code) != 5
|
if (not bank_acc.bank or not bank_acc.bank.code
|
||||||
|
or len(bank_acc.bank.code) != 5
|
||||||
or not bank_acc.office or len(bank_acc.office) != 5
|
or not bank_acc.office or len(bank_acc.office) != 5
|
||||||
or not bank_acc.acc_number or len(bank_acc.acc_number) != 11
|
or not bank_acc.acc_number or len(bank_acc.acc_number) != 11
|
||||||
or not bank_acc.key or len(bank_acc.key) != 2):
|
or not bank_acc.key or len(bank_acc.key) != 2):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# get the rib data (without the key)
|
# Get the rib data (without the key)
|
||||||
rib = "%s%s%s" % (bank_acc.bank.code, bank_acc.office, bank_acc.acc_number)
|
rib = "%s%s%s" % (bank_acc.bank.code, bank_acc.office,
|
||||||
# translate letters into numbers according to a specific table (notice how s -> 2)
|
bank_acc.acc_number)
|
||||||
# Note: maketrans and translate work best with latin1 - that should not be a problem for RIB data
|
# Translate letters into numbers according to a specific table
|
||||||
rib = rib.lower().encode('latin-1').translate(string.maketrans(u'abcdefghijklmnopqrstuvwxyz', u'12345678912345678923456789'))
|
# (notice how s -> 2)
|
||||||
|
# Note: maketrans and translate work best with latin1 - that
|
||||||
|
# should not be a problem for RIB data
|
||||||
|
# XXX use dict((ord(a), b) for a, b in zip(intab, outtab))
|
||||||
|
# and translate()
|
||||||
|
rib = rib.lower().encode('latin-1').translate(
|
||||||
|
string.maketrans(u'abcdefghijklmnopqrstuvwxyz',
|
||||||
|
u'12345678912345678923456789'))
|
||||||
|
|
||||||
# compute the key
|
# compute the key
|
||||||
key = 97 - (100 * int(rib)) % 97
|
key = 97 - (100 * int(rib)) % 97
|
||||||
|
@ -57,9 +63,11 @@ class res_partner_bank(osv.osv):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
|
def search(self, cr, uid, args, offset=0, limit=None, order=None,
|
||||||
#overwrite the search method in order to search not only on bank type == basic account number but also on type == rib
|
context=None, count=False):
|
||||||
res = super(res_partner_bank, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
|
"""Search on type == rib"""
|
||||||
|
res = super(res_partner_bank, self).search(cr, uid, args, offset,
|
||||||
|
limit=limit, order=order, context=context, count=count)
|
||||||
if filter(lambda x:x[0] == 'acc_number' , args):
|
if filter(lambda x:x[0] == 'acc_number' , args):
|
||||||
#get the value of the search
|
#get the value of the search
|
||||||
rib_value = filter(lambda x:x[0] == 'acc_number' , args)[0][2]
|
rib_value = filter(lambda x:x[0] == 'acc_number' , args)[0][2]
|
||||||
|
@ -68,16 +76,21 @@ class res_partner_bank(osv.osv):
|
||||||
#add the new criterion
|
#add the new criterion
|
||||||
args1 += [('rib', 'ilike', rib_value)]
|
args1 += [('rib', 'ilike', rib_value)]
|
||||||
#append the results to the older search
|
#append the results to the older search
|
||||||
res += super(res_partner_bank, self).search(cr, uid, args1, offset, limit,
|
res += super(res_partner_bank, self).search(cr, uid, args1, offset,
|
||||||
order, context=context, count=count)
|
limit, order, context=context, count=count)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'office': fields.char('Office Code', size=5, readonly=True, help="Office Code"),
|
'office': fields.char('Office Code', size=5, readonly=True,
|
||||||
'key': fields.char('Key', size=2, readonly=True, help="The key is a number allowing to check the correctness of the other codes."),
|
help="Office Code"),
|
||||||
|
'key': fields.char('Key', size=2, readonly=True,
|
||||||
|
help="The key is a number allowing to check the "
|
||||||
|
"correctness of the other codes."),
|
||||||
}
|
}
|
||||||
|
|
||||||
_constraints = [(_check_key, "The RIB key does not correspond to the other codes.", ["key"])]
|
_constraints = [(_check_key,
|
||||||
|
"The RIB key does not correspond to the other codes.",
|
||||||
|
["key"])]
|
||||||
|
|
||||||
res_partner_bank()
|
res_partner_bank()
|
||||||
|
|
||||||
|
@ -86,23 +99,25 @@ class res_bank(osv.osv):
|
||||||
_inherit = 'res.bank'
|
_inherit = 'res.bank'
|
||||||
|
|
||||||
# allow a search by code
|
# allow a search by code
|
||||||
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
|
def name_search(self, cr, user, name, args=None, operator='ilike',
|
||||||
if not args:
|
context=None, limit=80):
|
||||||
|
if args is None:
|
||||||
args = []
|
args = []
|
||||||
if context is None:
|
|
||||||
context = {}
|
|
||||||
ids = []
|
ids = []
|
||||||
if name:
|
if name:
|
||||||
ids = self.search(cr, user, [('name', operator, name)] + args, limit=limit, context=context)
|
ids = self.search(cr, user, [('name', operator, name)] + args,
|
||||||
|
limit=limit, context=context)
|
||||||
if not ids:
|
if not ids:
|
||||||
ids = self.search(cr, user, [('code', operator, name)] + args, limit=limit, context=context)
|
ids = self.search(cr, user, [('code', operator, name)] + args,
|
||||||
|
limit=limit, context=context)
|
||||||
return self.name_get(cr, user, ids, context)
|
return self.name_get(cr, user, ids, context)
|
||||||
|
|
||||||
# show the code before the name
|
# show the code before the name
|
||||||
def name_get(self, cr, uid, ids, context=None):
|
def name_get(self, cr, uid, ids, context=None):
|
||||||
result = []
|
result = []
|
||||||
for bank in self.browse(cr, uid, ids, context):
|
for bank in self.browse(cr, uid, ids, context):
|
||||||
result.append((bank.id, (bank.code and (bank.code + ' - ') or '') + bank.name))
|
result.append((bank.id,
|
||||||
|
(bank.code and (bank.code + ' - ') or '') + bank.name))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
res_bank()
|
res_bank()
|
||||||
|
|
|
@ -45,8 +45,8 @@
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="acc_number" position="before">
|
<field name="acc_number" position="before">
|
||||||
<newline />
|
<newline />
|
||||||
<field name="rib_bank" />
|
<field name="bank" />
|
||||||
<field name="rib_office" />
|
<field name="office" />
|
||||||
<newline />
|
<newline />
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
<field name="type">form</field>
|
<field name="type">form</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="acc_number" position="after">
|
<field name="acc_number" position="after">
|
||||||
<field name="rib_key" />
|
<field name="key" />
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -70,8 +70,8 @@
|
||||||
<field name="type">tree</field>
|
<field name="type">tree</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="acc_number" position="before">
|
<field name="acc_number" position="before">
|
||||||
<field name="rib_bank" />
|
<field name="bank" />
|
||||||
<field name="rib_office" />
|
<field name="office" />
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
<field name="type">tree</field>
|
<field name="type">tree</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="acc_number" position="after">
|
<field name="acc_number" position="after">
|
||||||
<field name="rib_key" />
|
<field name="key" />
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record> -->
|
</record> -->
|
||||||
|
|
Loading…
Reference in New Issue