Linking Opportunity >> RFQ >> Supplier Quotation

From an opportunity, we wrote a custom script to add “RFQ” option under the Create button.
To link the opportunity with RFQ, we have added a custom field Opportunity (link field with option Opportunity) in RFQ doctype and have overridden the following function in

def make_request_for_quotation(source_name, target_doc=None):
	doclist = get_mapped_doc("Opportunity", source_name, {
		"Opportunity": {
			"doctype": "Request for Quotation",
            "field_map": {
				"name": "opportunity"
		"Opportunity Item": {
			"doctype": "Request for Quotation Item",
			"field_map": [
				["name", "opportunity_item"],
				["parent", "opportunity"],
				["uom", "uom"]
	}, target_doc)

	return doclist

This works fine and on creating RFQ from opportunity, opportunity gets mapped to the created RFQ and shows up in the Opportunity field.

Now, when creating supplier quotation from this RFQ, we want to map this opportunity to the supplier quotation as well. A link field called “Opportunity” already exists in doctype Supplier quotation. How to achieve the same?
We tried overriding the below method in

def make_supplier_quotation(source_name, for_supplier, target_doc=None):
	def postprocess(source, target_doc):
		target_doc.supplier = for_supplier
		args = get_party_details(for_supplier, party_type="Supplier", ignore_permissions=True)
		target_doc.currency = args.currency or get_party_account_currency('Supplier', for_supplier,
		target_doc.buying_price_list = args.buying_price_list or frappe.db.get_value('Buying Settings', None, 'buying_price_list')
		set_missing_values(source, target_doc)

	doclist = get_mapped_doc("Request for Quotation", source_name, {
		"Request for Quotation": {
			"doctype": "Supplier Quotation",
			"validation": {
				"docstatus": ["=", 1]
            "field_map": {
				"opportunity": "opportunity"
		"Request for Quotation Item": {
			"doctype": "Supplier Quotation Item",
			"field_map": {
				"name": "request_for_quotation_item",
				"parent": "request_for_quotation"
	}, target_doc, postprocess)

	return doclist

but it doesn’t work. Can anybody help?