Add product in tax compute python code
bzr revid: ced-b285ec0a8e14045421fb6e1f704be508bfe4af2e
This commit is contained in:
parent
bee476d5f9
commit
44d01beae7
|
@ -829,7 +829,7 @@ class account_tax(osv.osv):
|
|||
'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 = {
|
||||
'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# product : product.product object or False\n\nresult = price_unit * 0.10''',
|
||||
'applicable_type': lambda *a: 'true',
|
||||
'type': lambda *a: 'percent',
|
||||
'amount': lambda *a: 0.196,
|
||||
|
@ -844,11 +844,11 @@ class account_tax(osv.osv):
|
|||
}
|
||||
_order = 'sequence'
|
||||
|
||||
def _applicable(self, cr, uid, taxes, price_unit, address_id=None):
|
||||
def _applicable(self, cr, uid, taxes, price_unit, address_id=None, product=None):
|
||||
res = []
|
||||
for tax in taxes:
|
||||
if tax.applicable_type=='code':
|
||||
localdict = {'price_unit':price_unit, 'address':self.pool.get('res.partner.address').browse(cr, uid, address_id)}
|
||||
localdict = {'price_unit':price_unit, 'address':self.pool.get('res.partner.address').browse(cr, uid, address_id), 'product':product,}
|
||||
exec tax.python_applicable in localdict
|
||||
if localdict.get('result', False):
|
||||
res.append(tax)
|
||||
|
@ -856,8 +856,8 @@ class account_tax(osv.osv):
|
|||
res.append(tax)
|
||||
return res
|
||||
|
||||
def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None):
|
||||
taxes = self._applicable(cr, uid, taxes, price_unit, address_id)
|
||||
def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None, product=None):
|
||||
taxes = self._applicable(cr, uid, taxes, price_unit, address_id, product)
|
||||
|
||||
res = []
|
||||
cur_price_unit=price_unit
|
||||
|
@ -870,7 +870,7 @@ class account_tax(osv.osv):
|
|||
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':
|
||||
address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
|
||||
localdict = {'price_unit':cur_price_unit, 'address':address}
|
||||
localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product,}
|
||||
exec tax.python_compute in localdict
|
||||
amount = localdict['result']
|
||||
res.append({
|
||||
|
@ -901,7 +901,7 @@ class account_tax(osv.osv):
|
|||
cur_price_unit+=amount2
|
||||
return res
|
||||
|
||||
def compute(self, cr, uid, taxes, price_unit, quantity, address_id=None):
|
||||
def compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None):
|
||||
"""
|
||||
Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
|
||||
|
||||
|
@ -910,7 +910,7 @@ class account_tax(osv.osv):
|
|||
tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
|
||||
one tax for each tax id in IDS and their childs
|
||||
"""
|
||||
res = self._unit_compute(cr, uid, taxes, price_unit, address_id)
|
||||
res = self._unit_compute(cr, uid, taxes, price_unit, address_id, product)
|
||||
for r in res:
|
||||
r['amount'] *= quantity
|
||||
return res
|
||||
|
|
|
@ -581,7 +581,7 @@ class account_invoice_line(osv.osv):
|
|||
'price':round(line.quantity*line.price_unit * (1.0- (line.discount or 0.0)/100.0),2),
|
||||
'account_id':line.account_id.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, line.invoice_line_tax_id, (line.price_unit *(1.0-(line['discount'] or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id):
|
||||
tax['amount'] = cur_obj.round(cr, uid, cur, tax['amount'])
|
||||
tax['sequence'] = tax['sequence']
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ class account_tax(osv.osv):
|
|||
'python_compute_inv':fields.text('Python Code (VAT Incl)'),
|
||||
}
|
||||
_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# product : product.product object or False\n\nresult = price_unit * 0.10''',
|
||||
}
|
||||
def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None):
|
||||
def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None, product=None):
|
||||
taxes = self._applicable(cr, uid, taxes, price_unit, address_id)
|
||||
|
||||
res = []
|
||||
|
@ -55,7 +55,7 @@ class account_tax(osv.osv):
|
|||
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':
|
||||
address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
|
||||
localdict = {'price_unit':cur_price_unit, 'address':address}
|
||||
localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product,}
|
||||
exec tax.python_compute_inv in localdict
|
||||
amount = localdict['result']
|
||||
res.append({
|
||||
|
@ -86,7 +86,7 @@ class account_tax(osv.osv):
|
|||
taxes.reverse()
|
||||
return res
|
||||
|
||||
def compute_inv(self, cr, uid, taxes, price_unit, quantity, address_id=None):
|
||||
def compute_inv(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None):
|
||||
"""
|
||||
Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID.
|
||||
Price Unit is a VAT included price
|
||||
|
@ -96,7 +96,7 @@ class account_tax(osv.osv):
|
|||
tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2}
|
||||
one tax for each tax id in IDS and their childs
|
||||
"""
|
||||
res = self._unit_compute_inv(cr, uid, taxes, price_unit, address_id)
|
||||
res = self._unit_compute_inv(cr, uid, taxes, price_unit, address_id, product)
|
||||
for r in res:
|
||||
r['amount'] *= quantity
|
||||
return res
|
||||
|
|
|
@ -102,7 +102,7 @@ class account_invoice_line(osv.osv):
|
|||
'account_id':line.account_id.id,
|
||||
'tax_amount': 0.0
|
||||
})
|
||||
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, line.invoice_line_tax_id, (line.price_unit *(1.0-(line['discount'] or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id):
|
||||
tax['amount'] = cur_obj.round(cr, uid, cur, tax['amount'])
|
||||
tax['sequence'] = tax['sequence']
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class purchase_order(osv.osv):
|
|||
val = 0.0
|
||||
cur=order.pricelist_id.currency_id
|
||||
for line in order.order_line:
|
||||
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, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id):
|
||||
val+= cur_obj.round(cr, uid, cur, c['amount'])
|
||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||
return res
|
||||
|
|
|
@ -56,9 +56,9 @@ class purchase_order(osv.osv):
|
|||
cur=order.pricelist_id.currency_id
|
||||
for line in order.order_line:
|
||||
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, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id)
|
||||
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, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id)
|
||||
for c in ttt:
|
||||
val += cur_obj.round(cr, uid, cur, c['amount'])
|
||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||
|
|
|
@ -85,7 +85,7 @@ class sale_order(osv.osv):
|
|||
val = 0.0
|
||||
cur=order.pricelist_id.currency_id
|
||||
for line in order.order_line:
|
||||
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, line.tax_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, order.partner_invoice_id.id, line.product_id):
|
||||
val+= cur_obj.round(cr, uid, cur, c['amount'])
|
||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||
return res
|
||||
|
|
|
@ -56,9 +56,9 @@ class sale_order(osv.osv):
|
|||
cur=order.pricelist_id.currency_id
|
||||
for line in order.order_line:
|
||||
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, line.tax_id, line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id, line.product_id)
|
||||
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, line.tax_id, line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id, line.product_id)
|
||||
for c in ttt:
|
||||
val += cur_obj.round(cr, uid, cur, c['amount'])
|
||||
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||
|
|
Loading…
Reference in New Issue