[FIX] account: account.move.line creation with account_tax_id accepts taxes with both base code and tax code or neither. base code xor tax code raises a warning.

Fixes #4452
This commit is contained in:
Arthur Maniet 2015-01-05 15:40:21 +01:00
parent 2107896d22
commit 371e96767d
2 changed files with 19 additions and 25 deletions

View File

@ -1339,24 +1339,25 @@ class account_move_line(osv.osv):
account_id = 'account_paid_id'
base_sign = 'ref_base_sign'
tax_sign = 'ref_tax_sign'
tmp_cnt = 0
base_adjusted = False
for tax in tax_obj.compute_all(cr, uid, [tax_id], total, 1.00, force_excluded=False).get('taxes'):
if bool(tax[base_code]) != bool(tax[tax_code]):
raise osv.except_osv(_('Tax misconfiguration !'), _('You cannot apply a tax which doesn\'t have a base code and a tax code. Please fix the configuration of tax %s.') % tax['name'])
#create the base movement
if tmp_cnt == 0:
if tax[base_code]:
tmp_cnt += 1
if tax_id.price_include:
total = tax['price_unit']
newvals = {
'tax_code_id': tax[base_code],
'tax_amount': tax[base_sign] * abs(total),
}
if tax_id.price_include:
if tax['price_unit'] < 0:
newvals['credit'] = abs(tax['price_unit'])
else:
newvals['debit'] = tax['price_unit']
self.write(cr, uid, [result], newvals, context=context)
if base_adjusted == False:
base_adjusted = True
if tax_id.price_include:
total = tax['price_unit']
newvals = {
'tax_code_id': tax[base_code],
'tax_amount': tax[base_sign] * abs(total),
}
if tax_id.price_include:
if tax['price_unit'] < 0:
newvals['credit'] = abs(tax['price_unit'])
else:
newvals['debit'] = tax['price_unit']
self.write(cr, uid, [result], newvals, context=context)
else:
data = {
'move_id': vals['move_id'],
@ -1372,8 +1373,7 @@ class account_move_line(osv.osv):
'credit': 0.0,
'debit': 0.0,
}
if data['tax_code_id']:
self.create(cr, uid, data, context)
self.create(cr, uid, data, context)
#create the Tax movement
data = {
'move_id': vals['move_id'],
@ -1389,8 +1389,7 @@ class account_move_line(osv.osv):
'credit': tax['amount']<0 and -tax['amount'] or 0.0,
'debit': tax['amount']>0 and tax['amount'] or 0.0,
}
if data['tax_code_id']:
self.create(cr, uid, data, context)
self.create(cr, uid, data, context)
del vals['account_tax_id']
if check and not context.get('novalidate') and (context.get('recompute', True) or journal.entry_posted):

View File

@ -1237,11 +1237,6 @@ class account_voucher(osv.osv):
'account_tax_id': voucher.tax_id.id,
})
if move_line.get('account_tax_id', False):
tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0]
if not (tax_data.base_code_id and tax_data.tax_code_id):
raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name))
# compute the amount in foreign currency
foreign_currency_diff = 0.0
amount_currency = False