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
@ api.multi
@ api.constrains ('order_line')
def _check_exist_product_in_line (self):
for rec in self:
product_id = self.env ['product.product']. search ([('default_code', '=', 'MIFFLIN')])
for line in self.order_line:
if line.product_id.id in product_id:
raise ValidationError (_ ('Product already added.'))
product_id.append (line.product_id.id)
i tried like this but it's not working its throwing operation not permitted. what am i missing here , someone help me here
TypeError: Mixing apples and oranges: product.product(28,) in sale.order.line(572,)