How to add a constraint to many2many field odoo14

يمكنك القيام بذلك باستخدام الكود التالي,

 

@api.constrains('category_id')
def _check_category_con(self):
for record in self:
if record.category_id:
#check your condition here
raise ValidationError("Duplicate category in items line not allowed !")