Hello,
Thanks for your quick answers but for the two solutions I have errors.
For Malay solution :
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/http.py", line 1578, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/home/odoo/src/odoo/odoo/service/model.py", line 134, in retrying
result = func()
File "/home/odoo/src/odoo/odoo/http.py", line 1607, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/home/odoo/src/odoo/odoo/http.py", line 1804, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 140, in _dispatch
result = endpoint(**request.params)
File "/home/odoo/src/odoo/odoo/http.py", line 698, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 42, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 459, in call_kw
result = _call_kw_model_create(method, model, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 439, in _call_kw_model_create
result = method(recs, *args, **kwargs)
File "", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 409, in _model_create_multi
return create(self, [arg])
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 915, in create
self.pool.init_models(self._cr, models, dict(self._context, update_custom_fields=True))
File "/home/odoo/src/odoo/odoo/modules/registry.py", line 465, in init_models
func()
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 1720, in _reflect_relation
self.env.invalidate_all()
File "/home/odoo/src/odoo/odoo/api.py", line 722, in invalidate_all
self.flush_all()
File "/home/odoo/src/odoo/odoo/api.py", line 732, in flush_all
self._recompute_all()
File "/home/odoo/src/odoo/odoo/api.py", line 728, in _recompute_all
self[field.model_name]._recompute_field(field)
File "/home/odoo/src/odoo/odoo/models.py", line 6155, in _recompute_field
field.recompute(records)
File "/home/odoo/src/odoo/odoo/fields.py", line 1324, in recompute
self.compute_value(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1346, in compute_value
records._compute_field_value(self)
File "/home/odoo/src/odoo/addons/sale/models/sale_order.py", line 1357, in _compute_field_value
return super()._compute_field_value(field)
File "/home/odoo/src/odoo/addons/mail/models/mail_thread.py", line 403, in _compute_field_value
return super()._compute_field_value(field)
File "/home/odoo/src/odoo/odoo/models.py", line 4190, in _compute_field_value
field.compute(self)
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 37, in
func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")
File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 337, in safe_eval
c = test_expr(expr, _SAFE_OPCODES, mode=mode, filename=filename)
File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 190, in test_expr
code_obj = compile(expr, filename or "", mode)
File "", line 4
rec.commitment_date_week_no = int(your Commitment Date.isocalendar()[1])
^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
For Abhishek soluton :
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/http.py", line 1578, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/home/odoo/src/odoo/odoo/service/model.py", line 134, in retrying
result = func()
File "/home/odoo/src/odoo/odoo/http.py", line 1607, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/home/odoo/src/odoo/odoo/http.py", line 1804, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 140, in _dispatch
result = endpoint(**request.params)
File "/home/odoo/src/odoo/odoo/http.py", line 698, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 42, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 459, in call_kw
result = _call_kw_model_create(method, model, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 439, in _call_kw_model_create
result = method(recs, *args, **kwargs)
File "", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 409, in _model_create_multi
return create(self, [arg])
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 915, in create
self.pool.init_models(self._cr, models, dict(self._context, update_custom_fields=True))
File "/home/odoo/src/odoo/odoo/modules/registry.py", line 465, in init_models
func()
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 1720, in _reflect_relation
self.env.invalidate_all()
File "/home/odoo/src/odoo/odoo/api.py", line 722, in invalidate_all
self.flush_all()
File "/home/odoo/src/odoo/odoo/api.py", line 732, in flush_all
self._recompute_all()
File "/home/odoo/src/odoo/odoo/api.py", line 728, in _recompute_all
self[field.model_name]._recompute_field(field)
File "/home/odoo/src/odoo/odoo/models.py", line 6155, in _recompute_field
field.recompute(records)
File "/home/odoo/src/odoo/odoo/fields.py", line 1324, in recompute
self.compute_value(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1346, in compute_value
records._compute_field_value(self)
File "/home/odoo/src/odoo/addons/sale/models/sale_order.py", line 1357, in _compute_field_value
return super()._compute_field_value(field)
File "/home/odoo/src/odoo/addons/mail/models/mail_thread.py", line 403, in _compute_field_value
return super()._compute_field_value(field)
File "/home/odoo/src/odoo/odoo/models.py", line 4190, in _compute_field_value
field.compute(self)
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 37, in
func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")
File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 337, in safe_eval
c = test_expr(expr, _SAFE_OPCODES, mode=mode, filename=filename)
File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 195, in test_expr
assert_valid_codeobj(allowed_codes, code_obj, expr)
File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 168, in assert_valid_codeobj
raise ValueError("forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in (code_codes - allowed_codes))))
ValueError: forbidden opcode(s) in 'import datetime\ndatetime.date(2010, 6, 16).isocalendar()[1]': IMPORT_NAME
Here is the solution :
for rec in self:
if rec.commitment_date:
rec['x_semaine'] = rec.commitment_date.isocalendar()[1]
else:
rec['x_semaine'] = 0