Merge pull request #23233 from ruchamahabal/fix-rfq-conv-factor

fix: set conversion factor while creating RFQ from Opportunity
diff --git a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py
index 3de9526..019cefc 100644
--- a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py
@@ -11,6 +11,8 @@
 from erpnext.templates.pages.rfq import check_supplier_has_docname_access
 from erpnext.buying.doctype.request_for_quotation.request_for_quotation import make_supplier_quotation
 from erpnext.buying.doctype.request_for_quotation.request_for_quotation import create_supplier_quotation
+from erpnext.crm.doctype.opportunity.test_opportunity import make_opportunity
+from erpnext.crm.doctype.opportunity.opportunity import make_request_for_quotation as make_rfq
 
 class TestRequestforQuotation(unittest.TestCase):
 	def test_quote_status(self):
@@ -110,6 +112,23 @@
 		self.assertEqual(supplier_quotation.items[0].qty, 5)
 		self.assertEqual(supplier_quotation.items[0].stock_qty, 10)
 
+	def test_make_rfq_from_opportunity(self):
+		opportunity = make_opportunity(with_items=1)
+		supplier_data = get_supplier_data()
+		rfq = make_rfq(opportunity.name)
+
+		self.assertEqual(len(rfq.get("items")), len(opportunity.get("items")))
+		rfq.message_for_supplier = 'Please supply the specified items at the best possible rates.'
+
+		for item in rfq.items:
+			item.warehouse = "_Test Warehouse - _TC"
+
+		for data in supplier_data:
+			rfq.append('suppliers', data)
+
+		rfq.status = 'Draft'
+		rfq.submit()
+
 def make_request_for_quotation(**args):
 	"""
 	:param supplier_data: List containing supplier data
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index 6096053..47b05f3 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -267,6 +267,9 @@
 
 @frappe.whitelist()
 def make_request_for_quotation(source_name, target_doc=None):
+	def update_item(obj, target, source_parent):
+		target.conversion_factor = 1.0
+
 	doclist = get_mapped_doc("Opportunity", source_name, {
 		"Opportunity": {
 			"doctype": "Request for Quotation"
@@ -277,7 +280,8 @@
 				["name", "opportunity_item"],
 				["parent", "opportunity"],
 				["uom", "uom"]
-			]
+			],
+			"postprocess": update_item
 		}
 	}, target_doc)
 
diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py
index 33d9007..04cd8a2 100644
--- a/erpnext/crm/doctype/opportunity/test_opportunity.py
+++ b/erpnext/crm/doctype/opportunity/test_opportunity.py
@@ -82,7 +82,8 @@
 	if args.with_items:
 		opp_doc.append('items', {
 			"item_code": args.item_code or "_Test Item",
-			"qty": args.qty or 1
+			"qty": args.qty or 1,
+			"uom": "_Test UOM"
 		})
 
 	opp_doc.insert()