Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5105 Vizualizări

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!

Imagine profil
Abandonează
Cel mai bun răspuns

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)]})
Imagine profil
Abandonează
Autor

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?

Autor

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?

Autor

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?

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

Related Posts Răspunsuri Vizualizări Activitate
1
dec. 22
2678
1
sept. 21
6028
1
apr. 21
2028
1
iul. 20
3429
2
dec. 19
6853