Fix tax line when encoding account lines manually

bzr revid: ced-7d8b75ee2c1f9e787e28a35e70436657a1673201
This commit is contained in:
ced
2007-12-11 15:45:59 +00:00
parent 9664a6975c
commit 14582a930a
3 changed files with 79 additions and 32 deletions
+32 -14
View File
@@ -266,8 +266,8 @@ class account_account(osv.osv):
'reconcile': fields.boolean('Reconcile', help="Check this account if the user can make a reconciliation of the entries in this account."),
'shortcut': fields.char('Shortcut', size=12),
'close_method': fields.selection([('none','None'), ('balance','Balance'), ('detail','Detail'),('unreconciled','Unreconciled')], 'Deferral Method', required=True, help="Tell Tiny ERP how to process the entries of this account when you close a fiscal year. None removes all entries to start with an empty account for the new fiscal year. Balance creates only one entry to keep the balance for the new fiscal year. Detail keeps the detail of all entries of the preceeding years. Unreconciled keeps the detail of unreconciled entries only."),
'tax_ids': fields.many2many('account.tax', 'account_account_tax_default_rel', 'account_id','tax_id', 'Default Taxes'),
'tax_ids': fields.many2many('account.tax', 'account_account_tax_default_rel',
'account_id','tax_id', 'Default Taxes'),
'note': fields.text('Note'),
'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Company Currency'),
'company_id': fields.many2one('res.company', 'Company', required=True),
@@ -765,33 +765,51 @@ class account_move(osv.osv):
todo = []
account = {}
account2 = {}
field_base = ''
if journal.type not in ('purchase','sale'):
continue
if journal.type=='purchase':
field_base='ref_'
for line in move.line_id:
if move.journal_id.type == 'sale':
if line.debit:
field_base = 'ref_'
key = 'account_paid_id'
else:
field_base = ''
key = 'account_collected_id'
else:
if line.debit:
field_base = ''
key = 'account_collected_id'
else:
field_base = 'ref_'
key = 'account_paid_id'
if line.account_id.tax_ids:
code = amount = False
for tax in line.account_id.tax_ids:
if tax.tax_code_id:
acc = (line.debit >0) and tax.account_paid_id.id or tax.account_collected_id.id
account[acc] = (getattr(tax,field_base+'tax_code_id').id, getattr(tax,field_base+'tax_sign'))
account2[(acc,getattr(tax,field_base+'tax_code_id').id)] = (getattr(tax,field_base+'tax_code_id').id, getattr(tax,field_base+'tax_sign'))
code = getattr(tax,field_base+'base_code_id').id
amount = getattr(tax, field_base+'base_sign') * (line.debit + line.credit)
acc = getattr(tax, key).id
account[acc] = (getattr(tax,
field_base + 'tax_code_id').id,
getattr(tax, field_base + 'tax_sign'))
account2[(acc,getattr(tax,
field_base + 'tax_code_id').id)] = (getattr(tax,
field_base + 'tax_code_id').id,
getattr(tax, field_base + 'tax_sign'))
code = getattr(tax, field_base + 'base_code_id').id
amount = getattr(tax, field_base+'base_sign') * \
(line.debit + line.credit)
break
if code and not (line.tax_code_id or line.tax_amount):
self.pool.get('account.move.line').write(cr, uid, [line.id], {
if code and not (line.tax_code_id or line.tax_amount):
self.pool.get('account.move.line').write(cr, uid,
[line.id], {
'tax_code_id': code,
'tax_amount': amount
}, context, check=False)
}, context=context, check=False)
else:
todo.append(line)
for line in todo:
code = amount = 0
key = (line.account_id.id,line.tax_code_id.id)
key = (line.account_id.id, line.tax_code_id.id)
if key in account2:
code = account2[key][0]
amount = account2[key][1] * (line.debit + line.credit)
+40 -10
View File
@@ -108,9 +108,22 @@ class account_move_line(osv.osv):
ref_id = ref_id or l.ref
total += (l.debit - l.credit)
for tax in l.account_id.tax_ids:
acc = (l.debit >0) and tax.account_paid_id.id or tax.account_collected_id.id
taxes.setdefault((acc,tax.tax_code_id.id), False)
taxes[(l.account_id.id,l.tax_code_id.id)] = True
if move.journal_id.type == 'sale':
if l.debit:
code = tax.ref_tax_code_id.id
acc = tax.account_paid_id.id
else:
code = tax.tax_code_id.id
acc = tax.account_collected_id.id
else:
if l.debit:
code = tax.tax_code_id.id
acc = tax.account_collected_id.id
else:
code = tax.ref_tax_code_id.id
acc = tax.account_paid_id.id
taxes.setdefault((acc, code), False)
taxes[(l.account_id.id, l.tax_code_id.id)] = True
if 'name' in fields:
data.setdefault('name', l.name)
@@ -120,20 +133,35 @@ class account_move_line(osv.osv):
data['partner_id'] = partner_id
if move.journal_id.type in ('purchase', 'sale'):
field_base=''
if move.journal_id.type=='purchase':
field_base='ref_'
for t in taxes:
if not taxes[t] and t[0]:
s=0
s = 0
tax_amount = 0
for l in move.line_id:
key = (l.debit and 'account_paid_id') or 'account_collected_id'
for tax in self.pool.get('account.tax').compute(cr, uid, l.account_id.tax_ids, l.debit or l.credit, 1, False):
if (tax[key] == t[0]) and (tax[field_base+'tax_code_id']==t[1]):
if move.journal_id.type == 'sale':
if l.debit:
field_base = 'ref_'
key = 'account_paid_id'
else:
field_base = ''
key = 'account_collected_id'
else:
if l.debit:
field_base = ''
key = 'account_collected_id'
else:
field_base = 'ref_'
key = 'account_paid_id'
for tax in self.pool.get('account.tax').compute(cr, uid,
l.account_id.tax_ids, l.debit or l.credit, 1, False):
if (tax[key] == t[0]) \
and (tax[field_base + 'tax_code_id'] == t[1]):
if l.debit:
s += tax['amount']
else:
s -= tax['amount']
tax_amount += tax['amount'] * \
tax[field_base + 'tax_sign']
if ('debit' in fields) or ('credit' in fields):
data['debit'] = s>0 and s or 0.0
data['credit'] = s<0 and -s or 0.0
@@ -142,6 +170,8 @@ class account_move_line(osv.osv):
data['tax_code_id'] = t[1]
if 'account_id' in fields:
data['account_id'] = t[0]
if 'tax_amount' in fields:
data['tax_amount'] = tax_amount
#
# Compute line for tax T
#
+7 -8
View File
@@ -229,23 +229,22 @@
<field name="field">credit</field>
<field name="sequence" eval="9"/>
</record>
<record model="account.journal.column" id="journal_col24">
<field name="view_id" ref="account_journal_view"/>
<field name="name">State</field>
<field name="field">state</field>
<field name="sequence" eval="10"/>
</record>
<record model="account.journal.column" id="journal_col25">
<field name="view_id" ref="account_journal_view"/>
<field name="name">Tax Acc.</field>
<field name="field">tax_code_id</field>
<field name="sequence" eval="11"/>
<field name="sequence" eval="10"/>
</record>
<record model="account.journal.column" id="journal_col26">
<field name="view_id" ref="account_journal_view"/>
<field name="name">Tax</field>
<field name="field">tax_amount</field>
<field name="sequence" eval="11"/>
</record>
<record model="account.journal.column" id="journal_col24">
<field name="view_id" ref="account_journal_view"/>
<field name="name">State</field>
<field name="field">state</field>
<field name="sequence" eval="12"/>
</record>