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

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
}



Avatar
Discard
Best Answer

Change Code. Create function returns browsable object.


@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,
}])
purchase_order_id = res.create({
'name' : 'New',
'partner_id': self.vendor_id.id,
'date_order': str(datetime.now()),
'order_line': value,

})
 return {
'name': _('Your String'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'res_id': purchase_order_id and purchase_order_id.id,
'type': 'ir.actions.act_window',
'target': 'current',
'nodestroy': True
}



Avatar
Discard
Author

Hi Hilar,

Thanks for your answer is works but . I've another problem I can't pass the taxes_id.

@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': 1,

'date_planned': str(datetime.now()),

'price_unit': self.purchase_price,

'taxes_id' : self.product_id.taxes_id # how to pass all the taxes??

}])

newpo= res.create({

'name' : 'New',

'partner_id': self.vendor_id.id,

'date_order': str(datetime.now()),

'order_line': value,

'requisition_id':self.supplierinfo_id.purchase_requisition_id.id,

})

return {

'domain': "[('id','='," + str(newpo.id) + ")]",

'name': 'Purchase Order',

'view_type': 'form',

'view_mode': 'form',

'res_model': 'purchase.order',

'type': 'ir.actions.act_window',

'res_id': newpo.id

}

I thought maybe I can create an ordeline object and add the properties this way? But if I do I get an error.

orderline = self.env['purchase.order.line']

orderline.product_id= self.product_id

Try self.product_Id.taxes_Id.ids

On Wed, 9 Oct 2019, 4:25 pm ATX, <it@atraxion.com> wrote:

Hi Hilar,

Thanks for your answer is works but . I've another problem I can't pass the taxes_id.

@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': 1,

'date_planned': str(datetime.now()),

'price_unit': self.purchase_price,

'taxes_id' : self.product_id.taxes_id # how to pass all the taxes??

}])

newpo= res.create({

'name' : 'New',

'partner_id': self.vendor_id.id,

'date_order': str(datetime.now()),

'order_line': value,

'requisition_id':self.supplierinfo_id.purchase_requisition_id.id,

})

return {

'domain': "[('id','='," + str(newpo.id) + ")]",

'name': 'Purchase Order',

'view_type': 'form',

'view_mode': 'form',

'res_model': 'purchase.order',

'type': 'ir.actions.act_window',

'res_id': newpo.id

}

I thought maybe I can create an ordeline object and add the properties this way? But if I do I get an error.

orderline = self.env['purchase.order.line']

orderline.product_id= self.product_id

Sent by Odoo S.A. using Odoo.

Related Posts Replies Views Activity
3
Dec 24
2351
1
Jul 24
698
1
Jun 24
767
2
Jun 24
895
1
Apr 24
494