Reputation: 365
Are there any way to create some new model after onchange triggered?
For example, I want to create my custom report object after the state of quotation is changed to sale order.
Upvotes: 2
Views: 2361
Reputation: 580
You can create a new instance of a model with the following code inside :sales.order
inside a method with the decorator @api.onchange('state')
report_model = self.env['my.custom.report.object']
new_report_object = report_model.create({
'report_message': 'Quotation changed state to Sales Order'
})
Upvotes: 1
Reputation: 365
I solved that by trying to override action_confirm method of sale.order and it's worked!
class sale_order(models.Model) :
_inherit = 'sale.order'
job_container = fields.One2many('job.container','order')
@api.multi
def action_confirm(self):
super(sale_order, self).action_confirm()
self.env['job.container'].create({
'order': self.id
})
Upvotes: 3