Hi,
I have a simple function that creates a purchase order. After the creation (of the purchase order) I want to redirect the user to this purchase order. (So he/she can check and confirm) But i can't seem to find the id of the purchase order I just made. And therefor can't redirect?
Heres is the code:
@api.multi
def purchase_article(self):
res = self.env['purchase.order']
value = []
value.append([0, 0, {
'product_id': self.product_id.id,
'product_uom': self.product_id.uom_id.id,
'name': self.product_id.name,
'product_qty': 0,
'date_planned': str(datetime.now()),
'price_unit': self.purchase_price,
}])
res.create({
'name' : 'New',
'partner_id': self.vendor_id.id,
'date_order': str(datetime.now()),
'order_line': value,
})
# I want to redirect to the purchase order I just created.
# because I can't find it in the res object I tried to search it but it's FALSE.
id = self.env['purchase.order'].browse(res._context.get('id',[]))
return {
'name': _('Your String'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'view_id': id,
'type': 'ir.actions.act_window',
'target': 'current',
'nodestroy': True
}