[MRG] from c2c l10n_ch

bzr revid: yannick.vaucher@camptocamp.com-20111104162624-66v2v28gp0ytnpe8
This commit is contained in:
Yannick Vaucher 2011-11-04 17:26:24 +01:00
parent 35c24ae1a1
commit 04993a88b0
9 changed files with 37 additions and 95 deletions

View File

@ -63,7 +63,7 @@ TODO :
""",
"version" : "6.1",
"author" : "Camptocamp",
"category" : "Localization/Account Charts",
"category" : "Finance",
"website": "http://www.camptocamp.com",
"depends" : [

View File

@ -48,7 +48,7 @@ class ResPartnerBank(osv.osv):
'print_bank': fields.boolean('Print Bank on BVR'),
'print_account': fields.boolean('Print Account Number on BVR'),
'acc_number': fields.char('Account/IBAN Number', size=64),
'my_bank': fields.boolean('Use my account to print BVR ?', help="Check to print BVR invoices"),
}
def name_get(self, cursor, uid, ids, context=None):
@ -64,83 +64,19 @@ class ResPartnerBank(osv.osv):
res = []
for r in self.read(cursor, uid, ids, ['name','state'], context):
res.append((r['id'], r['name']+' : '+bank_type_names.get(r['state'], '')))
return res
def post_write(self, cr, uid, ids, context={}):
""" Override of post_write method.
In Switzerland with post accounts you can either have a postal account
with a required bank number (BVR Bank) or a postal number alone (BV Post, BVR Post).
So acc_number is not always mandatory and postal and bank number are not the same field """
return res
obj_acc = self.pool.get('account.account')
obj_data = self.pool.get('ir.model.data')
for bank in self.browse(cr, uid, ids, context):
if bank.company_id and not bank.journal_id:
# Find the code and parent of the bank account to create
dig = 6
current_num = 1
ids = obj_acc.search(cr, uid, [('type','=','liquidity')], context=context)
# No liquidity account exists, no template available
if not ids: continue
ref_acc_bank_temp = obj_acc.browse(cr, uid, ids[0], context=context)
ref_acc_bank = ref_acc_bank_temp.parent_id
while True:
new_code = str(ref_acc_bank.code.ljust(dig-len(str(current_num)), '0')) + str(current_num)
ids = obj_acc.search(cr, uid, [('code', '=', new_code), ('company_id', '=', bank.company_id.id)])
if not ids:
break
current_num += 1
# Here is the test
if not bank.acc_number:
number = bank.post_number
else:
number = bank.acc_number
acc = {
'name': (bank.bank_name or '')+' '+ number,
'currency_id': bank.company_id.currency_id.id,
'code': new_code,
'type': 'liquidity',
'user_type': ref_acc_bank_temp.user_type.id,
'reconcile': False,
'parent_id': ref_acc_bank.id,
'company_id': bank.company_id.id,
}
acc_bank_id = obj_acc.create(cr,uid,acc,context=context)
# Get the journal view id
data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view')])
data = obj_data.browse(cr, uid, data_id[0], context=context)
view_id_cash = data.res_id
jour_obj = self.pool.get('account.journal')
new_code = 1
while True:
code = _('BNK')+str(new_code)
ids = jour_obj.search(cr, uid, [('code','=',code)], context=context)
if not ids:
break
new_code += 1
#create the bank journal
vals_journal = {
'name': (bank.bank_name or '')+' '+number,
'code': code,
'type': 'bank',
'company_id': bank.company_id.id,
'analytic_journal_id': False,
'currency_id': False,
'default_credit_account_id': acc_bank_id,
'default_debit_account_id': acc_bank_id,
'view_id': view_id_cash
}
journal_id = jour_obj.create(cr, uid, vals_journal, context=context)
self.write(cr, uid, [bank.id], {'journal_id': journal_id}, context=context)
return True
def _get_number(self, bank):
"Hook to get bank number of bank account"
res = super(ResPartnerBank, self)._get_number(bank)
res = res or u''
if bank.post_number:
if res:
res = u"%s - %s" % (res, bank.post_number)
else:
res = bank.post_number
return res
_sql_constraints = [('bvr_adherent_uniq', 'unique (bvr_adherent_num)',
'The BVR adherent number must be unique !')]

View File

@ -137,7 +137,9 @@
<newline/>
</group>
<separator colspan="4" string="Financial institute infos"/>
<group string="BVR print options" colspan="4" attrs="{'invisible': [('company_id','=',False)]}" >
<newline/>
<field name="my_bank" attrs="{'invisible': [('company_id', '!=', True)]}" 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"/>

View File

@ -53,10 +53,10 @@ class res_company(osv.osv):
}
_defaults = {
'bvr_scan_line_vert': lambda *a: 232,
'bvr_scan_line_horz': lambda *a: 72,
'bvr_scan_line_font_size': lambda *a: 12,
'bvr_scan_line_letter_spacing': lambda *a: 0,
'bvr_scan_line_vert': 232,
'bvr_scan_line_horz': 72,
'bvr_scan_line_font_size': 12,
'bvr_scan_line_letter_spacing': 0,
}
res_company()

View File

@ -17,7 +17,7 @@
<!-- <field name="iban">CH9100767000S00023455</field> -->
</record>
<record model="res.partner.bank" id="main_bank">
<record model="res.partner.bank" id="main_partner_bank">
<field name="name">My bank</field>
<!-- <field name="acc_number">123456</field> -->
<!-- <field name="iban">123456</field> -->
@ -53,7 +53,7 @@
<!-- Define a payment mode -->
<record model="payment.mode" id="payment_mode_dta">
<field name="name">DTA</field>
<field name="bank_id" ref="main_bank"/>
<field name="bank_id" ref="main_partner_bank"/>
<field name="journal" model="account.journal" search="[('type','=','cash')]"/>
</record>

View File

@ -73,8 +73,9 @@ class account_invoice(osv.osv):
help='The partner bank account to pay\nKeep empty to use the default'
),
### Amount to pay
'amount_to_pay': fields.function(_amount_to_pay, method=True,
type='float', string='Amount to be paid',
'amount_to_pay': fields.function(_amount_to_pay,
type='float',
string='Amount to be paid',
help='The amount which should be paid at the current date\n' \
'minus the amount which is already in payment order'),
}
@ -144,23 +145,26 @@ class account_invoice(osv.osv):
date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
""" Function that is call when the partner of the invoice is changed
it will retrieve and set the good bank partner bank"""
#context not define in signature of function in account module
context = {}
res = super(account_invoice, self).onchange_partner_id(cr,
uid,
ids,
type,
partner_id,
date_invoice,
payment_term)
payment_term,
partner_bank_id,
company_id)
bank_id = False
if partner_id:
if type in ('in_invoice', 'in_refund'):
p = self.pool.get('res.partner').browse(cr, uid, partner_id)
p = self.pool.get('res.partner').browse(cr, uid, partner_id, context)
if p.bank_ids:
bank_id = p.bank_ids[0].id
res['value']['partner_bank_id'] = bank_id
else:
user = self.pool.get('res.users').browse(cr, uid, uid)
user = self.pool.get('res.users').browse(cr, uid, uid, context)
bank_ids = user.company_id.partner_id.bank_ids
if bank_ids:
#How to order bank ?

View File

@ -95,7 +95,7 @@
context['active_id'] = pay_order_id
result = wiz.create_dta(context=context)
assert result, "No result returned"
data = wiz.read(['dta_file'])
dta_file = base64.decodestring(data[0]['dta_file'] or '')
assert dta_file, "File is empty"

View File

@ -168,7 +168,7 @@ def _import(self, cursor, user, data, context=None):
# line2reconcile = line.id
account_id = line.account_id.id
break
result = voucher_obj.onchange_partner_id(cursor, user, [], partner_id, journal_id=statement.journal_id.id, price=abs(record['amount']), voucher_currency_id= statement.currency.id, ttype='receipt', date=statement.date ,context=context)
result = voucher_obj.onchange_partner_id(cursor, user, [], partner_id, journal_id=statement.journal_id.id, price=abs(record['amount']), currency_id= statement.currency.id, ttype='receipt', date=statement.date ,context=context)
voucher_res = { 'type': 'receipt' ,
'name': values['name'],

View File

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