Hi,
I have two models connected via One2Many->Many2One relation. I create Model B from a tree-list in Model A.
Here is my code:
class dummy_workcenter(models.Model):
_inherit = 'mrp.workcenter'
machinetype = fields.Selection(string="Maschinenart", required=True, selection=[('a', 'Type A'), ('b', 'Type B')])
attributes = fields.One2many('dummy.workcenter.attribute', 'workcenter_id', string="Eigenschaften", required=True)
class dummy_workcenter_attribute(models.Model):
_name = 'dummy.workcenter.attribute'
name = fields.Char(string="Bezeichnung", required=True)
workcenter_id = fields.Many2one('mrp.workcenter', string="Maschine")
attributetype = fields.Char(compute='_attributetype')
attribute = fields.Selection(string="Type", selection='_attributeselection', required=True)
@api.depends('attributetype')
def _attributetype(self):
self.attributetype = self.workcenter_id.machinetype
def _attributeselection(self):
return [('1', 'Option 1'), ('2', 'Option 2')]
The computed Function "_attributetype" works fine, if model B is created and model A is saved.
But I want to have "attributetype" already in the "creation overlay" of model B.
So the question is, how can I use model A's values on model B's creation?!
(And if that works anyway, how can I use them if model A isn't saved already - in draft state!?!?!?)
... I hope I've explained it clear enough.