odoo/odoo#162096

Created by fw-bot
Merged at 24e65c2fe904e9a2a4e5004dc0e7ada220d1dacc

Statuses:

label
odoo-dev:16.0-15.0-sentry-5001664034-l10n-id-efaktur-typeerror-mega-LD46-fw
head
5b5c4258352afaec4bb609823b21cb82b739f58d
merged
2 years ago by Accounting, William André (wan)
odoo/odoo
15.0 #155196
16.0 #162096
saas-16.3 #162746
saas-16.4 #162747
17.0 #162749
saas-17.1 #162751
saas-17.2 #162753
18.0
saas-18.2
saas-18.3
saas-18.4
19.0
saas-19.1
saas-19.2
saas-19.3
master #162754

[FW][FIX] l10n_id_efaktur: prevent error when download e-Faktur without tax number

Currently, the error arises when downloading e-Faktur without a 'Tax Number'.

Steps to reproduce:

Stack Trace :

TypeError: 'bool' object is not subscriptable
  File "odoo/tools/safe_eval.py", line 365, in safe_eval
    return unsafe_eval(c, globals_dict, locals_dict)
  File "ir.actions.server(801,)", line 1, in <module>
  File "addons/l10n_id_efaktur/models/account_move.py", line 143, in download_efaktur
    self._generate_efaktur(',')
  File "addons/l10n_id_efaktur/models/account_move.py", line 338, in _generate_efaktur
    output_head = self._generate_efaktur_invoice(delimiter)
  File "addons/l10n_id_efaktur/models/account_move.py", line 178, in _generate_efaktur_invoice
    eTax['KD_JENIS_TRANSAKSI'] = move.l10n_id_tax_number[0:2] or 0
ValueError: <class 'TypeError'>: "'bool' object is not subscriptable" while evaluating
'action = records.download_efaktur()'
  File "odoo/http.py", line 2251, in __call__
    response = request._serve_db()
  File "odoo/http.py", line 1826, in _serve_db
    return self._transactioning(_serve_ir_http, readonly=ro)
  File "odoo/http.py", line 1847, in _transactioning
    return service_model.retrying(func, env=self.env)
  File "odoo/service/model.py", line 134, in retrying
    result = func()
  File "odoo/http.py", line 1824, in _serve_ir_http
    return self._serve_ir_http(rule, args)
  File "odoo/http.py", line 1832, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "odoo/http.py", line 2057, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "odoo/addons/base/models/ir_http.py", line 222, in _dispatch
    result = endpoint(**request.params)
  File "odoo/http.py", line 740, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "addons/web/controllers/action.py", line 46, in run
    result = action.run()
  File "home/odoo/src/custom/trial/saas_trial/models/sentry.py", line 33, in run
    res = super().run()
  File "odoo/addons/base/models/ir_actions.py", line 938, in run
    res = runner(run_self, eval_context=eval_context)
  File "addons/website/models/ir_actions_server.py", line 61, in _run_action_code_multi
    res = super(ServerAction, self)._run_action_code_multi(eval_context)
  File "odoo/addons/base/models/ir_actions.py", line 770, in _run_action_code_multi
    safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True, filename=str(self))  # nocopy allows to return 'action'
  File "odoo/tools/safe_eval.py", line 379, in safe_eval
    raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))

When downloading e-Faktur, There's an issue at [1], Where the system tries to access elements of 'l10n_id_tax_number', but 'Tax Number' is empty, So 'l10n_id_tax_number' is considered as a 'False'.

[1] : https://github.com/odoo/odoo/blob/9c4194ad3387c55d39ec7bbef1c6414893098c6e/addons/l10n_id_efaktur/models/account_move.py#L168-L170

This commit fixes the above issue by adding a condition to ensure that the system only accesses an 'l10n_id_tax_number' if it is available.

sentry-5001664034


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

Forward-Port-Of: #155196