Skip to Content
Menu
This question has been flagged
908 Views

Good Morning Odoo Developers,I'm blocked since one week in this Bug.I create a model contain a many2many field 'categ_ids' with product.categorie and another many2many field 'product_ids' with product.product.in order to fill the field product_ids , i create an onchange function depend on categ_ids in order to get products which have the selected categ but when i save the record i get an error :


The operation cannot be completed:

 - Create/update: a mandatory field is not set.

 - Delete: another model requires the record being deleted. If possible, archive it instead. Model: Product (product.product), Field: Product Template (product_tmpl_id)


this is my code :


class InsuranceOfferChapitre(models.Model):
     _name = 'insurance.offer.chapitre'
     ###########/
     categ_ids = fields.Many2many('product.category', string='Catégories')
    product_ids = fields.Many2many('product.product', string='Produits')
    @api.onchange('categ_ids' )
    def _onchange_categ_ids(self):
        product_ids = []
        template_ids = []
        self.product_ids = ()
        for categ in self.categ_ids:
        products_template = self.env['product.template'].search([('categ_id', '=', categ._origin.id)])
        if products_template:
            template_ids=[product.id for product in products_template]
            products = self.env['product.product'].search([('product_tmpl_id', 'in', template_ids)])
            if products:
                for rec in products:
                    product_ids.append(rec._origin.id)
        self.product_ids = [(6,0,product_ids)]



the problem is that the field product_tmpl_id in the model product.product is not filled.I need solution please as soon as possible and thank you all .

Select Product Categorie:

 

Result of the onchange function:


Error message on save :



Avatar
Discard