[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", "version" : "6.1",
"author" : "Camptocamp", "author" : "Camptocamp",
"category" : "Localization/Account Charts", "category" : "Finance",
"website": "http://www.camptocamp.com", "website": "http://www.camptocamp.com",
"depends" : [ "depends" : [

View File

@ -48,7 +48,7 @@ class ResPartnerBank(osv.osv):
'print_bank': fields.boolean('Print Bank on BVR'), 'print_bank': fields.boolean('Print Bank on BVR'),
'print_account': fields.boolean('Print Account Number on BVR'), 'print_account': fields.boolean('Print Account Number on BVR'),
'acc_number': fields.char('Account/IBAN Number', size=64), '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): def name_get(self, cursor, uid, ids, context=None):
@ -64,83 +64,19 @@ class ResPartnerBank(osv.osv):
res = [] res = []
for r in self.read(cursor, uid, ids, ['name','state'], context): for r in self.read(cursor, uid, ids, ['name','state'], context):
res.append((r['id'], r['name']+' : '+bank_type_names.get(r['state'], ''))) res.append((r['id'], r['name']+' : '+bank_type_names.get(r['state'], '')))
return res 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 """
obj_acc = self.pool.get('account.account')
obj_data = self.pool.get('ir.model.data') def _get_number(self, bank):
for bank in self.browse(cr, uid, ids, context): "Hook to get bank number of bank account"
if bank.company_id and not bank.journal_id: res = super(ResPartnerBank, self)._get_number(bank)
# Find the code and parent of the bank account to create res = res or u''
dig = 6 if bank.post_number:
current_num = 1 if res:
ids = obj_acc.search(cr, uid, [('type','=','liquidity')], context=context) res = u"%s - %s" % (res, bank.post_number)
# No liquidity account exists, no template available else:
if not ids: continue res = bank.post_number
return res
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
_sql_constraints = [('bvr_adherent_uniq', 'unique (bvr_adherent_num)', _sql_constraints = [('bvr_adherent_uniq', 'unique (bvr_adherent_num)',
'The BVR adherent number must be unique !')] 'The BVR adherent number must be unique !')]

View File

@ -137,7 +137,9 @@
<newline/> <newline/>
</group> </group>
<separator colspan="4" string="Financial institute infos"/> <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="bvr_adherent_num"/>
<field name="print_bank"/> <field name="print_bank"/>
<field name="print_account"/> <field name="print_account"/>

View File

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

View File

@ -17,7 +17,7 @@
<!-- <field name="iban">CH9100767000S00023455</field> --> <!-- <field name="iban">CH9100767000S00023455</field> -->
</record> </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="name">My bank</field>
<!-- <field name="acc_number">123456</field> --> <!-- <field name="acc_number">123456</field> -->
<!-- <field name="iban">123456</field> --> <!-- <field name="iban">123456</field> -->
@ -53,7 +53,7 @@
<!-- Define a payment mode --> <!-- Define a payment mode -->
<record model="payment.mode" id="payment_mode_dta"> <record model="payment.mode" id="payment_mode_dta">
<field name="name">DTA</field> <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')]"/> <field name="journal" model="account.journal" search="[('type','=','cash')]"/>
</record> </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' help='The partner bank account to pay\nKeep empty to use the default'
), ),
### Amount to pay ### Amount to pay
'amount_to_pay': fields.function(_amount_to_pay, method=True, 'amount_to_pay': fields.function(_amount_to_pay,
type='float', string='Amount to be paid', type='float',
string='Amount to be paid',
help='The amount which should be paid at the current date\n' \ help='The amount which should be paid at the current date\n' \
'minus the amount which is already in payment order'), '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): 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 """ Function that is call when the partner of the invoice is changed
it will retrieve and set the good bank partner bank""" 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, res = super(account_invoice, self).onchange_partner_id(cr,
uid, uid,
ids, ids,
type, type,
partner_id, partner_id,
date_invoice, date_invoice,
payment_term) payment_term,
partner_bank_id,
company_id)
bank_id = False bank_id = False
if partner_id: if partner_id:
if type in ('in_invoice', 'in_refund'): 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: if p.bank_ids:
bank_id = p.bank_ids[0].id bank_id = p.bank_ids[0].id
res['value']['partner_bank_id'] = bank_id res['value']['partner_bank_id'] = bank_id
else: 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 bank_ids = user.company_id.partner_id.bank_ids
if bank_ids: if bank_ids:
#How to order bank ? #How to order bank ?

View File

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

View File

@ -168,7 +168,7 @@ def _import(self, cursor, user, data, context=None):
# line2reconcile = line.id # line2reconcile = line.id
account_id = line.account_id.id account_id = line.account_id.id
break 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' , voucher_res = { 'type': 'receipt' ,
'name': values['name'], 'name': values['name'],

View File

@ -9,11 +9,11 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="DTA file creation - Results"> <form string="DTA file creation - Results">
<group width="300" colspan="4"> <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"/> <field name="dta_file"/>
<group colspan="4"> <group colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel" colspan="2"/> <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>
</group> </group>
</form> </form>