Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
10275 Zobrazení

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

Avatar
Zrušit
Nejlepší odpověď
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
Avatar
Zrušit
Nejlepší odpověď

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!")
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
led 22
18515
2
srp 19
8428
3
čvc 19
5413
2
pro 21
7385
4
lis 20
7897