[FIX]: fix a calculation of tax on change the

- journal
- lines cr and dr 
- tax id

bzr revid: mga@tinyerp.com-20100914080917-5y7b4ayzchdny3o8
This commit is contained in:
Mantavya Gajjar
2010-09-14 13:39:17 +05:30
parent 4ff1c93a9c
commit da3be9e496
2 changed files with 21 additions and 5 deletions
+19 -3
View File
@@ -166,6 +166,7 @@ class account_voucher(osv.osv):
voucher_line_pool.write(cr, uid, [line.id], {'amount':line.amount, 'untax_amount':line.untax_amount})
if not voucher.tax_id:
self.write(cr, uid, [voucher.id], {'amount':voucher_amount, 'tax_amount':0.0})
continue
tax = [tax_pool.browse(cr, uid, voucher.tax_id.id)]
@@ -223,11 +224,24 @@ class account_voucher(osv.osv):
voucher_total += line_amount
total = voucher_total
total_tax = 0.0
if tax_id:
tax = [tax_pool.browse(cr, uid, tax_id)]
if partner_id:
partner = partner_pool.browse(cr, uid, partner_id) or False
taxes = position_pool.map_tax(cr, uid, partner and partner.property_account_position or False, tax)
tax = tax_pool.browse(cr, uid, taxes)
if not tax[0].price_include:
for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_total, 1).get('taxes'):
total_tax += tax_line.get('amount')
total += total_tax
res.update({
'amount':total,
'tax_amount':total_tax
})
return {
'value':res
}
@@ -370,7 +384,7 @@ class account_voucher(osv.osv):
}
}
def onchange_journal(self, cr, uid, ids, journal_id):
def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, context={}):
if not journal_id:
return False
journal_pool = self.pool.get('account.journal')
@@ -379,8 +393,10 @@ class account_voucher(osv.osv):
tax_id = False
if account_id and account_id.tax_ids:
tax_id = account_id.tax_ids[0].id
return {'value':{'tax_id':tax_id}}
vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context)
vals['value'].update({'tax_id':tax_id})
return vals
def proforma_voucher(self, cr, uid, ids):
self.action_move_line_create(cr, uid, ids)
@@ -19,7 +19,7 @@
<form string="Sales Receipt">
<group col="6" colspan="4">
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id)" string="Customer"/>
<field name="journal_id" domain="[('type','in',['sale','purchase_refund'])]" widget="selection" on_change="onchange_journal(journal_id)"/>
<field name="journal_id" domain="[('type','in',['sale','purchase_refund'])]" widget="selection" on_change="onchange_journal(journal_id, line_cr_ids, tax_id, partner_id)"/>
<field name="number"/>
<field name="name" colspan="4"/>
<field name="date" on_change="onchange_date(date)"/>
@@ -111,7 +111,7 @@
<form string="Vendor Bills">
<group col="6" colspan="4">
<field name="partner_id" required="1" string="Vendor" on_change="onchange_partner_id(partner_id, journal_id, amount)"/>
<field name="journal_id" domain="[('type','in',['purchase','sale_refund'])]" widget="selection" select="1" on_change="onchange_journal(journal_id)"/>
<field name="journal_id" domain="[('type','in',['purchase','sale_refund'])]" widget="selection" select="1" on_change="onchange_journal(journal_id, line_dr_ids, tax_id, partner_id)"/>
<field name="reference" select="1"/>
<field name="name" colspan="4"/>
<field name="number"/>