Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
1423 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lut 22
1717
0
sie 23
1551
0
lip 25
2436
1
lis 20
3574
0
lut 25
951