OCA/contract

[15.0] Generating recurrent invoices end in error

Closed this issue · 5 comments

Module

contract

Describe the bug

I enter a contract with two lines, one for a service product, the other for a physical product. It is defined as pre-invoiced, and recurrence on the contract NOT at the line level, for a yearly occurence. Then generating invoices (through the Run Manualy button on the cron) gets an exception

Expected behavior
I would expect an invoice to be generated

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
File "/home/odocaltst15/odoo/parts/odoo/odoo/tools/safe_eval.py", line 332, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 1, in
File "/home/odocaltst15/odoo/parts/contract/contract/models/contract.py", line 617, in cron_recurring_create_invoice
invoices |= contracts_to_invoice._recurring_create_invoice(date_ref)
File "/home/odocaltst15/odoo/parts/contract/contract/models/contract.py", line 595, in _recurring_create_invoice
invoices_values = self._prepare_recurring_invoices_values(date_ref)
File "/home/odocaltst15/odoo/parts/contract/contract/models/contract.py", line 544, in _prepare_recurring_invoices_values
invoice_line_vals = line._prepare_invoice_line(move_form=move_form)
File "/home/odocaltst15/odoo/parts/contract/contract/models/contract_line.py", line 554, in _prepare_invoice_line
name = self._insert_markers(dates[0], dates[1])
File "/home/odocaltst15/odoo/parts/contract/contract/models/contract_line.py", line 604, in _insert_markers
name = name.replace("#END#", last_date_invoiced.strftime(date_format))
AttributeError: 'bool' object has no attribute 'strftime'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odocaltst15/odoo/parts/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/home/odocaltst15/odoo/parts/odoo/odoo/http.py", line 687, in dispatch
result = self._call_function(**self.params)
File "/home/odocaltst15/odoo/parts/odoo/odoo/http.py", line 359, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odocaltst15/odoo/parts/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odocaltst15/odoo/parts/odoo/odoo/http.py", line 348, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odocaltst15/odoo/parts/odoo/odoo/http.py", line 916, in call
return self.method(*args, **kw)
File "/home/odocaltst15/odoo/parts/odoo/odoo/http.py", line 535, in response_wrap
response = f(*args, **kw)
File "/home/odocaltst15/odoo/parts/odoo/addons/web/controllers/main.py", line 1351, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/home/odocaltst15/odoo/parts/odoo/addons/web/controllers/main.py", line 1339, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odocaltst15/odoo/parts/odoo/odoo/api.py", line 464, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/odocaltst15/odoo/parts/odoo/odoo/api.py", line 451, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/odocaltst15/odoo/parts/odoo/odoo/addons/base/models/ir_cron.py", line 85, in method_direct_trigger
cron.with_user(cron.user_id).with_context(lastcall=cron.lastcall).ir_actions_server_id.run()
File "/home/odocaltst15/odoo/parts/odoo/odoo/addons/base/models/ir_actions.py", line 643, in run
res = runner(run_self, eval_context=eval_context)
File "/home/odocaltst15/odoo/parts/odoo/addons/website/models/ir_actions.py", line 61, in _run_action_code_multi
res = super(ServerAction, self)._run_action_code_multi(eval_context)
File "/home/odocaltst15/odoo/parts/odoo/odoo/addons/base/models/ir_actions.py", line 512, in _run_action_code_multi
safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action'
File "/home/odocaltst15/odoo/parts/odoo/odoo/tools/safe_eval.py", line 348, in safe_eval
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odocaltst15/odoo/parts/odoo/odoo/http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odocaltst15/odoo/parts/odoo/odoo/http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: <class 'AttributeError'>: "'bool' object has no attribute 'strftime'" while evaluating
'model.cron_recurring_create_invoice()'

I noticed the "'bool' object has no attribute 'strftime'" in last_date_invoiced.strftime(date_format)). Now obviously last_date_invoiced is False if you have not send any invoice before. But how to get past that if you cannot generate your first invoice?

The exact same problem is happening on 14.0 also.

I'm facing the same problem with the latest 14.0 version, even though the last_date_invoiced field doesn't seem empty:
image
Also, the date is in 2023 and it might be because the module often creates invoices in the future, for some reason. It could be from a different bug.

This is fixed in #853 (for v13, but it's applicable the same for 14 and 15)

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.