Skip to Content
Menu
This question has been flagged
1 Reply
6198 Views

Hi,

I need to calculate a m2o field. Here's what I have:

class ProjectTask(models.Model):
    _inherit = "project.task"

    other_model = fields.One2many(comodel_name='other_model', inverse_name='task_id')
    upcoming_date = fields.Datetime(compute='_compute_next_other_model')
    subcontract = fields.Many2one(compute='_compute_next_other_model')
    @api.depends('other_model.__last_update', 'other_model.state')
    def _compute_next_other_model(self):
        for rec in self:
            others = self.env['other_model'].search(
                [('task_id', '=', [rec.id]), ('state','=', 'open')],
                order='date asc',
                limit=1)
            rec.upcoming_date = others.date
            if others.subcontract:
                rec.subcontract = others.subcontract.id
            else:
                rec.subcontract = []


but I can't understand why I get  the field "subcontract"'s value as:

_unknown,49

or if I use the in the above code the name in place of the id:

rec.subcontract = others.subcontract.name

then I get as value:

_unknown,John Doe

- Where does that "_unknown" comes from? 

The model "other_model" doesn't seems to be recognized

In the documentation (https://www.odoo.com/documentation/13.0/reference/orm.html) there is 

One2many and Many2many use a special “commands” format to manipulate the set of records stored in/associated with the field.
This format is a list of triplets executed sequentially, where each triplet is a command to execute on the set of records. Not all commands apply in all situations. Possible commands are:

Made me try without success:

                rec.trial_subcontract = [(1, [trials.trial_subcontract.id], 0)]
TIA.



Avatar
Discard
Author Best Answer

It seem my problem is related to :

https://github.com/odoo/odoo/issues/2693


My solution for now is to replaced the field 'subcontract' by a Char :

subcontract = fields.Char(compute='_compute_next_other_model')

and update the name:

rec.subcontract = others.subcontract.name



Avatar
Discard
Related Posts Replies Views Activity
0
Aug 19
2488
1
Dec 15
5134
1
Mar 15
6923
1
Feb 23
1376
0
May 21
2091