*major bugfix on vat creation while encoding entries by line

bzr revid: qdp@tinyerp.com-20081120172448-umklgdetkzmc2bxk
This commit is contained in:
qdp 2008-11-20 18:24:48 +01:00
parent a59fc66aff
commit e35628a21e
1 changed files with 51 additions and 12 deletions

View File

@ -794,7 +794,6 @@ class account_move_line(osv.osv):
context={}
account_obj = self.pool.get('account.account')
tax_obj=self.pool.get('account.tax')
if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
if 'journal_id' in vals and 'journal_id' not in context:
@ -880,12 +879,50 @@ class account_move_line(osv.osv):
# CREATE Taxes
if 'account_tax_id' in vals and vals['account_tax_id']:
tax_id=tax_obj.browse(cr,uid,vals['account_tax_id'])
total = vals['credit'] or (-vals['debit'])
total = vals['debit'] - vals['credit']
if journal.refund_journal:
base_code = 'ref_base_code_id'
tax_code = 'ref_tax_code_id'
account_id = 'account_paid_id'
base_sign = 'ref_base_sign'
tax_sign = 'ref_tax_sign'
else:
base_code = 'base_code_id'
tax_code = 'tax_code_id'
account_id = 'account_collected_id'
base_sign = 'base_sign'
tax_sign = 'tax_sign'
tmp_cnt = 0
for tax in tax_obj.compute(cr,uid,[tax_id],total,1.00):
self.write(cr, uid,[result], {
'tax_code_id': tax['base_code_id'],
'tax_amount': tax['base_sign'] * total
})
#create the base movement
if tmp_cnt == 0:
if tax[base_code]:
tmp_cnt += 1
self.write(cr, uid,[result], {
'tax_code_id': tax[base_code],
'tax_amount': tax[base_sign] * abs(total)
})
else:
data = {
'move_id': vals['move_id'],
'journal_id': vals['journal_id'],
'period_id': vals['period_id'],
'name': vals['name']+' '+tax['name'],
'date': vals['date'],
'partner_id': vals.get('partner_id',False),
'ref': vals.get('ref',False),
'account_tax_id': False,
'tax_code_id': tax[base_code],
'tax_amount': tax[base_sign] * abs(total),
'account_id': vals['account_id'],
'credit': 0.0,
'debit': 0.0,
}
if data['tax_code_id']:
self.create(cr, uid, data, context)
#create the VAT movement
data = {
'move_id': vals['move_id'],
'journal_id': vals['journal_id'],
@ -895,13 +932,15 @@ class account_move_line(osv.osv):
'partner_id': vals.get('partner_id',False),
'ref': vals.get('ref',False),
'account_tax_id': False,
'tax_code_id': tax['tax_code_id'],
'tax_amount': tax['tax_sign'] * tax['amount'],
'account_id': tax['account_paid_id'], # or collected ?
'credit': tax['amount']>0 and tax['amount'] or 0.0,
'debit': tax['amount']<0 and -tax['amount'] or 0.0,
'tax_code_id': tax[tax_code],
'tax_amount': tax[tax_sign] * abs(tax['amount']),
'account_id': tax[account_id],
'credit': tax['amount']<0 and -tax['amount'] or 0.0,
'debit': tax['amount']>0 and tax['amount'] or 0.0,
}
self.create(cr, uid, data, context)
if data['tax_code_id']:
self.create(cr, uid, data, context)
if check:
tmp = self.pool.get('account.move').validate(cr, uid, [vals['move_id']], context)
if journal.entry_posted and tmp: