跳至內容
選單
此問題已被標幟
1 回覆
1466 瀏覽次數

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

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
2月 22
1745
0
8月 23
1585
0
7月 25
2498
1
11月 20
3650
1
8月 25
259