[MERGE] l10n_ch. Merged new fixes and enhancements made by c2c. Thanks for the contribution

bzr revid: qdp-launchpad@openerp.com-20120206114533-fvh7kagc8r8ln1hb
This commit is contained in:
Quentin (OpenERP) 2012-02-06 12:45:33 +01:00
commit f06bde8978
11 changed files with 183 additions and 95 deletions

View File

@ -19,9 +19,8 @@
#
##############################################################################
{
"name" : "Switzerland - Accounting",
"description" : """
{"name" : "Switzerland - Accounting",
"description" : """
Swiss localisation :
- DTA generation for a lot of payment types
- BVR management (number generation, report, etc..)
@ -61,51 +60,47 @@ TODO :
""",
"version" : "6.1",
"author" : "Camptocamp",
'category': 'Localization/Account Charts',
"website": "http://www.camptocamp.com",
"version": "6.1",
"author": "Camptocamp",
'category': 'Localization/Account Charts',
"website": "http://www.camptocamp.com",
"depends" : [
"account_cancel",
"base_iban",
"account_payment",
"account_voucher",
"report_webkit",
],
"init_xml" : [
"dta_data.xml",
"journal_data.xml",
#FR sterchi chart data
'sterchi_chart/account.xml',
'sterchi_chart/vat.xml', #JUST REMOVE THIS FILE WHEN OBSOLETE. ALL REQUIERED DATA IN VAT2011.XML
'sterchi_chart/vat2011.xml',
'sterchi_chart/fiscal_position.xml',
],
"demo_xml" : [
"demo/demo.xml",
"demo/dta_demo.xml",
],
"update_xml" : [
"wizard.xml",
"wizard/bvr_import_view.xml",
"wizard/create_dta_view.xml",
"company_view.xml",
"account_invoice.xml",
"bank_view.xml",
"security/ir.model.access.csv",
"report/report_webkit_html_view.xml",
],
'test' : [
'test/l10n_ch_report.yml',
'test/l10n_ch_dta.yml',
#TODO: uncomment the 2 following tests once they are fixed
#'test/l10n_ch_v11.yml',
#'test/l10n_ch_v11_part.yml',
],
"auto_install": False,
"installable": True,
"certificate" : "001103836064567088989",
'images': ['images/config_chart_l10n_ch.jpeg','images/l10n_ch_chart.jpeg'],
}
"depends" : [ "account_cancel",
"base_iban",
"account_payment",
"account_voucher",
"report_webkit",
"l10n_multilang"],
"init_xml": ["dta_data.xml",
"journal_data.xml",
#FR sterchi chart data
'sterchi_chart/account.xml',
'sterchi_chart/vat.xml',
'sterchi_chart/vat2011.xml',
'sterchi_chart/fiscal_position.xml'],
"demo_xml": ["demo/demo.xml",
"demo/dta_demo.xml"],
"update_xml": ["wizard.xml",
"wizard/bvr_import_view.xml",
"wizard/create_dta_view.xml",
"company_view.xml",
"account_invoice.xml",
"bank_view.xml",
"security/ir.model.access.csv",
"report/report_webkit_html_view.xml"],
"test": ['test/l10n_ch_report.yml',
'test/l10n_ch_dta.yml',
#TODO: uncomment the 2 following tests once they are fixed
#'test/l10n_ch_v11.yml',
#'test/l10n_ch_v11_part.yml'
],
"auto_install": False,
"installable": True,
"certificate": "001103836064567088989",
'images': ['images/config_chart_l10n_ch.jpeg','images/l10n_ch_chart.jpeg']}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -21,6 +21,7 @@
from tools.translate import _
from osv import fields, osv
import re
class Bank(osv.osv):
"""Inherit res.bank class in order to add swiss specific field"""
@ -42,8 +43,8 @@ class ResPartnerBank(osv.osv):
_columns = {
'name': fields.char('Description', size=128, required=True),
'post_number': fields.char('Post number', size=64),
'bvr_adherent_num': fields.char('BVR adherent number', size=11),
'post_number': fields.char('Post number', size=64, help="Postal number 0x-xxxxxx-x or xxxxx"),
'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."),
'dta_code': fields.char('DTA code', size=5),
'print_bank': fields.boolean('Print Bank on BVR'),
'print_account': fields.boolean('Print Account Number on BVR'),
@ -68,11 +69,50 @@ class ResPartnerBank(osv.osv):
def _prepare_name(self, bank):
"Hook to get bank number of bank account"
res = super(ResPartnerBank, self)._prepare_name(bank)
res = u''
if bank.acc_number:
res = super(ResPartnerBank, self)._prepare_name(bank) or u''
if bank.post_number:
res = u"%s - %s" % (res, bank.post_number)
if res:
res = u"%s - %s" % (res, bank.post_number)
else:
res = bank.post_number
return res
def _check_9_pos_postal_num(self, number):
"""
check if a postal number in format xx-xxxxxx-x is correct,
return true if it matches the pattern
and if check sum mod10 is ok
"""
from tools import mod10r
pattern = r'^[0-9]{2}-[0-9]{1,6}-[0-9]$'
if not re.search(pattern, number):
return False
num, checksum = (number.replace('-','')[:-1], number[-1:])
return mod10r(num)[-1:] == checksum
def _check_5_pos_postal_num(self, number):
"""
check if a postal number on 5 positions is correct
"""
pattern = r'^[0-9]{1,5}$'
if not re.search(pattern, number):
return False
return True
def _check_postal_num(self, cursor, uid, ids):
banks = self.browse(cursor, uid, ids)
for b in banks:
return self._check_9_pos_postal_num(b.post_number) or \
self._check_5_pos_postal_num(b.post_number)
_constraints = [(_check_postal_num,
'Please enter a correct postal number. (01-23456-5 or 12345)',
['post_number'])]
_sql_constraints = [('bvr_adherent_uniq', 'unique (bvr_adherent_num)',
'The BVR adherent number must be unique !')]

View File

@ -130,12 +130,14 @@
</group>
<separator colspan="4" string="Financial institute infos"/>
<newline/>
<field name="my_bank" attrs="{'invisible': [('company_id', '=', False)]}" colspan="4"/>
<group string="BVR print options" colspan="4" attrs="{'invisible': [('my_bank', '!=', True)]}" >
<field name="bvr_adherent_num"/>
<field name="print_bank"/>
<field name="print_account"/>
<newline/>
<group attrs="{'invisible': ['|', ('state', 'not in', ['bvrpost','bvrbank']), ('company_id', '=', False)]}" colspan="4">
<field name="my_bank" attrs="{'invisible': [('company_id', '=', False)]}" />
<group string="BVR print options" colspan="4" attrs="{'invisible': [('my_bank', '!=', True)]}" >
<field name="bvr_adherent_num" attrs="{'invisible': [('state','!=','bvrbank')]}"/>
<field name="print_bank"/>
<field name="print_account"/>
<newline/>
</group>
</group>
<newline/>
<field name="bank" />

View File

@ -11,7 +11,7 @@
<field name="acc_number">11-1234-1</field>
<field name="partner_id" ref="base.main_partner"/>
<field name="state">bvrbank</field>
<field name="post_number">11-1234-1</field>
<field name="post_number">70-004152-8</field>
<field name="bank" ref="main_bank"/>
<!-- <field name="iban">CH9100767000S00023455</field> -->
<field name="bvr_adherent_num">0000000</field>

View File

@ -12,7 +12,7 @@
<field name="acc_number">123456</field>
<field name="partner_id" ref="base.res_partner_agrolait"/>
<field name="state">bvrbank</field>
<field name="post_number">234567</field>
<field name="post_number">01-23456-5</field>
<field name="bank" ref="partner_bank"/>
<!-- <field name="iban">CH9100767000S00023455</field> -->
</record>

View File

@ -124,28 +124,24 @@ class l10n_ch_report_webkit_html(report_sxw.rml_parse):
invoice_obj = pool.get('account.invoice')
ids = invoice_ids
for invoice in invoice_obj.browse(cursor, self.uid, ids):
invoice_name = "%s %s" %(invoice.name, invoice.number)
if not invoice.partner_bank_id:
raise except_osv(_('UserError'),
_('No bank specified on invoice:\n' + \
invoice_obj.name_get(cursor, self.uid, [invoice.id],
context={})[0][1]))
_('No bank specified on invoice:\n%s' %(invoice_name)))
if not self._compile_check_bvr.match(
invoice.partner_bank_id.post_number or ''):
raise except_osv(_('UserError'),
_('Your bank BVR number should be of the form 0X-XXX-X! ' +
'Please check your company ' +
'information for the invoice:\n' +
invoice_obj.name_get(cursor, self.uid, [invoice.id],
context={})[0][1]))
_(('Your bank BVR number should be of the form 0X-XXX-X! '
'Please check your company '
'information for the invoice:\n%s')
%(invoice_name)))
if invoice.partner_bank_id.bvr_adherent_num \
and not self._compile_check_bvr_add_num.match(
invoice.partner_bank_id.bvr_adherent_num):
raise except_osv(_('UserError'),
_('Your bank BVR adherent number must contain exactly seven' +
'digits!\nPlease check your company ' +
'information for the invoice:\n' +
invoice_obj.name_get(cursor, self.uid, [invoice.id],
context={})[0][1]))
_(('Your bank BVR adherent number must contain only '
'digits!\nPlease check your company '
'information for the invoice:\n%s') %(invoice_name)))
return ''
class BVRWebKitParser(webkit_report.WebKitParser):

View File

@ -11802,7 +11802,12 @@
<field name="property_account_receivable" ref="ch_1100"/>
<field name="property_account_payable" ref="ch_2000"/>
<field name="property_account_expense_categ" ref="ch_4200"/>
<field name="property_account_income_categ" ref="ch_1000"/>
<field name="property_account_income_categ" ref="ch_3200"/>
<field name="property_account_expense" ref="ch_4200"/>
<field name="property_account_income" ref="ch_3200"/>
<field name="property_account_income_opening" ref="ch_2990"/>
<field name="property_account_expense_opening" ref="ch_2990"/>
<field name="property_reserve_and_surplus_account" ref="ch_2991"/>
</record>
<!-- journal configuration of account -->

View File

@ -16,7 +16,7 @@
address_contact_id: base.res_partner_address_8
address_invoice_id: base.res_partner_address_8
reference_type: bvr
reference: 111111111111111111111111111111
reference: 11111111111111111111
date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
period_id: account.period_1
#invoice_line:
@ -65,7 +65,7 @@
amount_currency: 7000
bank_id: l10n_ch.agro_bank
#bank_statement_line_id
communication: "111111111111111111111111111111"
communication: "11111111111111111111"
#communication2
company_currency: base.EUR
#create_date
@ -76,7 +76,7 @@
#ml_date_created
#ml_inv_ref
#ml_maturity_date
move_line_id: !ref {model: account.move.line, search: "[('ref','=','111111111111111111111111111111')]"}
move_line_id: !ref {model: account.move.line, search: "[('ref','=','11111111111111111111')]"}
#name (reference)
order_id: dta_payment_order
partner_id: base.res_partner_agrolait
@ -152,7 +152,7 @@
# wiz = self.browse(cr, uid, wiz_id)
#
# line_obj = self.pool.get('payment.line')
# pay_line_ids = line_obj.search(cr, uid, [('communication','=','111111111111111111111111111111'),('amount','=','7000')])
# pay_line_ids = line_obj.search(cr, uid, [('communication','=','11111111111111111111'),('amount','=','7000')])
#
# data = { 'lines': [(6, 0, [pay_line_ids[0]])],}
# wiz.write(data)

View File

@ -71,6 +71,9 @@ def _import(self, cursor, user, data, context=None):
statement_obj = self.pool.get('account.bank.statement')
property_obj = self.pool.get('ir.property')
file = data['form']['file']
if not file:
raise osv.except_osv(_('UserError'),
_('Please select a file first!'))
statement_id = data['id']
records = []
total_amount = 0
@ -239,7 +242,7 @@ def _import(self, cursor, user, data, context=None):
class bvr_import_wizard(osv.osv_memory):
_name = 'bvr.import.wizard'
_columns = {
'file':fields.binary('BVR File', readonly=True)
'file':fields.binary('BVR File')
}
def import_bvr(self, cr, uid, ids, context=None):

View File

@ -28,6 +28,8 @@ import pooler
from tools.translate import _
import unicode2ascii
import re
TRANS=[
(u'é','e'),
(u'è','e'),
@ -346,6 +348,14 @@ def c_ljust(s, size):
s = s.decode('utf-8').encode('latin1','replace').ljust(size)
return s
def _is_9_pos_bvr_adherent(adherent_num):
"""
from a bvr adherent number,
return true if
"""
pattern = r'[0-9]{2}-[0-9]{1,6}-[0-9]'
return re.search(pattern, adherent_num)
def _create_dta(obj, cr, uid, data, context=None):
v = {}
v['uid'] = str(uid)
@ -435,10 +445,24 @@ def _create_dta(obj, cr, uid, data, context=None):
or False
v['partner_bvr'] = pline.bank_id.post_number or ''
if v['partner_bvr']:
v['partner_bvr'] = v['partner_bvr'].replace('-','')
if len(v['partner_bvr']) < 9:
v['partner_bvr'] = v['partner_bvr'][:2] + '0' * \
(9 - len(v['partner_bvr'])) + v['partner_bvr'][2:]
is_9_pos_adherent = None
# if adherent bvr number is a 9 pos number
# add 0 to fill 2nd part plus remove '-'
# exemple: 12-567-C becomes 12000567C
if _is_9_pos_bvr_adherent(v['partner_bvr']):
parts = v['partner_bvr'].split('-')
parts[1] = parts[1].rjust(6, '0')
v['partner_bvr'] = ''.join(parts)
is_9_pos_adherent = True
# add 4*0 to bvr adherent number with 5 pos
# exemple: 12345 becomes 000012345
elif len(v['partner_bvr']) == 5:
v['partner_bvr'] = v['partner_bvr'].rjust(9, '0')
is_9_pos_adherent = False
else:
raise osv.except_osv(_('Error'),
_('Wrong postal number format.\n'
'It must be 12-123456-9 or 12345 format'))
if pline.bank_id.bank:
v['partner_bank_city'] = pline.bank_id.bank.city or False
@ -518,15 +542,39 @@ def _create_dta(obj, cr, uid, data, context=None):
elif elec_pay == 'bvrbank' or elec_pay == 'bvrpost':
from tools import mod10r
if v['reference']:
v['reference'] = v['reference'].replace(' ',
'').rjust(27).replace(' ', '0')
if not v['reference'] \
or (mod10r(v['reference'][:-1]) != v['reference'] and \
not len(v['reference']) == 15):
raise osv.except_osv(_('Error'), _('You must provide ' \
'a valid BVR reference number \n' \
'for the line: %s') % pline.name)
if not v['reference']:
raise osv.except_osv(_('Error'),
_('You must provide ' \
'a BVR reference number \n' \
'for the line: %s') % pline.name)
v['reference'] = v['reference'].replace(' ', '')
if is_9_pos_adherent:
if len(v['reference']) > 27:
raise osv.except_osv(_('Error'),
_('BVR reference number is not valid \n'
'for the line: %s. \n'
'Reference is too long.') % pline.name)
# do a mod10 check
if mod10r(v['reference'][:-1]) != v['reference']:
raise osv.except_osv(_('Error'),
_('BVR reference number is not valid \n'
'for the line: %s. \n'
'Mod10 check failed') % pline.name)
# fill reference with 0
v['reference'] = v['reference'].rjust(27, '0')
else:
# reference of BVR adherent with 5 positions number
# have 15 positions references
if len(v['reference']) > 15:
raise osv.except_osv(_('Error'),
_('BVR reference number is not valid \n'
'for the line: %s. \n'
'Reference is too long '
'for this type of beneficiary.') % pline.name)
# complete 15 first digit with 0 on left and complete 27 digits with trailing spaces
# exemple: 123456 becomes 00000000012345____________
v['reference'] = v['reference'].rjust(15, '0').ljust(27, ' ')
if not v['partner_bvr']:
raise osv.except_osv(_('Error'), _('You must provide a BVR number\n'
'for the bank account: %s' \

View File

@ -8,8 +8,7 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="DTA file creation - Results">
<group width="300" colspan="4">
<separator string="Create DTA - (DTA file will appear after you click on create)" colspan="4"/>
<group colspan="4">
<field name="dta_file"/>
<group colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel" colspan="2"/>