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
andMany2many
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)]