Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1408 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
úno 22
1701
0
srp 23
1543
0
čvc 25
2398
1
lis 20
3494
0
úno 25
927