Hi, i want to calculate custom tax on the account module. By default tax is being calculated by quantity * unit price but i want it to calculate tax on the custom field. like retail_price * quantity. By default it is: -
@ api.model
def _get_price_total_and_subtotal_model ( self , price_unit , quantity , discount , currency , product , partner , taxes , move_type): res = {} # Compute 'price_subtotal'. price_unit_wo_discount = price_unit * ( 1 - (discount / 100.0 )) subtotal = quantity * price_unit_wo_discount # Compute 'price_total'. if taxes: taxes_res = taxes._origin.compute_all (price_unit_wo_discount , quantity
= quantity , currency = currency ,
= product , partner = partner , is_refund = move_type in ( 'out_refund' , 'in_refund' ))
res [ 'price_subtotal' ] = taxes_res [ 'total_excluded' ]
res [ 'price_total' ] = taxes_res [ 'total_included' ]
else :
res [ 'price_total' ] = res [ 'price_subtotal' ] = subtotal
#In case of multi currency, round before it's use for computing debit credit
if currency: res = {k: currency.round (v)for k
, V in res.items ()}
return res
And i'm doing it like this but it is being called recursively and when tax_amount is zero it makes the tax = 0.
res = {}
# Compute 'price_subtotal'.
price_unit_wo_discount = price_unit * (1 - (discount / 100.0))
#subtotal =quantity * price_unit_wo_discount
# FOr now make
subtotal = self.rtl_ex_fed * 1 * (tax_amount / 100)
#Compute 'price_total'.
if taxes:
taxes_res = taxes._origin.compute_all(price_unit_wo_discount,
quantity=quantity, currency=currency, product=product, partner=partner, is_refund=move_type in ('out_refund', 'in_refund'))
res['price_subtotal'] = taxes_res['total_excluded']
res['price_total'] = taxes_res['total_included']
else:
res['price_total'] = res['price_subtotal'] = subtotal
#In case of multi currency, round before it's use for computing debit credit
if currency:
res = {k: currency.round(v) for k, v in res.items()}
return res
Can somebody guide me how to calculate it on the custom field?