Skip to Content
Menu
This question has been flagged

In module procurement_sale_forecast, the function create a procurement.

@api.multi
def create_procurements(self):
procurement_obj = self.env['procurement.order']
procure_lst = []
for record in self:
for product_line in record.forecast_lines:
if product and not product_line.procurement_id:
procure_id = procurement_obj.create({
'name': (
'MPS: ' + record.name + ' (' + record.date_from +
'.' + record.date_to + ') ' +
record.warehouse_id.name),
'date_planned': product_line.date,
'product_id': product.id,
'product_qty': product_qty,
'product_uom': product.uom_id.id,
'location_id': record.warehouse_id.lot_stock_id.id,
'company_id': record.warehouse_id.company_id.id,
'warehouse_id': record.warehouse_id.id,
'origin' : product_line.order_id.name,
})
procure_id.signal_workflow('button_confirm')
procure_lst.append(procure_id.id)
product_line.procurement_id = procure_id.id

self.write({ 'state' : 'done' })
return {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'procurement.order',
'res_ids': procure_lst,
'domain': [('id', 'in', procure_lst)],
'type': 'ir.actions.act_window',
}

I have two products in same line(product_id,product_rep_id).I want to create two procurements for one line, each product_id have a procurement.

I add a test in the function but the procurement is created by product_rep_id and not with two product.

@api.multi

def create_procurements(self):
procurement_obj = self.env['procurement.order']
procure_lst = []
for record in self:
for product_line in record.forecast_lines:
if product_line.product_rep_id :
product = product_line.product_rep_id
product_qty = product_line.procurment_rep_qty
else :
product = product_line.product_id
product_qty = product_line.procurment_qty
if product and not product_line.procurement_id:
procure_id = procurement_obj.create({
'name': (
'MPS: ' + record.name + ' (' + record.date_from +
'.' + record.date_to + ') ' +
record.warehouse_id.name),
'date_planned': product_line.date,
'product_id': product.id,
'product_qty': product_qty,
'product_uom': product.uom_id.id,
'location_id': record.warehouse_id.lot_stock_id.id,
'company_id': record.warehouse_id.company_id.id,
'warehouse_id': record.warehouse_id.id,
'origin' : product_line.order_id.name,

})
procure_id.signal_workflow('button_confirm')
procure_lst.append(procure_id.id)
product_line.procurement_id = procure_id.id
self.write({ 'state' : 'done' })

return {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'procurement.order',
'res_ids': procure_lst,
'domain': [('id', 'in', procure_lst)],
'type': 'ir.actions.act_window',

}



Avatar
Discard
Best Answer

hello,

You may try create a fields procure_rep_id (copy procure id) and you create procurements when product_id exist (with procure_id) and product_rep_id (with procure_rep_id) 

Hope this will help you.

Avatar
Discard
Related Posts Replies Views Activity
3
Aug 15
2337
2
Jul 15
3963
0
Mar 15
3123
1
Mar 15
2421
2
Aug 22
12863