Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Feb 22
1701
0
Agu 23
1543
0
Jul 25
2400
1
Nov 20
3494
0
Feb 25
928