I need to forbid the user from confirming a sales order (action occurred when clicking on confirm sale button: Sales-> Sales Order-> choose an order). So I override the action that confirm the Sales, and add a condition which raise a validation Error, so the super wont be called in case an invalid condition(e.g. order line with product without names).
But the issue occured in S.O. - Edit mode and when clicking on confirm SO an insert to the database(insert in sale_order_line) is executed before executing the following overwritten function.
//the inherited class
class sales_warning(models.Model):
_inherit = "sale.order"
@api.multi
def action_button_confirm(self):
print "begin overwritten action_button_confirm()"
if(ForbidCondition==True):
raise ValidationError("You cannot confirm a S.O...")
else:
res = super(sales_warning, self).action_button_confirm()
return res
Logs showing the write operation before invoking the overwritten function:
crm werkzeug: .. "POST /web/dataset/call_kw/sale.order/write HTTP/1.1" 200 begin overwritten action_button_confirm()
Question: is there a way to add a constraint the will be launched before any other action such as the write above?
thank you