Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
10293 มุมมอง

hello guys so i have 

model product identity

field:

1. ~~

2. ~~

3. barcode 


and product template has relation one2many to product identity

and i want to give/raise warning every product identity created in one2many tree view when there is record with the same/duplicate barcode in the one2many data.. 


can anyone help me? i try use api.onchange but it seems not that easy thank you :D

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด
Consider identity_ids as one2many field in the product template
You can write an onchange function for this field.

@api.onchange('identity_ids')
def onchange_identity_ids(self):
for order in self.identity_ids:
line = self.identity_ids.filtered(lambda l: l.barcode == order.barcode)
if len(line) > 1:
raise ValidationError(_('You cannot have multiple lines with same barcode(%s)')%(line[1].barcode))
break
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Here's an example of using an Automated Action to prevent duplicates (Odoo already blocks duplicate barcodes so this is the Internal Reference).  If I understand your requirement you could change the Python code to ensure that there are no duplicates within the product identity group.

https://odootricks.tips/automated-action-to-prevent-duplicates/


Model:  Product Template
Action To Do:    Execute Python Code
Trigger Condition:   On Creation & Update
Before Update Domain: Internal Reference is set
Apply on:  Match all records 

Python Code

if record.default_code:
   existing_product = env['product.template'].search([('id','!=',record.id),('default_code','=',record.default_code)])
   if existing_product:
     raise Warning("You can't have the same Internal Reference Number in Odoo twice!")
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 22
18526
2
ส.ค. 19
8430
3
ก.ค. 19
5417
2
ธ.ค. 21
7388
4
พ.ย. 20
7906