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

i'm just trying to add log at bottom using mail.tread & mail.activity.mixxing
and this error pop ups

Error:

Odoo Server Error


Traceback (most recent call last):

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch

    result = request.dispatch()

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/http.py", line 696, in dispatch

    result = self._call_function(**self.params)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/http.py", line 370, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/service/model.py", line 94, in wrapper

    return f(dbname, *args, **kwargs)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/http.py", line 358, in checked_call

    result = self.endpoint(*a, **kw)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/http.py", line 919, in __call__

    return self.method(*args, **kw)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/http.py", line 544, in response_wrap

    response = f(*args, **kw)

  File "/Users/lyon/Desktop/Lyon/odoo/addons/web/controllers/main.py", line 1370, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "/Users/lyon/Desktop/Lyon/odoo/addons/web/controllers/main.py", line 1362, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/api.py", line 399, in call_kw

    result = _call_kw_multi(method, model, args, kwargs)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/api.py", line 386, in _call_kw_multi

    result = method(recs, *args, **kwargs)

  File "/Users/lyon/Desktop/Lyon/addons/nti_odoo_gen/nti_dynamic_restrict_gen/models/base.py", line 9, in read

    result = super(BaseModelExtend, self).read(fields, load=load)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/models.py", line 3023, in read

    return self._read_format(fnames=fields, load=load)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/models.py", line 3043, in _read_format

    vals[name] = convert(record[name], record, use_name_get)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/models.py", line 5699, in __getitem__

    return self._fields[key].__get__(self, type(self))

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 1042, in __get__

    self.compute_value(recs)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 1198, in compute_value

    records._compute_field_value(self)

  File "/Users/lyon/Desktop/Lyon/odoo/addons/mail/models/mail_thread.py", line 410, in _compute_field_value

    return super()._compute_field_value(field)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/models.py", line 4076, in _compute_field_value

    odoo.fields.determine(field.compute, self)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 85, in determine

    return needle(records, *args)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 562, in _compute_related

    values = [first(value[name]) for value in values]

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 562, in

    values = [first(value[name]) for value in values]

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/models.py", line 5699, in __getitem__

    return self._fields[key].__get__(self, type(self))

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 2495, in __get__

    return super().__get__(records, owner)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 1042, in __get__

    self.compute_value(recs)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 1198, in compute_value

    records._compute_field_value(self)

  File "/Users/lyon/Desktop/Lyon/odoo/addons/mail/models/mail_thread.py", line 410, in _compute_field_value

    return super()._compute_field_value(field)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/models.py", line 4076, in _compute_field_value

    odoo.fields.determine(field.compute, self)

  File "/Users/lyon/Deasktop/Lyon/odoo/odoo/fields.py", line 85, in determine

    return needle(records, *args)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 574, in _compute_related

    record[self.name] = self._process_related(value[self.related_field.name])

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/models.py", line 5708, in __setitem__

    return self._fields[key].__set__(self, value)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 1130, in __set__

    self.write(protected_records, value)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 2734, in write

    cache_value = self.convert_to_cache(value, records)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/fields.py", line 2659, in convert_to_cache

    raise ValueError("Wrong value for %s: %r" % (self, value))

Exception


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


Traceback (most recent call last):

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/http.py", line 652, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/Users/lyon/Desktop/Lyon/odoo/odoo/http.py", line 317, in _handle_exception

    raise exception.with_traceback(None) from new_cause

ValueError: Wrong value for hr.plan.activity.activity_type_id: mail.activity.type()



The Code

from odoo import _, api, fields, models

class HrPlanActivity(models.Model):
    _name = 'hr.plan.activity'
    _description = 'Hr Plan Activity'
    _inherit = ['mail.thread', 'mail.activity.mixin']
    
    name = fields.Char('Name',tracking=True)
    employee_id = fields.Many2one('hr.employee', string='Employee')
    activity_type_id = fields.Many2one('hr.plan.activity.type', string='Activity',tracking=True)
    plan_id = fields.Many2one('hr.plan', string='Plan')
    description = fields.Html('Description',related='activity_type_id.note')
    job_id = fields.Many2one('hr.job', string='Job Position',related='employee_id.job_id')
    date = fields.Date('Date')
    is_approval = fields.Boolean('Is Approval',compute='compute_is_approval')
    state = fields.Selection([
        ('draft', 'Draft'),
        ('done', 'Done')
    ], string='Status', default='draft')
    line_ids = fields.One2many('hr.plan.activity.line', 'activity_id', string='line')
    note = fields.Text('Note')
    def compute_is_approval(self):
        for record in self:
            activity_type = record.activity_type_id
            employee = record.employee_id
            user = self.env.user.employee_id
            responsible = activity_type.responsible
            
            if responsible == 'manager':
                if employee.parent_id.id and user.id == employee.parent_id.id:
                    record.is_approval = True
                else:
                    record.is_approval = False
            elif responsible == 'employee':
                if employee.id == user.id:
                    record.is_approval = True
                else:
                    record.is_approval = False
            elif responsible == 'other':
                if user.id == activity_type.responsible_id.id:
                    record.is_approval = True
                else:
                    record.is_approval = False
            else:
                record.is_approval = False

    def button_done(self):
        self.state = 'done'

    def button_revision(self):
        self.state = 'draft'
        
    @api.model
    def create(self, vals):
        vals['name'] = self.env['ir.sequence'].next_by_code('hr.plan.activity')
        return super(HrPlanActivity, self).create(vals)

Avatar
Discard
Best Answer

Hi,

According to the given code, it appears that the problem is with the definition of the description field and how it relates to the activity_type_id. The updated code is as follows:

from odoo import _, api, fields, models

class HrPlanActivity(models.Model):
_name = 'hr.plan.activity'
_description = 'Hr Plan Activity'
_inherit = ['mail.thread', 'mail.activity.mixin']
 
name = fields.Char('Name', tracking=True)
employee_id = fields.Many2one('hr.employee', string='Employee')
activity_type_id = fields.Many2one('hr.plan.activity.type', string='Activity', tracking=True)
plan_id = fields.Many2one('hr.plan', string='Plan')
description = fields.Html('Description', compute='_compute_description')
job_id = fields.Many2one('hr.job', string='Job Position', related='employee_id.job_id')
date = fields.Date('Date')
is_approval = fields.Boolean('Is Approval', compute='compute_is_approval')
state = fields.Selection([
('draft', 'Draft'),
('done', 'Done')
], string='Status', default='draft')
line_ids = fields.One2many('hr.plan.activity.line', 'activity_id', string='Line')
note = fields.Text('Note')
 
def compute_is_approval(self):
for record in self:
activity_type = record.activity_type_id
employee = record.employee_id
user = self.env.user.employee_id
responsible = activity_type.responsible
 
if responsible == 'manager':
if employee.parent_id.id and user.id == employee.parent_id.id:
record.is_approval = True
else:
record.is_approval = False
elif responsible == 'employee':
if employee.id == user.id:
record.is_approval = True
else:
record.is_approval = False
elif responsible == 'other':
if user.id == activity_type.responsible_id.id:
record.is_approval = True
else:
record.is_approval = False
else:
record.is_approval = False

def button_done(self):
self.state = 'done'

def button_revision(self):
self.state = 'draft'
 
@api.depends('activity_type_id')
def _compute_description(self):
for record in self:
record.description = record.activity_type_id.note
if record.activity_type_id
else False

@api.model
def create(self, vals):
vals['name'] = self.env['ir.sequence'].next_by_code('hr.plan.activity')
return super(HrPlanActivity, self).create(vals)

Regards

Avatar
Discard
Author Best Answer

The problem is not from the compute, but the error from the field:o2m activity_type_id, because when I inherit mail.thread, it sends an error wrong value. But when I do not inherit to mail, it's all fine..

Avatar
Discard

Can you change the field name of Many2one in relation 'hr.plan.activity.type'. Inside the mail.activity already a field exists with same name .Change the field name as follows,
plan_activity_type_id = fields.Many2one('hr.plan.activity.type', string='Activity',tracking=True)

Best Answer

Hi 

Update this other responsible condition as follows

elif responsible == 'other':

                if user.user_id.id == activity_type.responsible_id.id:

​record.is_approval = True


Hope this Helps

Regards

                   

Avatar
Discard
Related Posts Replies Views Activity
4
Jun 25
1937
1
Jun 25
790
0
Feb 25
879
1
Nov 24
1690
1
Nov 24
985