Допомога

0

Change product variant_seller_ids

Avatar
arthur

Hello I don't know what did I do wrong, but all my products have two varriant_sellers. The right one and the one created by Odoo User, like the image bellow.


I am trying to run a script to correct these  variant seller that are wrong. I am running the following code:

@api.multi
    def correct_procuts_vendors(self):
        products = self.env['product.template'].search([])
        for product in products:
            newSellers = []
            for seller in product.variant_seller_ids:
                if seller.name.name != "maassump@gmail.com":
                    newSellers.append(seller)
            product.write({'variant_seller_ids': newSellers})

However, nothing happens when I run it and I get the follwing warnings:

2019-01-27 18:22:41,680 12814 WARNING Master odoo.models: Comparing apples and oranges: product.supplierinfo(16405,) == 1 (/usr/lib/python3/dist-packages/odoo/fields.py:2276)

2019-01-27 18:22:41,684 12814 WARNING Master odoo.models: Comparing apples and oranges: product.supplierinfo(16405,) == 2 (/usr/lib/python3/dist-packages/odoo/fields.py:2278)

2019-01-27 18:22:41,684 12814 WARNING Master odoo.models: Comparing apples and oranges: product.supplierinfo(16405,) == 3 (/usr/lib/python3/dist-packages/odoo/fields.py:2280)

2019-01-27 18:22:41,684 12814 WARNING Master odoo.models: Comparing apples and oranges: product.supplierinfo(16405,) == 4 (/usr/lib/python3/dist-packages/odoo/fields.py:2286)

2019-01-27 18:22:41,684 12814 WARNING Master odoo.models: Comparing apples and oranges: product.supplierinfo(16405,) == 5 (/usr/lib/python3/dist-packages/odoo/fields.py:2292)

2019-01-27 18:22:41,684 12814 WARNING Master odoo.models: Comparing apples and oranges: product.supplierinfo(16405,) == 6 (/usr/lib/python3/dist-packages/odoo/fields.py:2300)


Does anyone know what I am doing wrong?

Thanks!

Аватар
Відмінити
1 Відповідь
2
Avatar
Mitul Shingala
Найкраща відповідь

hello 

try with below code

@api.multi
    def correct_procuts_vendors(self):
        products = self.env['product.template'].search([])
        for product in products:
            newSellers = []
            for seller in product.variant_seller_ids:
                if seller.name.name != "maassump@gmail.com":
                    newSellers.append(seller.id)
            product.write({'variant_seller_ids': [(6, 0, newSellers)]})
4 Коментар
Аватар
Відмінити
Avatar
arthur
-

It did work, thanks very much! I understand why to change the append to seller.id, but I didn't get what "[(6, 0, newSellers)]" actually means. Would you mund telling me, please?

Avatar
arthur
-

It did work, thanks very much! I understand why to change the append to seller.id, but I didn't get what "[(6, 0, newSellers)]" actually means. Would you mund telling me, please?

Avatar
arthur
-

It did work, thanks very much! I understand why to change the append to seller.id, but I didn't get what "[(6, 0, newSellers)]" actually means. Would you mind telling me, please?

Avatar
Mitul Shingala
-

in odoo, when you write into many2many field at that time you have pass the value like [(6, 0, [list_of_record_ids])].

for more detail refer this website: https://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html