Skip to Content
Menu
This question has been flagged
3 Replies
9841 Views

Odoo 12 CE - Ubuntu

All of a sudden, the scheduled action for the \contract module (Generate Recurring Invoices from Contracts) which calls: 

model.cron_recurring_create_invoice()

Is throwing the following error:

Error:
Odoo Server Error

Traceback (most recent call last):
  File "/opt/odoo12/odoo/odoo/tools/safe_eval.py", line 352, in safe_eval
    return unsafe_eval(c, globals_dict, locals_dict)
  File "", line 1, in <module>
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract.py", line 633, in cron_recurring_create_invoice
    invoices |= contracts_to_invoice._recurring_create_invoice(date_ref)
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract.py", line 618, in _recurring_create_invoice
    invoices_values = self._prepare_recurring_invoices_values(date_ref)
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract.py", line 587, in _prepare_recurring_invoices_values
    invoice_values=invoice_values,
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract_line.py", line 698, in _prepare_invoice_line
    name = self._insert_markers(dates[0], dates[1])
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract_line.py", line 747, in _insert_markers
    name = name.replace('#END#', last_date_invoiced.strftime(date_format))
AttributeError: 'bool' object has no attribute 'strftime'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/odoo12/odoo/odoo/http.py", line 656, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo12/odoo/odoo/http.py", line 314, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo12/odoo/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/opt/odoo12/odoo/odoo/http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo12/odoo/odoo/http.py", line 346, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo12/odoo/odoo/service/model.py", line 98, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo12/odoo/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo12/odoo/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo12/odoo/odoo/http.py", line 519, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo12/odoo/addons/web/controllers/main.py", line 967, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo12/odoo/addons/web/controllers/main.py", line 955, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo12/odoo/odoo/api.py", line 759, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo12/odoo/odoo/api.py", line 746, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/opt/odoo12/odoo/odoo/addons/base/models/ir_cron.py", line 83, in method_direct_trigger
    self.sudo(user=cron.user_id.id).ir_actions_server_id.run()
  File "/opt/odoo12/odoo/odoo/addons/base/models/ir_actions.py", line 543, in run
    res = func(action, eval_context=eval_context)
  File "/opt/odoo12/odoo/addons/website/models/ir_actions.py", line 57, in run_action_code_multi
    res = super(ServerAction, self).run_action_code_multi(action, eval_context)
  File "/opt/odoo12/odoo/odoo/addons/base/models/ir_actions.py", line 434, in run_action_code_multi
    safe_eval(action.sudo().code.strip(), eval_context, mode="exec", nocopy=True)  # nocopy allows to return 'action'
  File "/opt/odoo12/odoo/odoo/tools/safe_eval.py", line 375, in safe_eval
    pycompat.reraise(ValueError, ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)), exc_info[2])
  File "/opt/odoo12/odoo/odoo/tools/pycompat.py", line 86, in reraise
    raise value.with_traceback(tb)
  File "/opt/odoo12/odoo/odoo/tools/safe_eval.py", line 352, in safe_eval
    return unsafe_eval(c, globals_dict, locals_dict)
  File "", line 1, in <module>
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract.py", line 633, in cron_recurring_create_invoice
    invoices |= contracts_to_invoice._recurring_create_invoice(date_ref)
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract.py", line 618, in _recurring_create_invoice
    invoices_values = self._prepare_recurring_invoices_values(date_ref)
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract.py", line 587, in _prepare_recurring_invoices_values
    invoice_values=invoice_values,
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract_line.py", line 698, in _prepare_invoice_line
    name = self._insert_markers(dates[0], dates[1])
  File "/opt/odoo12/odoo-custom-addons/contract/models/contract_line.py", line 747, in _insert_markers
    name = name.replace('#END#', last_date_invoiced.strftime(date_format))
ValueError: <class 'AttributeError'>: "'bool' object has no attribute 'strftime'" while evaluating
'model.cron_recurring_create_invoice()'
Avatar
Discard

Hi there,

I am facing the exact same issue. Did you find a fix please ?


Thanks.

Sorry, I did not.

Best Answer

check it in contracts which contract line is having manual renewal needed, and also check if in any contract you missed marking the product in the product line. As both these conditions can lead to cron being not able to execute.

Avatar
Discard
Best Answer
Hi,
The error is because of the field last_date_invoiced has no value stored. The value in that field is False. And that's why we can't use any datetime functionality (here:- strftime()) in it.

Either you can solve the issue by providing a valid date in that field or use the below code

current_date = datetime.date.today()
last_date_invoiced = last_date_invoiced or current_date
name = name.replace('#END#', last_date_invoiced.strftime(date_format))
Or 
Simply set a validation condition before the statement ie,

if last_date_invoiced:
name = name.replace('#END#', last_date_invoiced.strftime(date_format)

Hope it helps

Avatar
Discard

It won't solve the error at all. I mean, for sure it will work in order to fix the AttributeError, but last_date_invoiced is a computed value, which is calculated many times in the code: _insert_markers(), _update_recurring_next_date() ...

So, due to that value will be False when calculated, it will throw a new error, given that this field is manipulated so many times.

I think it is a bug that OCA should take care of.

Related Posts Replies Views Activity
3
Sep 21
11342
0
Apr 24
960
3
Dec 22
13558
2
Jan 21
4514
2
Apr 20
71536