Skip to Content
Menu
This question has been flagged
1 Reply
2070 Views

Good day everyone.


Is there a way to execute custom code after a sale order is created succesfully? I was thinking inherit sale order and override or extend the create method not sure if thats the proper/right way.


Thanks in advance


Avatar
Discard

when you need to execute your function, on creation of the sale order or on confirming the sale order ?

Yes you have to override create or write method..

Author

Thanks Ray, that worked just fine. 

Best Answer

Take a look at how we do this in the sale_purchase module:

https://github.com/odoo/odoo/blob/15.0/addons/sale_purchase/models/sale_order.py#L24

There is an internal function that we override.

(you would do the same in your own module: call super and then your code)

def _action_confirm(self):
result = super(SaleOrder, self)._action_confirm()
for order in self:
order.order_line.sudo()._purchase_service_generation()
return result

More documentation at https://www.odoo.com/documentation/15.0/developer/howtos/rdtraining/13_inheritance.html

Avatar
Discard