İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
1317 Görünümler

i have  categorized products as meals and ingredients using 2 boolean fields(is_meal and is_ingredient). In my product.template, there is a child model for entering ingredients of the meals. when product entered in the child model, i want to pass this product to ingredients product 

@api.model

defcreate(self,vals):

ifvals['ingredients_id']:

self.ingredients_id.is_ingredient =True

returnsuper().create(vals)



Avatar
Vazgeç
En İyi Yanıt

Hi,

Better option is to make the is_ingredient field as a compute stored field. You can add the compute logic as follows, if there is atleast one child, then set is_ingredient as True.

Suppose if the child_ids is the o2m field then you can define the compute function as follows:

is_ingredient = fields.Boolean(string="Is Ingredient", compute='_compute_is_ingredient', store=True)

@api.depends('child_ids')
def _compute_is_ingredient(self):
for rec in self:
is_ingredient = False
if
rec.child_ids:
is_ingredient = True
rec.is_ingredient = is_ingredient


Thanks

Avatar
Vazgeç