Skip to content

Commit

Permalink
[FIX] Change addons with new release 7.1
Browse files Browse the repository at this point in the history
  *) Add ccp account on res_bank but keep retro compatibility with old model.
     If no ccp is set on bank old behavior is kept
     Be aware if you have customize bvr.mako you have to replace acc_number by get_account_number()
  *) Add constraint to avoid wrong entries
  *) Disable invoice reference overwrite
  *) Better bank views
  *) Validating an account invoice does not overwrite invoice reference
  • Loading branch information
nbessi authored and vrenaville committed Jul 8, 2013
2 parents 821b32c + a6cecdd commit f29a8df
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 180 deletions.
46 changes: 36 additions & 10 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
Change with release 7.1

*) Add ccp account on res_bank but keep retro compatibility with old model.
If no ccp is set on bank old behavior is kept.
Be aware if you have customizde bvr.mako you have to replace acc_number by get_account_number().
This change allows to avoid duplication of res.partner.bank

*) Fix res.bank view

*) Improve res.bank name search by adding intelligent search

*) Add city to res.bank name_get

*) Add constraint to avoid wrong entries on res.partner.bank

*) Disable invoice reference overwrite when validating an invoice

*) Better res.bank views in list mode

*) Fix BVR options in res.partner.bank views

*) Remove attachments from payment order view as document addon is fixed

*) Various fixes of DTA wizard

Changes with release 7.0

*) This release will introduce major changes to l10n_ch.
Due to important refactoring needs and the Switzerland adoption of new international payment standard during 2013-2014.
Due to important refactoring needs and the Switzerland adoption of new international payment standard during 2013-2014.
We have reorganised the swiss localization addons this way:

*) l10n_ch: Multilang swiss STERCHI account chart and taxes (official addon)
- Removing all code not related to account chart
- Added de_DE, it_IT tranlsation files

*) l10n_ch_base_bank: Technical module that introduces a new and simplified version of bank type management
- Type are simplified we add only BV and BVR, bank view is also simplified.

*) l10n_ch_bank: List of swiss banks
- No changes, just code ceanup

*) l10n_ch_zip: List of swiss postal zip
- Updated with 2012 data,
- Updated with 2012 data,
- Removing duplicated entries and military NPA (Caserne etc.)

*) l10n_ch_dta: Support of dta payment protocol (will be deprecated end 2014)
- Refactoring and clean-up done + adaptation to the new bank type

*) l10n_ch_payment_slip: Support of ESR/BVR payment slip report and reconciliation. Report refactored with easy element positioning.
- Refactoring of Mako CSS.
- Refactoring of Mako CSS.
- Remove of custom parser
- Cleaning dead code
- Switch to commercial_entity for address display
- TODO a wizard that contatenate the invoice PDF + the payment slip

*) l10n_ch_sepa: Alpha implementation of PostFinance SEPA/PAIN support will be completed during 2013/2014
-Not ported yet
- Not ported yet

Changes with release 6.1

Expand Down
2 changes: 1 addition & 1 deletion l10n_ch/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
The modules will be soon available on OpenERP swiss localization on launchpad:
https://launchpad.net/openerp-swiss-localization
""",
'version': '7.0',
'version': '7.1',
'author': 'Camptocamp',
'category': 'Localization/Account Charts',
'website': 'http://www.camptocamp.com',
Expand Down
2 changes: 1 addition & 1 deletion l10n_ch_bank/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
"update_xml": [],
"active": False,
"installable": True,
}
}
6 changes: 3 additions & 3 deletions l10n_ch_base_bank/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
##############################################################################

{'name': 'Switzerland - Bank type',
'description': """
'description': """
Swiss localization Bank type. Add new bank types
================================================
This addons will add different bank type required by
DTA, and ESR system in order to manage duality of Post and bank systems
""",
'version': '1.0',
'version': '1.1',
'author': 'Camptocamp',
'category': 'Localization',
'website': 'http://www.camptocamp.com',
Expand All @@ -36,5 +36,5 @@
'auto_install': False,
'installable': True,
'images': []
}
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
176 changes: 139 additions & 37 deletions l10n_ch_base_bank/bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,11 @@
#
##############################################################################
import re
from openerp.osv.orm import Model, fields
from openerp.osv import orm, fields
from tools import mod10r


class Bank(Model):
"""Inherit res.bank class in order to add swiss specific field"""
_inherit = 'res.bank'
_columns = {
### Internal reference
'code': fields.char('Code', size=64),
###Swiss unik bank identifier also use in IBAN number
'clearing': fields.char('Clearing number', size=64),
### city of the bank
'city': fields.char('City', size=128, select=1),
}


class ResPartnerBank(Model):
"""
Inherit res.partner.bank class in order to add swiss specific fields and state controls
"""
_inherit = "res.partner.bank"

_columns = {
'name': fields.char('Description', size=128, required=True),
'bvr_adherent_num': fields.char('Bank BVR adherent number', size=11,
help=("Your Bank adherent number to be printed in references of your BVR."
"This is not a postal account number.")),
'acc_number': fields.char('Account/IBAN Number', size=64, required=True),
}

class BankCommon(object):

def _check_9_pos_postal_num(self, number):
"""
Expand All @@ -63,12 +37,11 @@ def _check_9_pos_postal_num(self, number):
return False
nums = number.split('-')
prefix = nums[0]
num = nums[1].rjust(6,'0')
num = nums[1].rjust(6, '0')
checksum = nums[2]
expected_checksum = mod10r(prefix + num)[-1]
return expected_checksum == checksum


def _check_5_pos_postal_num(self, number):
"""
check if a postal number on 5 positions is correct
Expand All @@ -78,23 +51,152 @@ def _check_5_pos_postal_num(self, number):
return False
return True


class Bank(orm.Model, BankCommon):
"""Inherit res.bank class in order to add swiss specific field"""
_inherit = 'res.bank'
_columns = {
### Internal reference
'code': fields.char('Code', size=64, select=True),
###Swiss unik bank identifier also use in IBAN number
'clearing': fields.char('Clearing number', size=64),
### city of the bank
'city': fields.char('City', size=128, select=1),
### ccp of the bank
'ccp': fields.char('CCP', size=64, select=1)
}

def _check_ccp_duplication(self, cursor, uid, ids):
p_acc_obj = self.pool['res.partner.bank']
for bank in self.browse(cursor, uid, ids):
p_acc_ids = p_acc_obj.search(cursor, uid, [('bank', '=', bank.id)])
if p_acc_ids:
check = p_acc_obj._check_ccp_duplication(cursor, uid, p_acc_ids)
if not check:
return False
return True

def _check_postal_num(self, cursor, uid, ids):
"""
validate postal number format
"""
banks = self.browse(cursor, uid, ids)
for b in banks:
if not b.state in ('bv', 'bvr'):
return True
return self._check_9_pos_postal_num(b.acc_number) or \
self._check_5_pos_postal_num(b.acc_number)
for bank in banks:
if not bank.ccp:
continue
if not (self._check_9_pos_postal_num(bank.ccp) or
self._check_5_pos_postal_num(bank.ccp)):
return False
return True

def name_get(self, cursor, uid, ids, context=None):
res = []
cols = ('bic', 'name', 'street', 'city')
for bank in self.browse(cursor, uid, ids, context):
vals = (bank[x] for x in cols if bank[x])
res.append((bank.id, ' - '.join(vals)))
return res

def name_search(self, cursor, uid, name, args=None, operator='ilike', context=None, limit=80):
if args is None:
args = []
if context is None:
context = {}
ids = []
cols = ('code', 'bic', 'name', 'street', 'city')
if name:
for val in name.split(' '):
for col in cols:
tmp_ids = self.search(cursor, uid, [(col, 'ilike', val)] + args, limit=limit)
if tmp_ids:
ids += tmp_ids
break
# we sort by occurence
to_ret_ids = list(set(ids))
to_ret_ids = sorted(to_ret_ids, key=lambda x: ids.count(x), reverse=True)

return self.name_get(cursor, uid, to_ret_ids, context=context)

_constraints = [(_check_postal_num,
'Please enter a correct postal number. (01-23456-1 or 12345)',
['acc_number'])]
['ccp']),

(_check_ccp_duplication,
'You can not enter a ccp both on the bank and on an account'
' of type BV, BVR',
['acc_number', 'bank'])]


class ResPartnerBank(orm.Model, BankCommon):
"""
Inherit res.partner.bank class in order to add swiss specific fields and state controls
"""
_inherit = 'res.partner.bank'

_columns = {
'name': fields.char('Description', size=128, required=True),
'bvr_adherent_num': fields.char('Bank BVR adherent number', size=11,
help=("Your Bank adherent number to be printed in references of your BVR."
"This is not a postal account number.")),
'acc_number': fields.char('Account/IBAN Number', size=64, required=True),
'ccp': fields.related('bank', 'ccp', type='char', string='CCP',
readonly=True),
}

def get_account_number(self, cursor, uid, bid, context=None):
if isinstance(bid, list):
bid = bid[0]
current = self.browse(cursor, uid, bid, context=context)
if current.state not in ('bv', 'bvr'):
return current.acc_number
if current.bank and current.bank.ccp:
return current.bank.ccp
else:
return current.acc_number

def _check_postal_num(self, cursor, uid, ids):
"""
validate postal number format
"""
p_banks = self.browse(cursor, uid, ids)
for p_bank in p_banks:
if not p_bank.state in ('bv', 'bvr'):
continue
if not (self._check_9_pos_postal_num(p_bank.get_account_number()) or
self._check_5_pos_postal_num(p_bank.get_account_number())):
return False
return True

def _check_ccp_duplication(self, cursor, uid, ids):
"""
Ensure that there is not a ccp in bank and res partner bank
at same time
"""
p_banks = self.browse(cursor, uid, ids)
for p_bank in p_banks:
if not p_bank.state in ('bv', 'bvr'):
continue
bank_ccp = p_bank.bank.ccp if p_bank.bank else False
if not bank_ccp:
continue
part_bank_check = (self._check_5_pos_postal_num(p_bank.acc_number) or
self._check_9_pos_postal_num(p_bank.acc_number))
bank_check = (self._check_5_pos_postal_num(p_bank.bank.ccp) or
self._check_9_pos_postal_num(p_bank.bank.ccp))
if part_bank_check and bank_check:
return False
return True

_constraints = [(_check_postal_num,
'Please enter a correct postal number. (01-23456-1 or 12345)',
['acc_number']),

(_check_ccp_duplication,
'You can not enter a ccp both on the bank and on an account'
' of type BV, BVR',
['acc_number', 'bank'])]

_sql_constraints = [('bvr_adherent_uniq', 'unique (bvr_adherent_num)',
'The BVR adherent number must be unique !')]
'The BVR adherent number must be unique !')]

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
63 changes: 63 additions & 0 deletions l10n_ch_base_bank/bank_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,68 @@
</field>
</field>
</record>

<record id="view__bank_search" model="ir.ui.view">
<field name="name">res.bank.search</field>
<field name="model">res.bank</field>
<field name="arch" type="xml">
<search string="Banks">
<filter name="Postfinance"
icon="terp-check" string="PostFinance"
domain="[('bic', '=', 'POFICHBEXXX')]"
help="PostFinance"/>
<field name="name"/>
<field name="code"/>
<field name="street"/>
<field name="city"/>

</search>
</field>
</record>

<!-- 'POFICHBEXXX' corresponds to Postfinance bic -->

<record model="ir.ui.view" id="add_custom_fields_on_bank">
<field name="name">add custom fields on bank</field>
<field name="model">res.bank</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_res_bank_form"/>
<field name="arch" type="xml">
<field name="bic" position="after">
<field name="code"/>
<field name="clearing"/>
<field name="ccp" attrs="{'invisible': [('bic', '=', 'POFICHBEXXX')]}"/>
</field>
</field>
</record>

<record model="ir.ui.view" id="add_custom_fields_on_bank_list">
<field name="name">add custom fields on bank list</field>
<field name="model">res.bank</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_res_bank_tree"/>
<field name="arch" type="xml">
<field name="bic" position="after">
<field name="code"/>
<field name="clearing"/>
<field name="ccp"/>
<field name="street"/>
<field name="city"/>
</field>
</field>
</record>

<record model="ir.ui.view" id="add_ccp_on_res_partner_bank">
<field name="name">Add ccp on res partner bank</field>
<field name="model">res.partner.bank</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_bank_form"/>
<field name="arch" type="xml">
<field name="bank_bic" position="after">
<field name="ccp" attrs="{'invisible': [('bank_bic', '=', 'POFICHBEXXX')]}"/>
</field>
</field>
</record>

</data>
</openerp>
Loading

0 comments on commit f29a8df

Please sign in to comment.