Fetch data from SO doctype

Q : How to fetch data from Sales Order in Order Acceptance ?

Doctype : Order Acceptance
Fetch Data From : Sales Order

–> click on Sales Order (button–>Get Item From) ,
–> Select one sales order then click get items then error is


Py :

@frappe.whitelist()
def make_order_acceptance(source_name, target_doc=None, ignore_permissions=False):
def postprocess(source, target):
set_missing_values(source, target)
#Get the advance paid Journal Entries in Sales Invoice Advance
target.set_advances()

def set_missing_values(source, target):
	target.flags.ignore_permissions = True
	target.run_method("set_missing_values")
	target.run_method("calculate_taxes_and_totals")

	# set company address
	target.update(get_company_address(target.company))
	if target.company_address:
		target.update(get_fetch_values("Sales Invoice", 'company_address', target.company_address))

def update_item(source, target, source_parent):
	target.amount = flt(source.amount) - flt(source.billed_amt)
	target.base_amount = target.amount * flt(source_parent.conversion_rate)
	target.qty = target.amount / flt(source.rate) if (source.rate and source.billed_amt) else source.qty

	item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
	target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
		or item.selling_cost_center \
		or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")

doclist = get_mapped_doc("Order Acceptance", source_name, {
	"Sales Order Item": {
		"doctype": "Sales Order Item",
		"field_map": {
			#"name": "so_detail",
			"parent": "sales_order",
		},	
		"postprocess": update_item,
		"condition": lambda doc: doc.qty and (doc.base_amount==0 or abs(doc.billed_amt) < abs(doc.amount))
	},
	"Sales Taxes and Charges": {
		"doctype": "Sales Taxes and Charges",
		"add_if_empty": True
	},
	"Sales Team": {
		"doctype": "Sales Team",
		"add_if_empty": True
	},
}, target_doc, postprocess, ignore_permissions=ignore_permissions)

return doclist

Hi @Divyesh_Kanzariya ,

1 Is it showing SO-00003 on the Link FIeld?
2. If you trigger a JS on change of the lInk field, are you able to fetch the SO in JS or may be a whitelist in PY ?

Still I am not clear with the sequence… The get from item button… it asks for SO or you enter in link field ?

Regards,

Parth

Hi @joshiparthin
now i get solution, the problem inside method of make_order_acceptance in python.
Py :
@frappe.whitelist()
def make_order_acceptance(source_name, target_doc=None, ignore_permissions=False):

def postprocess(source, target):
	set_missing_values(source, target)
	#Get the advance paid Journal Entries in Sales Invoice Advance
	#target.set_advances()

def set_missing_values(source, target):
	target.flags.ignore_permissions = True
	target.run_method("set_missing_values")
	target.run_method("calculate_taxes_and_totals")
	
	# set company address
	target.update(get_company_address(target.company))
	if target.company_address:
		target.update(get_fetch_values("Order Acceptance", 'company_address', target.company_address))

def update_item(source, target, source_parent):
	target.amount = flt(source.amount) - flt(source.billed_amt)
	target.base_amount = target.amount * flt(source_parent.conversion_rate)
	target.qty = target.amount / flt(source.rate) if (source.rate and source.billed_amt) else source.qty

	item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
	target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
		or item.selling_cost_center \
		or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")

doclist = get_mapped_doc("Sales Order", source_name, {
	"Sales Order": {
		"doctype": "Order Acceptance",
		"validation": {
			"docstatus": ["=", 1]
		}
	},
	"Sales Order Item": {
		"doctype": "Order Acceptance Item",
		"field_map": {
			"parent": "sales_order",
		},	
		"postprocess": update_item,
		"condition": lambda doc: doc.qty and (doc.base_amount==0 or abs(doc.billed_amt) < abs(doc.amount))
	},		
	"Sales Taxes and Charges": {
		"doctype": "Sales Taxes and Charges",
		"add_if_empty": True
	},
	"Sales Team": {
		"doctype": "Sales Team",
		"add_if_empty": True
	},
}, target_doc, postprocess, ignore_permissions=ignore_permissions)

return doclist