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

Hello @all,

I want to get sale.order ID on creating a Production Order in mrp.production. for that I am trying to override the create function of mrp.production.


@api.model
def create(self, values):
res = super(MrpProduction, self).create(values)
sale_order = self.env['sale.order'].search([('name', '=', values['origin'])])
values['sale_id'] = sale_order.id
return res

I know that origin is the sale order so i want to get that ID and add it to mrp.production. The function get the right ID of Sale.order but it dont save the ID to the database.


Any help to what i am doing wrang would be nice. Thanks in advance.

Jens

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

Hello Jens,

It seems the issue is in the line assigning the id to values['sale_id']. This line is storing the sale order id to the values but the values have already been used to create the record above. You should try moving the call to super() to the end so that it creates the record with the newly added 'sale_id' value.

Câu trả lời hay nhất

You called super in the first line so the MRP production already created so passing the sale order id to values will not do anything.

Try the below:

@api.model
def create(self, values):
res = super(MrpProduction, self).create(values)
if 'origin' in values:
sale_order = self.env['sale.order'].search([('name', '=', values['origin'])])
if sale_order:
res.sale_id = sale_order.id
return res
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

@Waleed

Thanks a lot. just a simple issue. Now Sale.order is connected to mrp.production. Thanks!

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