hi all iam a newbie to odoo , what iam trying to achieve is i want to prevent from adding duplicate products in order line , if the same exits already we should not able to add the duplicate product , I tried like this but its not working
@ api.constrains ('order_line')
def _check_exist_product_in_line (self):
product_ids = self.env ['product.product']. search ([('default_code', '=', 'KIB_PRF')])
for line in self.order_line:
# self.env ['sale.order.line']. create ({'product_id': product_id.id, 'order_id': self.id})
if line.product_id in product_ids:
raise ValidationError (_ ('Product already added.'))
# product_id.append (line.product_id.id)