İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
2556 Görünümler

Hello, I cannot seem to create a mail.activity and evaluate for the user_id value. Please see my code below:

def _create_activity(self):
---"""Create an Odoo activity for the record on creation."""
---self.env['mail.activity'].create({
------'summary': 'Overall Equipment Efficiency',
------'user_id':self.env['res.users'].browse(self.env['ir.config_parameter'].sudo().get_param('oee.responsible_user')),'date_deadline': fields.Datetime.now() +relativedelta(months=1),
------'res_id': self.id,
------'res_model_id': self.env['ir.model']._get_id('oee.log'),
------'note': "Record machine hours from last month. Reference the previous month's record to see that starting hours for that month.",     
})


I am trying to gather the user_id from oee.responsible_user but it keeps giving me an error (Full Traceback)
ERROR: null value in column "user_id" of relation "mail_activity" violates not-null constraint
DETAIL: Failing row contains (15, 624, null, 0, null, null, Overall Equipment Efficiency,

Record machine hours from last month. Reference the previous ..., 2023-08-11, null, null, null, null, null, 2, 2023-07-11 17:52:38.94198, 2, 2023-07-11 17:52:38.94198).
2023-07-11 17:52:38,992 51 ERROR ******-odoo-sh-testing-8932533 odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/home/odoo/src/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/odoo/src/user/nxc_oee/models/oee.py", line 61, in _create_activity
self.env['mail.activity'].create({
File "", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 412, in _model_create_multi
return create(self, [arg])
File "/home/odoo/src/odoo/addons/mail/models/mail_activity.py", line 263, in create
activities = super(MailActivity, self).create(vals_list)
File "", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 413, in _model_create_multi
return create(self, arg)
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_fields.py", line 613, in create
recs = super().create(vals_list)
File "", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 413, in _model_create_multi
return create(self, arg)
File "/home/odoo/src/odoo/odoo/models.py", line 4081, in create
records = self._create(data_list)
File "/home/odoo/src/odoo/odoo/models.py", line 4179, in _create
cr.execute(query, params)
File "", line 2, in execute
File "/home/odoo/src/odoo/odoo/sql_db.py", line 90, in check
return f(self, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/sql_db.py", line 311, in execute
res = self._obj.execute(query, params)
psycopg2.errors.NotNullViolation: null value in column "user_id" of relation "mail_activity" violates not-null constraint
DETAIL: Failing row contains (15, 624, null, 0, null, null, Overall Equipment Efficiency,

Record machine hours from last month. Reference the previous ..., 2023-08-11, null, null, null, null, null, 2, 2023-07-11 17:52:38.94198, 2, 2023-07-11 17:52:38.94198).


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

Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/home/odoo/src/odoo/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/home/odoo/src/odoo/odoo/http.py", line 368, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/http.py", line 357, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 921, in __call__
return self.method(*args, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 546, in response_wrap
response = f(*args, **kw)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1324, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1316, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 462, in call_kw
result = _call_kw_model_create(method, model, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 442, in _call_kw_model_create
result = method(recs, *args, **kwargs)
File "", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 412, in _model_create_multi
return create(self, [arg])
File "/home/odoo/src/odoo/addons/base_automation/models/base_automation.py", line 324, in create
action._process(action._filter_post(records))
File "/home/odoo/src/odoo/addons/base_automation/models/base_automation.py", line 274, in _process
raise e
File "/home/odoo/src/odoo/addons/base_automation/models/base_automation.py", line 271, in _process
action_server.sudo().with_context(**ctx).run()
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions.py", line 643, in run
res = runner(run_self, eval_context=eval_context)
File "/home/odoo/src/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/odoo/src/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))
Exceptiond

:


The responsible_user field is many2one on the res.users model. Might anyone here know this can be resolved? Am I retrieving the value improperly?

Avatar
Vazgeç
Üretici

Neha Kakkar, thank you for the reply. I printed the value of the config parameter (oee.responsible_user) using the logger. It is showing a null value, even though the value has been set in the UI. When I leave odoo settings and come back the value I set is still stored. I am not quite sure why this is happening but I will post here when I find the solution.

En İyi Yanıt

The value for user_id seems to be None, which is causing the error.
Check the value of oee.responsible_user.  The value returned by self.env['ir.config_parameter'].sudo().get_param('oee.responsible_user') is a valid user ID.
You can print the value to check its correctness.

Avatar
Vazgeç

Thank you for providing the additional information. If the oee.responsible_user configuration parameter is showing a null value despite being set in the UI and saved, it suggestsThat there might be an issue with the retrieval of the configuration parameter.

Check the code where the oee.responsible_user configuration parameter is set.
Might be typos or inconsistencies in the code that might be causing this issue.

Also Check if there are any other parts of your codebase that might be modifying or overriding the oee.responsible_user configuration parameter. Look for any customizations or other modules that might affect its value.
Verify if there are any access restrictions or permissions in place that could prevent the retrieval of the configuration parameter.
One more Important things that you can do restarting the Odoo server or refreshing the environment to ensure that the latest changes are reflected in the system. Sometimes, changes made in the UI might require a server restart to take effect.

Please keep us updated on any progress or findings you come across,

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 24
1687
0
Şub 22
1289
13
Mar 16
5204
1
Eyl 15
5889
0
Ağu 24
1309