Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[9.0] How to solve this Problem of quantity when a PO is created after the confirmation of SO ?

By
Totor
on 3/29/16, 4:04 AM 292 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.

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 ^^

Totor
on 3/29/16, 10:28 AM

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?

Yenthe
on 3/30/16, 5:46 AM

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()

Totor
on 3/30/16, 6:00 AM
0
Totor
On 3/30/16, 7:02 AM

The solution is to add first : @api.multi


And at the end : return res

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/29/16, 4:04 AM
Seen: 292 times
Last updated: 3/30/16, 7:02 AM