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

How to create a procurement with two product in sale sale_forecast??

By
Achref Mhadhbi
on 11/5/15, 1:13 PM 433 views

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',

}



0
Sakli
On 11/10/15, 1:05 PM

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.

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

2 follower(s)

Stats

Asked: 11/5/15, 1:13 PM
Seen: 433 times
Last updated: 11/10/15, 1:05 PM