Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
7171 Lượt xem

please correct me where i'm wrong / or suggest me best way to achieve my goal ...

in xml

```

<field name="ssr_line" on_change="onchange_product(ssr_line)">

```

in python 


```

class ssr_line(models.Model):

 _name="ssr.line"
def onchange_product(self, order_line): 

 mylist = [] 

 if order_line != []: 

 for line in order_line: 

 for loop in line: 

if isinstance(loop, dict): 

mylist.append(loop['product_id']) 

 if len(mylist) != len(set(mylist)): raise exceptions.ValidationError('Product Should be Unique') 

 return True

```

nathig happen no error no out put no result

correct me or sugeest me othe way 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

From onchange, you cannot raise exception or it won't stop the flow. 

Better to check the duplicate products on save button (create / write method) and display the duplicate product name in the exception message.

Ảnh đại diện
Huỷ bỏ

After the user enter say 50 records in the sale order line you suggest raising the error then?

Câu trả lời hay nhất

Dear Usman,

To check exist the same Product in the line level.

from odoo import models, fields, api
from odoo.exceptions import ValidationError


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

@api.multi
@api.constrains('order_line')
def _check_exist_product_in_line(self):
for purchase in self:
exist_product_list = []
for line in purchase.order_line:
if line.product_id.id in exist_product_list:
raise ValidationError(_('Product should be one per line.'))
exist_product_list.append(line.product_id.id)

Hope this code help you

Best Thanks,

Ankit H Gandhi.

Ảnh đại diện
Huỷ bỏ
Tác giả

great

Câu trả lời hay nhất

Hi,

You can use the unique constrains for this, please see my previous answer for the similar question: How to Prevent selecting the same value in one2many field in odoo 10?


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

i use this solution ... thanks @Niyas

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 2 24
11692
2
thg 2 25
5942
1
thg 12 24
1484
2
thg 12 24
6580
1
thg 11 22
16025