Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1373 Vistas

Hello,

We have created a material requisition model from which we can choose if the RFQ needs to be created. If the products are to be requested from the same vendor, the current code creates individual RFQ for every line item (product). But we need to loop it in the same RFQ with multiple products to the single vendor. My current code is 

for partner_id in rec.partner_ids:
self.env['purchase.order'].create({
'partner_id': partner_id.id,
'requisition_order': self.name,
'project_requisition_name_id': self.project_requisition_name_id.id,
'job_number': self.job_num,
"order_line": [(0, 0, {
'product_id': rec.product_id.id,
'product_qty': rec.quantity,
'name': rec.description,
})]})

Could you please advise/guide how to make sure a single RFQ is created for multiple line items (products) having the same vendor

Avatar
Descartar
Mejor respuesta

Hi Alark Kulkarni,

The provided code creates individual RFQs for each line item because it loops through rec.partner_ids, which likely contains multiple vendors. Here's how to modify the code to create a single RFQ with multiple products for the same vendor:

  • Instead of looping through individual partners, group the requisition lines by vendor first. This will ensure products for the same vendor are processed together. Here's an example using Python's group by function: 

grouped_lines = groupby(rec, lambda line: line.product_id.seller_id.id)

  • Now Loop through the grouped lines dictionary (grouped_lines).
    Inside the loop, create a single RFQ for each vendor group:

for vendor_id, vendor_lines in grouped_lines:

    # Create RFQ with vendor details

    rfq = self.env['purchase.order'].create({

        'partner_id': vendor_id,

        'requisition_order': self.name,

        'project_requisition_name_id': self.project_requisition_name_id.id,

        'job_number': self.job_num,

        'order_line': []

    })

    # Add product lines to the RFQ

    for line in vendor_lines:

        rfq.order_line = [(0, 0, {

            'product_id': line.product_id.id,

            'product_qty': line.quantity,

            'name': line.description,

        })]


Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
feb 22
1686
0
ago 23
1526
0
jul 25
2361
1
nov 20
3441
0
feb 25
894