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

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

Imagine profil
Abandonează
Cel mai bun răspuns
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
Imagine profil
Abandonează
Cel mai bun răspuns

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!")
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
ian. 22
18548
2
aug. 19
8442
3
iul. 19
5448
2
dec. 21
7411
4
nov. 20
7923