refactor: variable names and suggested changes
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js
index 29c3d5b..64d5841 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.js
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js
@@ -212,7 +212,7 @@
 	},
 
 	get_items: function (frm) {
-		frm.clear_table('prod_plan_ref');
+		frm.clear_table('prod_plan_references');
 
 		frappe.call({
 			method: "get_items",
@@ -224,15 +224,13 @@
 		});
 	},
 	combine_items: function (frm) {
-		frm.clear_table('prod_plan_ref');
+		frm.clear_table('prod_plan_references');
 
 		frappe.call({
 			method: "get_items",
 			freeze: true,
 			doc: frm.doc,
 		});
-
-
 	},
 
 	get_items_for_mr: function(frm) {
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 8d578fd..46e0476 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -171,20 +171,28 @@
 		for data in items:
 			item_details = get_item_details(data.item_code)
 			if self.combine_items:	
-				if item_details.bom_no in refs.keys():
+				if item_details.bom_no in refs:
+					refs[item_details.bom_no]['so_details'].append({
+						'sales_order': data.parent,
+						'sales_order_item': data.name, 
+						'qty': data.pending_qty
+					})
 					refs[item_details.bom_no]['qty'] += data.pending_qty
-					refs[item_details.bom_no]['so'].append(data.parent)	
-					refs[item_details.bom_no]['so_items'].append(data.name)
-					refs[item_details.bom_no]['planned_qty'].append(data.pending_qty)
 					continue
+
 				else:
-					refs[item_details.bom_no] = {'qty': data.pending_qty, 'ref': data.name}
-					refs[item_details.bom_no]['so'] = [data.parent]
-					refs[item_details.bom_no]['so_items'] = [data.name]
-					refs[item_details.bom_no]['planned_qty'] = [data.pending_qty]
-		
+					refs[item_details.bom_no] = {
+						'qty': data.pending_qty,
+						'po_item_ref': data.name,
+						'so_details': []
+					}
+					refs[item_details.bom_no]['so_details'].append({
+						'sales_order': data.parent,
+						'sales_order_item': data.name, 
+						'qty': data.pending_qty
+					})
+					
 			pi = self.append('po_items', {
-				'name': data.name,
 				'include_exploded_items': 1,
 				'warehouse': data.warehouse,
 				'item_code': data.item_code,
@@ -201,8 +209,6 @@
 				pi.sales_order = data.parent
 				pi.sales_order_item = data.name
 				pi.description = data.description
-				pi.item_reference = data.name
-				
 					
 			elif self.get_items_from == "Material Request":
 				pi.material_request = data.parent
@@ -210,24 +216,21 @@
 				pi.description = data.description
 	
 		if refs:
-			for d in self.po_items:
-				d.planned_qty = refs[d.bom_no]['qty']
-				d.pending_qty = refs[d.bom_no]['qty']
-				d.sales_order = ''
+			for po_item in self.po_items:
+				po_item.planned_qty = refs[po_item.bom_no]['qty']
+				po_item.pending_qty = refs[po_item.bom_no]['qty']
+				po_item.sales_order = ''
 			self.add_pp_ref(refs)
 
 	def add_pp_ref(self, refs):
 		for bom_no in refs:
-			idx = 0
-			for so in refs[bom_no]['so']:
+			for so_detail in refs[bom_no]['so_details']:
 				self.append('prod_plan_references', {
-						'item_reference': refs[bom_no]['ref'],
-						'sales_order': so,
-						'sales_order_item':refs[bom_no]['so_items'][idx],
-						'qty':refs[bom_no]['planned_qty'][idx]
+						'item_reference': refs[bom_no]['po_item_ref'],
+						'sales_order': so_detail['sales_order'],
+						'sales_order_item': so_detail['sales_order_item'],
+						'qty': so_detail['qty']
 				})
-				idx+=1
-
 
 	def calculate_total_planned_qty(self):
 		self.total_planned_qty = 0
diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
index ec5c5e0..768f99e 100644
--- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
@@ -166,16 +166,16 @@
 			'grand_total': so.grand_total
 		})
 		pln.combine_items = 1
-		pln.get_so_items()
-		for plan_reference in pln.prod_plan_references:
-			plan_reference.item_reference = pln.po_items[0].name
+		pln.get_items()
 		pln.submit()
 
-		self.assertTrue(pln.po_items[0].planned_qty,3)	
+		self.assertTrue(pln.po_items[0].planned_qty, 3)	
 
 		pln.make_work_order()
-		work_order = frappe.db.get_value('Work Order', {'production_plan_item': pln.po_items[0].name,
-			'production_plan': pln.name,}, 'name')
+		work_order = frappe.db.get_value('Work Order', {
+			'production_plan_item': pln.po_items[0].name,
+			'production_plan': pln.name
+		}, 'name')
 
 		wo_doc = frappe.get_doc('Work Order', work_order)
 		wo_doc.update({
@@ -194,8 +194,8 @@
 			so_wo_qty = frappe.db.get_value('Sales Order Item', so_item, 'work_order_qty')
 			self.assertEqual(so_wo_qty, 0.0)
 		
-		lat_plan = frappe.get_doc('Production Plan',pln.name)
-		lat_plan.cancel()
+		latest_plan = frappe.get_doc('Production Plan', pln.name)
+		latest_plan.cancel()
 	
 	def test_pp_to_mr_customer_provided(self):
 		#Material Request from Production Plan for Customer Provided
diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py
index bb6450b..a154464 100644
--- a/erpnext/manufacturing/doctype/work_order/work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/work_order.py
@@ -377,7 +377,7 @@
 				total_bundle_qty = 1
 
 		prod_plan = frappe.get_doc('Production Plan', self.production_plan)
-		item_reference = frappe.get_value('Production Plan Item', self.production_plan_item,'item_reference')
+		item_reference = frappe.get_value('Production Plan Item', self.production_plan_item, 'sales_order_item')
 		
 		for plan_reference in prod_plan.prod_plan_references:
 			work_order_qty = 0.0