Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
7678 มุมมอง

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.



อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ส.ค. 19
3438
1
ธ.ค. 15
6128
1
มี.ค. 15
7983
1
ก.พ. 23
2439
0
พ.ค. 21
2849