ACCOUNT: Add possibilitty to include tax amount in base amount for the computation of the next taxes
bzr revid: ced-2131b8cd119da193d24cc3f7fbd82bebb667e858
This commit is contained in:
parent
5a22519a9c
commit
2dea59f722
|
@ -826,6 +826,7 @@ class account_tax(osv.osv):
|
||||||
'ref_tax_code_id': fields.many2one('account.tax.code', 'Tax Code', help="Use this code for the VAT declaration."),
|
'ref_tax_code_id': fields.many2one('account.tax.code', 'Tax Code', help="Use this code for the VAT declaration."),
|
||||||
'ref_base_sign': fields.float('Base Code Sign', help="Usualy 1 or -1."),
|
'ref_base_sign': fields.float('Base Code Sign', help="Usualy 1 or -1."),
|
||||||
'ref_tax_sign': fields.float('Tax Code Sign', help="Usualy 1 or -1."),
|
'ref_tax_sign': fields.float('Tax Code Sign', help="Usualy 1 or -1."),
|
||||||
|
'include_base_amount': fields.boolean('Include in base amount', help="Indicate if the amount of tax must be included in the base amount for the computation of the next taxes"),
|
||||||
}
|
}
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'python_compute': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n\nresult = price_unit * 0.10''',
|
'python_compute': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n\nresult = price_unit * 0.10''',
|
||||||
|
@ -839,6 +840,7 @@ class account_tax(osv.osv):
|
||||||
'ref_base_sign': lambda *a: -1,
|
'ref_base_sign': lambda *a: -1,
|
||||||
'tax_sign': lambda *a: 1,
|
'tax_sign': lambda *a: 1,
|
||||||
'base_sign': lambda *a: 1,
|
'base_sign': lambda *a: 1,
|
||||||
|
'include_base_amount': lambda *a: False,
|
||||||
}
|
}
|
||||||
_order = 'sequence'
|
_order = 'sequence'
|
||||||
|
|
||||||
|
@ -854,24 +856,21 @@ class account_tax(osv.osv):
|
||||||
res.append(tax)
|
res.append(tax)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _unit_compute(self, cr, uid, ids, price_unit, address_id=None):
|
def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None):
|
||||||
taxes = self.browse(cr, uid, ids)
|
|
||||||
return self._unit_compute_br(cr, uid, taxes, price_unit, address_id)
|
|
||||||
|
|
||||||
def _unit_compute_br(self, cr, uid, taxes, price_unit, address_id=None):
|
|
||||||
taxes = self._applicable(cr, uid, taxes, price_unit, address_id)
|
taxes = self._applicable(cr, uid, taxes, price_unit, address_id)
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
|
cur_price_unit=price_unit
|
||||||
for tax in taxes:
|
for tax in taxes:
|
||||||
# we compute the amount for the current tax object and append it to the result
|
# we compute the amount for the current tax object and append it to the result
|
||||||
if tax.type=='percent':
|
if tax.type=='percent':
|
||||||
amount = price_unit * tax.amount
|
amount = cur_price_unit * tax.amount
|
||||||
res.append({'id':tax.id, 'name':tax.name, 'amount':amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id})
|
res.append({'id':tax.id, 'name':tax.name, 'amount':amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': cur_price_unit, 'tax_code_id': tax.tax_code_id.id,})
|
||||||
elif tax.type=='fixed':
|
elif tax.type=='fixed':
|
||||||
res.append({'id':tax.id, 'name':tax.name, 'amount':tax.amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id})
|
res.append({'id':tax.id, 'name':tax.name, 'amount':tax.amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': 1, 'tax_code_id': tax.tax_code_id.id,})
|
||||||
elif tax.type=='code':
|
elif tax.type=='code':
|
||||||
address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
|
address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
|
||||||
localdict = {'price_unit':price_unit, 'address':address}
|
localdict = {'price_unit':cur_price_unit, 'address':address}
|
||||||
exec tax.python_compute in localdict
|
exec tax.python_compute in localdict
|
||||||
amount = localdict['result']
|
amount = localdict['result']
|
||||||
res.append({
|
res.append({
|
||||||
|
@ -879,7 +878,14 @@ class account_tax(osv.osv):
|
||||||
'name': tax.name,
|
'name': tax.name,
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'account_collected_id': tax.account_collected_id.id,
|
'account_collected_id': tax.account_collected_id.id,
|
||||||
'account_paid_id': tax.account_paid_id.id
|
'account_paid_id': tax.account_paid_id.id,
|
||||||
|
'base_code_id': tax.base_code_id.id,
|
||||||
|
'ref_base_code_id': tax.ref_base_code_id.id,
|
||||||
|
'sequence': tax.sequence,
|
||||||
|
'base_sign': tax.base_sign,
|
||||||
|
'ref_base_sign': tax.ref_base_sign,
|
||||||
|
'price_unit': cur_price_unit,
|
||||||
|
'tax_code_id': tax.tax_code_id.id,
|
||||||
})
|
})
|
||||||
amount2 = res[-1]['amount']
|
amount2 = res[-1]['amount']
|
||||||
if len(tax.child_ids):
|
if len(tax.child_ids):
|
||||||
|
@ -889,11 +895,13 @@ class account_tax(osv.osv):
|
||||||
else:
|
else:
|
||||||
amount = amount2
|
amount = amount2
|
||||||
for t in tax.child_ids:
|
for t in tax.child_ids:
|
||||||
parent_tax = self._unit_compute_br(cr, uid, [t], amount, address_id)
|
parent_tax = self._unit_compute(cr, uid, [t], amount, address_id)
|
||||||
res.extend(parent_tax)
|
res.extend(parent_tax)
|
||||||
|
if tax.include_base_amount:
|
||||||
|
cur_price_unit+=amount2
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def compute(self, cr, uid, ids, price_unit, quantity, address_id=None):
|
def compute(self, cr, uid, taxes, price_unit, quantity, address_id=None):
|
||||||
"""
|
"""
|
||||||
Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
|
Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
|
||||||
|
|
||||||
|
@ -902,9 +910,9 @@ class account_tax(osv.osv):
|
||||||
tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
|
tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
|
||||||
one tax for each tax id in IDS and their childs
|
one tax for each tax id in IDS and their childs
|
||||||
"""
|
"""
|
||||||
res = self._unit_compute(cr, uid, ids, price_unit, address_id)
|
res = self._unit_compute(cr, uid, taxes, price_unit, address_id)
|
||||||
for r in res:
|
for r in res:
|
||||||
r['amount'] = round(quantity * r['amount'],2)
|
r['amount'] *= quantity
|
||||||
return res
|
return res
|
||||||
account_tax()
|
account_tax()
|
||||||
|
|
||||||
|
|
|
@ -95,20 +95,18 @@ class account_move_line(osv.osv):
|
||||||
|
|
||||||
data['partner_id'] = partner_id
|
data['partner_id'] = partner_id
|
||||||
|
|
||||||
print taxes
|
|
||||||
for t in taxes:
|
for t in taxes:
|
||||||
if not taxes[t] and t[0]:
|
if not taxes[t] and t[0]:
|
||||||
s=0
|
s=0
|
||||||
for l in move.line_id:
|
for l in move.line_id:
|
||||||
for tax in l.account_id.tax_ids:
|
taxes = self.pool.get('account.tax').compute(cr, uid, l.account_id.tax_ids, l.debit or l.credit, 1, False)
|
||||||
taxes = self.pool.get('account.tax').compute(cr, uid, [tax.id], l.debit or l.credit, 1, False)
|
key = (l.debit and 'account_paid_id') or 'account_collected_id'
|
||||||
key = (l.debit and 'account_paid_id') or 'account_collected_id'
|
for t2 in taxes:
|
||||||
for t2 in taxes:
|
if (t2[key] == t[0]) and (t2['tax_code_id']==t[1]):
|
||||||
if (t2[key] == t[0]) and (tax.tax_code_id.id==t[1]):
|
if l.debit:
|
||||||
if l.debit:
|
s += t2['amount']
|
||||||
s += t2['amount']
|
else:
|
||||||
else:
|
s -= t2['amount']
|
||||||
s -= t2['amount']
|
|
||||||
data['debit'] = s>0 and s or 0.0
|
data['debit'] = s>0 and s or 0.0
|
||||||
data['credit'] = s<0 and -s or 0.0
|
data['credit'] = s<0 and -s or 0.0
|
||||||
|
|
||||||
|
|
|
@ -589,7 +589,9 @@
|
||||||
<field name="type" select="1"/>
|
<field name="type" select="1"/>
|
||||||
<field name="applicable_type"/>
|
<field name="applicable_type"/>
|
||||||
<field name="amount" select="1"/>
|
<field name="amount" select="1"/>
|
||||||
|
<field name="include_base_amount"/>
|
||||||
<field name="domain"/>
|
<field name="domain"/>
|
||||||
|
<newline/>
|
||||||
<field name="account_collected_id"/>
|
<field name="account_collected_id"/>
|
||||||
<label string="Keep empty to use the income account" nolabel="1" colspan="2"/>
|
<label string="Keep empty to use the income account" nolabel="1" colspan="2"/>
|
||||||
<field name="account_paid_id"/>
|
<field name="account_paid_id"/>
|
||||||
|
|
|
@ -566,9 +566,11 @@ class account_invoice_line(osv.osv):
|
||||||
res = []
|
res = []
|
||||||
tax_grouped = {}
|
tax_grouped = {}
|
||||||
tax_obj = self.pool.get('account.tax')
|
tax_obj = self.pool.get('account.tax')
|
||||||
|
cur_obj = self.pool.get('res.currency')
|
||||||
#TODO: rewrite using browse instead of the manual SQL queries
|
#TODO: rewrite using browse instead of the manual SQL queries
|
||||||
# cr.execute('SELECT id FROM account_invoice_line WHERE invoice_id=%d', (invoice_id,))
|
# cr.execute('SELECT id FROM account_invoice_line WHERE invoice_id=%d', (invoice_id,))
|
||||||
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id)
|
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id)
|
||||||
|
cur = inv.currency_id
|
||||||
|
|
||||||
for line in inv.invoice_line:
|
for line in inv.invoice_line:
|
||||||
res.append( {
|
res.append( {
|
||||||
|
@ -579,37 +581,36 @@ class account_invoice_line(osv.osv):
|
||||||
'price':round(line.quantity*line.price_unit * (1.0- (line.discount or 0.0)/100.0),2),
|
'price':round(line.quantity*line.price_unit * (1.0- (line.discount or 0.0)/100.0),2),
|
||||||
'account_id':line.account_id.id
|
'account_id':line.account_id.id
|
||||||
})
|
})
|
||||||
for tax2 in line.invoice_line_tax_id:
|
for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, (line.price_unit *(1.0-(line['discount'] or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id):
|
||||||
for tax in tax_obj.compute(cr, uid, [tax2.id], line.price_unit, line.quantity, inv.address_invoice_id.id):
|
tax['amount'] = cur_obj.round(cr, uid, cur, tax['amount'])
|
||||||
tax['amount'] = tax['amount']*(1.0- (line['discount'] or 0.0)/100.0)
|
tax['sequence'] = tax['sequence']
|
||||||
tax['sequence'] = tax2.sequence
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Setting the tax account and amount for the line
|
# Setting the tax account and amount for the line
|
||||||
#
|
#
|
||||||
if inv.type in ('out_invoice','out_refund'):
|
if inv.type in ('out_invoice','out_refund'):
|
||||||
res[-1]['tax_code_id'] = tax2.base_code_id.id
|
res[-1]['tax_code_id'] = tax['base_code_id']
|
||||||
res[-1]['tax_amount'] = line['price_unit'] * line['quantity'] * (1.0- (line['discount'] or 0.0)/100.0) * tax2.base_sign
|
res[-1]['tax_amount'] = tax['amount'] * tax['base_sign']
|
||||||
else:
|
else:
|
||||||
res[-1]['tax_code_id'] = tax2.ref_base_code_id.id
|
res[-1]['tax_code_id'] = tax['ref_base_code_id']
|
||||||
res[-1]['tax_amount'] = line['price_unit'] * line['quantity'] * (1.0- (line['discount'] or 0.0)/100.0) * tax2.ref_base_sign
|
res[-1]['tax_amount'] = tax['amount'] * tax['ref_base_sign']
|
||||||
if inv.type in ('out_refund','in_refund'):
|
if inv.type in ('out_refund','in_refund'):
|
||||||
res[-1]['tax_amount'] = -res[-1]['tax_amount']
|
res[-1]['tax_amount'] = -res[-1]['tax_amount']
|
||||||
|
|
||||||
if inv.type in ('out_invoice','out_refund'):
|
if inv.type in ('out_invoice','out_refund'):
|
||||||
tax['account_id'] = tax['account_collected_id'] or line.account_id.id
|
tax['account_id'] = tax['account_collected_id'] or line.account_id.id
|
||||||
else:
|
else:
|
||||||
tax['account_id'] = tax['account_paid_id'] or line.account_id.id
|
tax['account_id'] = tax['account_paid_id'] or line.account_id.id
|
||||||
#
|
#
|
||||||
# Revoir la clé: tax.id ?
|
# Revoir la clé: tax.id ?
|
||||||
#
|
#
|
||||||
key = (res[-1]['tax_code_id'], tax['account_id'])
|
key = (res[-1]['tax_code_id'], tax['account_id'])
|
||||||
if not key in tax_grouped:
|
if not key in tax_grouped:
|
||||||
tax_grouped[key] = tax
|
tax_grouped[key] = tax
|
||||||
tax_grouped[key]['base'] = line['price_unit'] * line['quantity'] * (1.0- (line['discount'] or 0.0)/100.0)
|
tax_grouped[key]['base'] = tax['price_unit'] * line['quantity']
|
||||||
else:
|
else:
|
||||||
tax_grouped[key]['amount'] += tax['amount']
|
tax_grouped[key]['amount'] += tax['amount']
|
||||||
tax_grouped[key]['base'] += line['price_unit'] * line['quantity'] * (1.0- (line['discount'] or 0.0)/100.0)
|
tax_grouped[key]['base'] += tax['price_unit'] * line['quantity']
|
||||||
# delete automatic tax lines for this invoice
|
# delete automatic tax lines for this invoice
|
||||||
cr.execute("DELETE FROM account_invoice_tax WHERE NOT manual AND invoice_id=%d", (invoice_id,))
|
cr.execute("DELETE FROM account_invoice_tax WHERE NOT manual AND invoice_id=%d", (invoice_id,))
|
||||||
self.move_line_tax_create(cr, uid, inv, tax_grouped, context)
|
self.move_line_tax_create(cr, uid, inv, tax_grouped, context)
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
<blockTableStyle id="Tableau3">
|
<blockTableStyle id="Tableau3">
|
||||||
<blockAlignment value="LEFT"/>
|
<blockAlignment value="LEFT"/>
|
||||||
<blockValign value="TOP"/>
|
<blockValign value="TOP"/>
|
||||||
|
<blockBackground colorName="#e6e6e6" start="0,1" stop="0,1"/>
|
||||||
|
<blockBackground colorName="#e6e6e6" start="1,1" stop="1,1"/>
|
||||||
|
<blockBackground colorName="#e6e6e6" start="2,1" stop="2,1"/>
|
||||||
</blockTableStyle>
|
</blockTableStyle>
|
||||||
<blockTableStyle id="Tableau4">
|
<blockTableStyle id="Tableau4">
|
||||||
<blockAlignment value="LEFT"/>
|
<blockAlignment value="LEFT"/>
|
||||||
|
@ -105,9 +108,9 @@
|
||||||
<para style="Standard">
|
<para style="Standard">
|
||||||
<font color="white"> </font>
|
<font color="white"> </font>
|
||||||
</para>
|
</para>
|
||||||
<para style="Standard">Tél. : [[ o.address_invoice_id.phone or '' ]]</para>
|
<para style="Standard">Tel. : [[ o.address_invoice_id.phone or '' ]]</para>
|
||||||
<para style="Standard">Fax : [[ o.address_invoice_id.fax or '' ]]</para>
|
<para style="Standard">Fax : [[ o.address_invoice_id.fax or '' ]]</para>
|
||||||
<para style="Standard">TVA : [[ o.partner_id.vat or '' ]]</para>
|
<para style="Standard">VAT : [[ o.partner_id.vat or '' ]]</para>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</blockTable>
|
</blockTable>
|
||||||
|
@ -152,10 +155,10 @@
|
||||||
<para style="P9">Unit Price</para>
|
<para style="P9">Unit Price</para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P9">Disc.</para>
|
<para style="P9">Disc. (%)</para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P9">Net Price</para>
|
<para style="P9">Price</para>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</blockTable>
|
</blockTable>
|
||||||
|
@ -176,7 +179,7 @@
|
||||||
<para style="P12">[[ '%.2f' % l.price_unit ]]</para>
|
<para style="P12">[[ '%.2f' % l.price_unit ]]</para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P12">[[ '%.3f' % (l.discount or 0.0) ]] </para>
|
<para style="P12">[[ '%.2f' % (l.discount or 0.0) ]] </para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P12">[[ '%.2f' %l.price_subtotal ]] [[o.currency_id.code ]]</para>
|
<para style="P12">[[ '%.2f' %l.price_subtotal ]] [[o.currency_id.code ]]</para>
|
||||||
|
@ -229,7 +232,7 @@
|
||||||
<blockTable colWidths="214.0,95.0" style="Tableau5">
|
<blockTable colWidths="214.0,95.0" style="Tableau5">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<para style="P18">Subtotal :</para>
|
<para style="P18">Total (excl. taxes):</para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P19">[[ '%.2f' % o.amount_untaxed ]] [[o.currency_id.code ]]</para>
|
<para style="P19">[[ '%.2f' % o.amount_untaxed ]] [[o.currency_id.code ]]</para>
|
||||||
|
@ -237,7 +240,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<para style="P18">Taxes :</para>
|
<para style="P18">Taxes:</para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P19">[[ '%.2f' % o.amount_tax ]] [[o.currency_id.code ]]</para>
|
<para style="P19">[[ '%.2f' % o.amount_tax ]] [[o.currency_id.code ]]</para>
|
||||||
|
@ -245,7 +248,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<para style="P20">Total :</para>
|
<para style="P20">Total <font face="Times-Roman">(incl. taxes):</font></para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P21">[[ '%.2f' % o.amount_total ]] [[o.currency_id.code ]]</para>
|
<para style="P21">[[ '%.2f' % o.amount_total ]] [[o.currency_id.code ]]</para>
|
||||||
|
|
|
@ -40,24 +40,22 @@ class account_tax(osv.osv):
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'python_compute_inv': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n\nresult = price_unit * 0.10''',
|
'python_compute_inv': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n\nresult = price_unit * 0.10''',
|
||||||
}
|
}
|
||||||
def _unit_compute_inv(self, cr, uid, ids, price_unit, address_id=None):
|
def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None):
|
||||||
taxes = self.browse(cr, uid, ids)
|
|
||||||
return self._unit_compute_inv_br(cr, uid, taxes, price_unit, address_id)
|
|
||||||
|
|
||||||
def _unit_compute_inv_br(self, cr, uid, taxes, price_unit, address_id=None):
|
|
||||||
taxes = self._applicable(cr, uid, taxes, price_unit, address_id)
|
taxes = self._applicable(cr, uid, taxes, price_unit, address_id)
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
|
taxes.reverse()
|
||||||
|
cur_price_unit=price_unit
|
||||||
for tax in taxes:
|
for tax in taxes:
|
||||||
# we compute the amount for the current tax object and append it to the result
|
# we compute the amount for the current tax object and append it to the result
|
||||||
if tax.type=='percent':
|
if tax.type=='percent':
|
||||||
amount = price_unit - (price_unit / (1 + tax.amount))
|
amount = cur_price_unit - (cur_price_unit / (1 + tax.amount))
|
||||||
res.append({'id':tax.id, 'name':tax.name, 'amount':amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id})
|
res.append({'id':tax.id, 'name':tax.name, 'amount':amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': cur_price_unit - amount,})
|
||||||
elif tax.type=='fixed':
|
elif tax.type=='fixed':
|
||||||
res.append({'id':tax.id, 'name':tax.name, 'amount':tax.amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id})
|
res.append({'id':tax.id, 'name':tax.name, 'amount':tax.amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': 1,})
|
||||||
elif tax.type=='code':
|
elif tax.type=='code':
|
||||||
address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
|
address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
|
||||||
localdict = {'price_unit':price_unit, 'address':address}
|
localdict = {'price_unit':cur_price_unit, 'address':address}
|
||||||
exec tax.python_compute_inv in localdict
|
exec tax.python_compute_inv in localdict
|
||||||
amount = localdict['result']
|
amount = localdict['result']
|
||||||
res.append({
|
res.append({
|
||||||
|
@ -65,7 +63,13 @@ class account_tax(osv.osv):
|
||||||
'name': tax.name,
|
'name': tax.name,
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'account_collected_id': tax.account_collected_id.id,
|
'account_collected_id': tax.account_collected_id.id,
|
||||||
'account_paid_id': tax.account_paid_id.id
|
'account_paid_id': tax.account_paid_id.id,
|
||||||
|
'base_code_id': tax.base_code_id.id,
|
||||||
|
'ref_base_code_id': tax.ref_base_code_id.id,
|
||||||
|
'sequence': tax.sequence,
|
||||||
|
'base_sign': tax.base_sign,
|
||||||
|
'ref_base_sign': tax.ref_base_sign,
|
||||||
|
'price_unit': cur_price_unit - amount,
|
||||||
})
|
})
|
||||||
amount2 = res[-1]['amount']
|
amount2 = res[-1]['amount']
|
||||||
if len(tax.child_ids):
|
if len(tax.child_ids):
|
||||||
|
@ -75,11 +79,14 @@ class account_tax(osv.osv):
|
||||||
else:
|
else:
|
||||||
amount = amount2
|
amount = amount2
|
||||||
for t in tax.child_ids:
|
for t in tax.child_ids:
|
||||||
parent_tax = self._unit_compute_inv_br(cr, uid, [t], amount, address_id)
|
parent_tax = self._unit_compute_inv(cr, uid, [t], amount, address_id)
|
||||||
res.extend(parent_tax)
|
res.extend(parent_tax)
|
||||||
|
if tax.include_base_amount:
|
||||||
|
cur_price_unit-=amount
|
||||||
|
taxes.reverse()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def compute_inv(self, cr, uid, ids, price_unit, quantity, address_id=None):
|
def compute_inv(self, cr, uid, taxes, price_unit, quantity, address_id=None):
|
||||||
"""
|
"""
|
||||||
Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
|
Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
|
||||||
Price Unit is a VAT included price
|
Price Unit is a VAT included price
|
||||||
|
@ -89,7 +96,7 @@ class account_tax(osv.osv):
|
||||||
tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
|
tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
|
||||||
one tax for each tax id in IDS and their childs
|
one tax for each tax id in IDS and their childs
|
||||||
"""
|
"""
|
||||||
res = self._unit_compute_inv(cr, uid, ids, price_unit, address_id)
|
res = self._unit_compute_inv(cr, uid, taxes, price_unit, address_id)
|
||||||
for r in res:
|
for r in res:
|
||||||
r['amount'] *= quantity
|
r['amount'] *= quantity
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -90,6 +90,8 @@ class account_invoice_line(osv.osv):
|
||||||
res = []
|
res = []
|
||||||
tax_grouped = {}
|
tax_grouped = {}
|
||||||
tax_obj = self.pool.get('account.tax')
|
tax_obj = self.pool.get('account.tax')
|
||||||
|
cur_obj = self.pool.get('res.currency')
|
||||||
|
cur = inv.currency_id
|
||||||
for line in inv.invoice_line:
|
for line in inv.invoice_line:
|
||||||
res.append( {
|
res.append( {
|
||||||
'type':'src',
|
'type':'src',
|
||||||
|
@ -100,37 +102,41 @@ class account_invoice_line(osv.osv):
|
||||||
'account_id':line.account_id.id,
|
'account_id':line.account_id.id,
|
||||||
'tax_amount': 0.0
|
'tax_amount': 0.0
|
||||||
})
|
})
|
||||||
for tax2 in line.invoice_line_tax_id:
|
for tax in tax_obj.compute_inv(cr, uid, line.invoice_line_tax_id, (line.price_unit *(1.0-(line['discount'] or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id):
|
||||||
for tax in tax_obj.compute_inv(cr, uid, [tax2.id], line.price_unit, line.quantity, inv.address_invoice_id.id):
|
tax['amount'] = cur_obj.round(cr, uid, cur, tax['amount'])
|
||||||
tax['amount'] = round(tax['amount']*(1.0- (line['discount'] or 0.0)/100.0),2)
|
tax['sequence'] = tax['sequence']
|
||||||
tax['sequence'] = tax2.sequence
|
|
||||||
|
|
||||||
res[-1]['tax_amount'] += (line['price_unit'] * line['quantity'] * (1.0- (line['discount'] or 0.0)/100.0) * tax2.base_sign)
|
#res[-1]['tax_amount'] += (line['price_unit'] * line['quantity'] * (1.0- (line['discount'] or 0.0)/100.0) * tax2.base_sign)
|
||||||
#
|
#
|
||||||
# Setting the tax account and amount for the line
|
# Setting the tax account and amount for the line
|
||||||
#
|
#
|
||||||
if inv.type in ('out_invoice','in_refund'):
|
if inv.type in ('out_invoice','out_refund'):
|
||||||
res[-1]['tax_code_id'] = tax2.base_code_id.id
|
res[-1]['tax_code_id'] = tax['base_code_id']
|
||||||
else:
|
res[-1]['tax_amount'] = tax['amount'] * tax['base_sign']
|
||||||
res[-1]['tax_code_id'] = tax2.ref_base_code_id.id
|
else:
|
||||||
|
res[-1]['tax_code_id'] = tax['ref_base_code_id']
|
||||||
|
res[-1]['tax_amount'] = tax['amount'] * tax['ref_base_sign']
|
||||||
|
if inv.type in ('out_refund','in_refund'):
|
||||||
|
res[-1]['tax_amount'] = -res[-1]['tax_amount']
|
||||||
|
|
||||||
if inv.type in ('out_invoice','in_refund'):
|
if inv.type in ('out_invoice','out_refund'):
|
||||||
tax['account_id'] = tax['account_collected_id'] or line.account_id.id
|
tax['account_id'] = tax['account_collected_id'] or line.account_id.id
|
||||||
else:
|
else:
|
||||||
tax['account_id'] = tax['account_paid_id'] or line.account_id.id
|
tax['account_id'] = tax['account_paid_id'] or line.account_id.id
|
||||||
#
|
#
|
||||||
# Revoir la clé: tax.id ?
|
# Revoir la clé: tax.id ?
|
||||||
#
|
#
|
||||||
key = (tax['id'], tax['account_id'])
|
key = (res[-1]['tax_code_id'], tax['account_id'])
|
||||||
|
#res[-1]['price'] -= tax['amount']
|
||||||
res[-1]['price'] -= tax['amount']
|
#res[-1]['tax_amount'] -= (tax['amount']* tax2.base_sign)
|
||||||
res[-1]['tax_amount'] -= (tax['amount']* tax2.base_sign)
|
if not key in tax_grouped:
|
||||||
if not key in tax_grouped:
|
tax_grouped[key] = tax
|
||||||
tax_grouped[key] = tax
|
#tax_grouped[key]['base'] = res[-1]['price']
|
||||||
tax_grouped[key]['base'] = res[-1]['price']
|
tax_grouped[key]['base'] = tax['price_unit'] * line['quantity']
|
||||||
else:
|
else:
|
||||||
tax_grouped[key]['amount'] += tax['amount']
|
tax_grouped[key]['amount'] += tax['amount']
|
||||||
tax_grouped[key]['base'] += res[-1]['price']
|
#tax_grouped[key]['base'] += res[-1]['price']
|
||||||
|
tax_grouped[key]['base'] += tax['price_unit'] * line['quantity']
|
||||||
# delete automatic tax lines for this invoice
|
# delete automatic tax lines for this invoice
|
||||||
cr.execute("DELETE FROM account_invoice_tax WHERE NOT manual AND invoice_id=%d", (invoice_id,))
|
cr.execute("DELETE FROM account_invoice_tax WHERE NOT manual AND invoice_id=%d", (invoice_id,))
|
||||||
self.move_line_tax_create(cr, uid, inv, tax_grouped, context)
|
self.move_line_tax_create(cr, uid, inv, tax_grouped, context)
|
||||||
|
|
|
@ -65,9 +65,8 @@ class purchase_order(osv.osv):
|
||||||
val = 0.0
|
val = 0.0
|
||||||
cur=order.pricelist_id.currency_id
|
cur=order.pricelist_id.currency_id
|
||||||
for line in order.order_line:
|
for line in order.order_line:
|
||||||
for tax in line.taxes_id:
|
for c in self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id):
|
||||||
for c in self.pool.get('account.tax').compute(cr, uid, [tax.id], line.price_unit, line.product_qty, order.partner_address_id.id):
|
val+= cur_obj.round(cr, uid, cur, c['amount'])
|
||||||
val+= cur_obj.round(cr, uid, cur, c['amount'])
|
|
||||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -50,17 +50,18 @@ class purchase_order(osv.osv):
|
||||||
|
|
||||||
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
||||||
res = {}
|
res = {}
|
||||||
|
cur_obj=self.pool.get('res.currency')
|
||||||
for order in self.browse(cr, uid, ids):
|
for order in self.browse(cr, uid, ids):
|
||||||
val = 0.0
|
val = 0.0
|
||||||
|
cur=order.pricelist_id.currency_id
|
||||||
for line in order.order_line:
|
for line in order.order_line:
|
||||||
for tax in line.taxes_id:
|
if order.price_type=='tax_included':
|
||||||
if order.price_type=='tax_included':
|
ttt = self.pool.get('account.tax').compute_inv(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id)
|
||||||
ttt = self.pool.get('account.tax').compute_inv(cr, uid, [tax.id], line.price_unit, line.product_qty, order.partner_address_id.id)
|
else:
|
||||||
else:
|
ttt = self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id)
|
||||||
ttt = self.pool.get('account.tax').compute(cr, uid, [tax.id], line.price_unit, line.product_qty, order.partner_address_id.id)
|
for c in ttt:
|
||||||
for c in ttt:
|
val += cur_obj.round(cr, uid, cur, c['amount'])
|
||||||
val += round(c['amount'], 2)
|
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||||
res[order.id]=round(val,2)
|
|
||||||
return res
|
return res
|
||||||
_inherit = "purchase.order"
|
_inherit = "purchase.order"
|
||||||
_columns = {
|
_columns = {
|
||||||
|
|
|
@ -85,9 +85,8 @@ class sale_order(osv.osv):
|
||||||
val = 0.0
|
val = 0.0
|
||||||
cur=order.pricelist_id.currency_id
|
cur=order.pricelist_id.currency_id
|
||||||
for line in order.order_line:
|
for line in order.order_line:
|
||||||
for tax in line.tax_id:
|
for c in self.pool.get('account.tax').compute(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, order.partner_invoice_id.id):
|
||||||
for c in self.pool.get('account.tax').compute(cr, uid, [tax.id], line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, order.partner_invoice_id.id):
|
val+= cur_obj.round(cr, uid, cur, c['amount'])
|
||||||
val+= cur_obj.round(cr, uid, cur, c['amount'])
|
|
||||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -64,13 +64,14 @@ class sale_order_rebate(osv.osv):
|
||||||
|
|
||||||
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
||||||
res = {}
|
res = {}
|
||||||
|
cur_obj=self.pool.get('res.currency')
|
||||||
for order in self.browse(cr, uid, ids):
|
for order in self.browse(cr, uid, ids):
|
||||||
val = 0.0
|
val = 0.0
|
||||||
|
cur=order.pricelist_id.currency_id
|
||||||
for line in order.order_line:
|
for line in order.order_line:
|
||||||
for tax in line.tax_id:
|
for c in self.pool.get('account.tax').compute(cr, uid, line.tax_id, line.price_unit, line.product_uom_qty, order.partner_invoice_id.id):
|
||||||
for c in self.pool.get('account.tax').compute(cr, uid, [tax.id], line.price_unit, line.product_uom_qty, order.partner_invoice_id.id):
|
val += cur_obj.round(cr, uid, cur, (c['amount'] * (100.0 - order.rebate_percent) / 100.0))
|
||||||
val += c['amount'] * (100.0 - order.rebate_percent) / 100.0
|
res[order.id] = cur_obj.round(cr, uid, cur, val)
|
||||||
res[order.id] = val
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
|
|
@ -50,17 +50,18 @@ class sale_order(osv.osv):
|
||||||
|
|
||||||
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
||||||
res = {}
|
res = {}
|
||||||
|
cur_obj=self.pool.get('res.currency')
|
||||||
for order in self.browse(cr, uid, ids):
|
for order in self.browse(cr, uid, ids):
|
||||||
val = 0.0
|
val = 0.0
|
||||||
|
cur=order.pricelist_id.currency_id
|
||||||
for line in order.order_line:
|
for line in order.order_line:
|
||||||
for tax in line.tax_id:
|
if order.price_type=='tax_included':
|
||||||
if order.price_type=='tax_included':
|
ttt = self.pool.get('account.tax').compute_inv(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id)
|
||||||
ttt = self.pool.get('account.tax').compute_inv(cr, uid, [tax.id], line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id)
|
else:
|
||||||
else:
|
ttt = self.pool.get('account.tax').compute(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id)
|
||||||
ttt = self.pool.get('account.tax').compute(cr, uid, [tax.id], line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id)
|
for c in ttt:
|
||||||
for c in ttt:
|
val += cur_obj.round(cr, uid, cur, c['amount'])
|
||||||
val += round(c['amount'], 2)
|
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||||
res[order.id]=round(val,2)
|
|
||||||
return res
|
return res
|
||||||
_inherit = "sale.order"
|
_inherit = "sale.order"
|
||||||
_columns = {
|
_columns = {
|
||||||
|
|
Loading…
Reference in New Issue