Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
5366 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ

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?

Tác giả

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

Tác giả Câu trả lời hay nhất

The solution is to add first : @api.multi


And at the end : return res

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 16
5108
1
thg 3 16
3853
0
thg 3 15
4597
1
thg 12 21
1396
1
thg 12 15
4608