you want to make a custom calculation with the price, according to conditions you must multiply by a factor. Example: if it is tax 10, then you must multiply the price by 0.847
if it is tax 2, it must be multiplied by the predetermined factor.
then with the new values, the tax calculation is performed normally.
What is happening to me with the code, is that it does not respect the tax code (filter: if line_tax.tipo_afectacion_igv.code in ["10"]: ), if it enters the conditions it is the value for all the calculations of the tax. Each calculation should be differentiated for each tax.
when it enters the condition of tax 10, it takes the value of 0.847 and uses it to calculate all the taxes, without respecting the condition : price_unit* factorTAX if line_tax.tipo_afectacion_igv.code in ["10"] else price_unit*FactorDEFAULT
code:
@api.multi
def get_taxes_values(self):#para calcular el valor de los impuestos.
tax_grouped = {}
for line in self.invoice_line_ids:
if len(line.invoice_line_tax_ids)>0:
for line_tax in line.invoice_line_tax_ids:
if line_tax.tipo_afectacion_igv.code in ["10"]:
price_unit = line.price_unit
taxes=line.invoice_line_tax_ids.compute_all(price_unit* factorTAX if line_tax.tipo_afectacion_igv.code in ["10"] else price_unit*FactorDEFAULT, self.currency_id, line.quantity, line.product_id, self.partner_id)['taxes']
for tax in taxes:
val = self._prepare_tax_line_vals(line, tax)
key = self.env['account.tax'].browse(tax['id']).get_grouping_key(val)
if key not in tax_grouped:
tax_grouped[key] = val
else:
tax_grouped[key]['amount'] += val['amount']
tax_grouped[key]['base'] += val['base']
return tax_grouped
invoice detail |
|||||
quantity |
price |
subtotal |
factor according to tax |
default factor |
tax |
1 |
2370 |
2370 |
0.847 |
1 |
tax 10 (27,8%) |
tax2 (18%) |
|||||
tax 10 |
(price*factor)*tax10%(2370*0.847)*27.8% |
||||
tax 2 |
(price*factorDefault+tax10value)*tax2%||((2370*1)+valuetax10)*18% |
I do still not understand, what you want to achieve and why you need to code and can not use Odoo's default possibilities to define taxes.
Hello,
it concludes:
for an invoice that has only one item, but 2 selected taxes.
The price for the calculation should change like this:
if the tax is tax10
price * factor
2370 * 0.847
if the tax is tax2
price * factordefault
2370 * 1
keep in mind that it is the same article, and the same line.
With the default configuration you can not do that, depending on what you check.