Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
4 Ответы
3631 Представления

Hello,

In below code, product_id is my Many2many field of product1 table and price is a field of that table When i select more than one product in Many2many field, I get this error : ValueError: Expected singleton:
product1.product1(2, 4)  . can anyone help me.

Thanks in advance.


Code:


total = fields.Float("Total",readonly=True,compute="count")

product_id = fields.Many2many('product1.product1',string="Products")

@api.onchange('product_id')
def count(self):
for i in self:
i.total = i.product_id.price

Аватар
Отменить

Thanks, Mitul Singala it works.




Лучший ответ

Hello,

in your code product_id is many2many field. and into method line: i.product_id.price, you get the multiple product ids. that's why you get singleton error.make below change into your code:

@api.onchange('product_id')
def count(self):
    for i in self:
        total = 0
        for prod in i.product_id:
            total += prod.price
        i.total = total
Аватар
Отменить
Лучший ответ

Hi Ruturaj,

ValueError: Expected singleton: product1.product1(2, 4)  it means product_id return multiple records you can not directly assign values.

Example:

@api.onchange('product_id')
def count(self):
    for i in self:
        total = 0
        for p in i.product_id:
            total += p.price
        i.total = total
Thank You.
Аватар
Отменить
Автор Лучший ответ


Аватар
Отменить
Related Posts Ответы Просмотры Активность
4
мар. 24
1603
4
дек. 19
5277
2
июл. 23
2330
1
дек. 20
14457
5
февр. 20
9038