跳至內容
選單
此問題已被標幟
1 回覆
5149 瀏覽次數

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!

頭像
捨棄
最佳答案

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)]})
頭像
捨棄
作者

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?

作者

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?

作者

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

相關帖文 回覆 瀏覽次數 活動
1
12月 22
2704
1
9月 21
6080
1
4月 21
2066
1
7月 20
3455
2
12月 19
6904