Skip to Content
Menu
This question has been flagged
1 Reply
1533 Views

Hello i'm making a wizard to add multiples allergens to multiples products.

I'm using odoo 17.

The wizard opens, the products selected before the wizard appear are automatically selected BUT when i want to apply one or more allergen to one or more product i have an error stating that my function inside my wizard takes only 1 argument, which is true, but got 2 arguments and i dont know why. If someone can help me it would be wonderful !


here is my wizard codes :


​Python :


from odoo import models, fields, api


class ProductAllergenWizard(models.TransientModel):

    _name = 'product.allergen.wizard'


    product_ids = fields.Many2many(

        comodel_name='product.template',

        string='Products',

        inverse_name = "allergen_category_ids"

    )

    allergen_ids = fields.Many2many(

        string = "Allergen Category",

        comodel_name="allergen_category.category",

        inverse_name="products_ids",

    )


    @api.model

    def default_get(self, fields):

        defaults = super(ProductAllergenWizard, self).default_get(fields)

        product_ids = self._context.get('default_product_ids')

        if product_ids:

            defaults['product_ids'] = product_ids

        return defaults


    @api.model

    def add_product_allergen(self):

        for record in self:

            if record.product_ids and record.allergen_ids:

                for product in record.product_ids:

                    for allergen in record.allergen_ids:

                        product.allergen_ids += allergen





​xml :



   

        product.wizard.form

        product.allergen.wizard

       

           

               

                   

                       

                       

                   

               

               

                   

                   

               

           

       

   


   

        product.wizard.form

        product.allergen.wizard

        form

        new

       

   



And here is the error if it can help to solve the problem :


TypeError: ProductAllergenWizard.add_product_allergen() takes 1 positional argument but 2 were given

Avatar
Discard

Hello,

Remove @api.model and try it hope it will work
def add_product_allergen(self):
for record in self:
if record.product_ids and record.allergen_ids:
for product in record.product_ids:
for allergen in record.allergen_ids:
product.allergen_ids += allergen

Best Answer

Hello,

Remove @api.model and write @api.multi

Avatar
Discard
Related Posts Replies Views Activity
0
Aug 21
162
5
May 20
18366
1
Jun 16
3573
0
Mar 15
3315
0
Mar 15
3762