Skip to Content
Menu
This question has been flagged
1 Reply
1865 Views

I have an invoice where the line of the invoice can have two taxes.
I want a calculation to be made when selecting a specific tax.
the code is correct if the first tax is the value of the filter (if line_tax.tipo_afectacion_igv.code in ["10"]:)
if I put it in second place it gives me the following error.
the line of the error is: (self.tax_line_ids[indextax].amount_total=self.amount_tax)
do not find the error, try changing the location of the index to the next for also.

code:

for line in self.invoice_line_ids:
for indextax,line2 in enumerate(line.invoice_line_tax_ids):
for line_tax in line2:
if line_tax.tipo_afectacion_igv.code in ["10"]:
self.amount_tax += round_curr((line.price_subtotal+line.calculo_isc_items)*line_tax.amount/100*(1-self.descuento_global/100))
os.system("echo Indice: '{}'".format(indextax))
self.tax_line_ids[indextax].amount_total=self.amount_tax

error: (IndexError: tuple index out of range)

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 940, in __get__
value = record.env.cache.get(record, self)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 967, in get
value = self._data[key][field][record._ids[0]]
KeyError:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/http.py", line 651, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 310, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/usr/lib/python3/dist-packages/odoo/http.py", line 693, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 342, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 335, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 937, in __call__
return self.method(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 934, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 926, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5198, in onchange
snapshot1 = Snapshot(record, nametree)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5105, in __init__
if subnames else record[name]
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4785, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 946, in __get__
self.determine_draft_value(record)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1066, in determine_draft_value
self._compute_value(record)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1002, in _compute_value
getattr(records, self.compute)()
File "", line 2, in _compute_amount
File "/usr/lib/python3/dist-packages/odoo/api.py", line 369, in loop
result = [method(rec, *args, **kwargs) for rec in self]
File "/usr/lib/python3/dist-packages/odoo/api.py", line 369, in
result = [method(rec, *args, **kwargs) for rec in self]
File "/mnt/extra-addons/efact/models/account/account_invoice.py", line 363, in _compute_amount
self.tax_line_ids[indextax].amount_total=self.amount_tax
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4789, in __getitem__
return self._browse((self._ids[key],), self.env)
IndexError: tuple index out of range

Avatar
Discard
Best Answer

Hi, You are using `line.invoice_line_tax_ids`'s index on `self.tax_line_ids` they are basically too different fields and even if it worked without error, the result was unpredictable. 

And I suggest using tax hierarchy in accounting module instead of writing it in code.

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 24
267
1
Oct 24
335
4
Oct 24
325
2
Oct 24
362
2
Dec 24
670