This question has been flagged
4 Replies
3817 Views

Hi, I inherit the function "make_po" in order that after the confirmation of a SO, a PO is created.

It works but the problem is that if I put 1 article X in my SO, I'll have 3 articles X in my PO

I did tests with prints and the function "make_po" is executed 3 times but I don't know why.

This is my class:

class procurement_order(models.Model):

_inherit = 'procurement.order'

def make_po(self):

res = super(procurement_order,self).make_po()

so_name = self.origin[:5]

sale_order=self.env['sale.order'].search([('name', '=', so_name)])

analytic_account_id = sale_order.project_id.id

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

idPOLine = po_line.search([('id', '=', self.purchase_line_id.id)])

idPOLine.write({'name':self.name,'account_analytic_id':analytic_account_id})

procurement_order()

In advance, thanks.

Avatar
Discard

Still have the problem but the problem comes from the fact that the make_po method is runned 3 times,


so the quantity is set to 3 instead 1


But I don't know why, help me please ^^

You should use @api.multi at the top of the function and use self.ensure_one inside the function. Why don't you write on the res record? You're writing on the po_line.search but why not write directly on res which contains your values?

Author

I tried your solution but it doesn't work : class procurement_order(models.Model): _inherit = 'procurement.order' @api.multi def make_po(self): self.ensure_one() res = super(procurement_order,self).make_po() so_name = self.origin[:5] sale_order=self.env['sale.order'].search([('name', '=', so_name)]) analytic_account_id = sale_order.project_id.id po_line = self.env['purchase.order.line'] idPOLine = po_line.search([('id', '=', self.purchase_line_id.id)]) idPOLine.write({'name':self.name,'account_analytic_id':analytic_account_id}) procurement_order()

Author Best Answer

The solution is to add first : @api.multi


And at the end : return res

Avatar
Discard