refactor: variable names and refactored cancel function into submit function
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.json b/erpnext/manufacturing/doctype/production_plan/production_plan.json
index 5c73992..3041507 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.json
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.json
@@ -31,7 +31,7 @@
   "combine_items",
   "po_items",
   "section_break_25",
-  "prod_plan_ref",
+  "prod_plan_references",
   "material_request_planning",
   "include_non_stock_items",
   "include_subcontracted_items",
@@ -321,13 +321,6 @@
    "label": "Include Safety Stock in Required Qty Calculation"
   },
   {
-   "fieldname": "prod_plan_ref",
-   "fieldtype": "Table",
-   "hidden": 1,
-   "label": "Production Plan Item Reference",
-   "options": "Production Plan Item Reference"
-  },
-  {
    "default": "0",
    "fieldname": "combine_items",
    "fieldtype": "Check",
@@ -336,13 +329,20 @@
   {
    "fieldname": "section_break_25",
    "fieldtype": "Section Break"
+  },
+  {
+   "fieldname": "prod_plan_references",
+   "fieldtype": "Table",
+   "hidden": 1,
+   "label": "Production Plan Item Reference",
+   "options": "Production Plan Item Reference"
   }
  ],
  "icon": "fa fa-calendar",
  "index_web_pages_for_search": 1,
  "is_submittable": 1,
  "links": [],
- "modified": "2021-04-26 14:11:43.564957",
+ "modified": "2021-05-07 16:56:00.255001",
  "modified_by": "Administrator",
  "module": "Manufacturing",
  "name": "Production Plan",
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 088089f..8d578fd 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -172,7 +172,7 @@
 			item_details = get_item_details(data.item_code)
 			if self.combine_items:	
 				if item_details.bom_no in refs.keys():
-					refs[item_details.bom_no]['qty'] = refs[item_details.bom_no]['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)
@@ -217,15 +217,15 @@
 			self.add_pp_ref(refs)
 
 	def add_pp_ref(self, refs):
-		for r in refs:
+		for bom_no in refs:
 			idx = 0
-			for so in refs[r]['so']:
-				self.append('prod_plan_ref', {
-						'item_ref': refs[r]['ref'],
+			for so in refs[bom_no]['so']:
+				self.append('prod_plan_references', {
+						'item_reference': refs[bom_no]['ref'],
 						'sales_order': so,
-						'sales_order_item':refs[r]['so_items'][idx],
-						'qty':refs[r]['planned_qty'][idx]
-						})
+						'sales_order_item':refs[bom_no]['so_items'][idx],
+						'qty':refs[bom_no]['planned_qty'][idx]
+				})
 				idx+=1
 
 
diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
index 19b06bc..ec5c5e0 100644
--- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
@@ -167,8 +167,8 @@
 		})
 		pln.combine_items = 1
 		pln.get_so_items()
-		for d in pln.prod_plan_ref:
-			d.item_ref = pln.po_items[0].name
+		for plan_reference in pln.prod_plan_references:
+			plan_reference.item_reference = pln.po_items[0].name
 		pln.submit()
 
 		self.assertTrue(pln.po_items[0].planned_qty,3)	
@@ -184,13 +184,14 @@
 
 		wo_doc.submit()
 		so_items = []
-		for d in pln.prod_plan_ref:
-			so_items.append(d.sales_order_item)
-			so_wo_qty = frappe.db.get_value('Sales Order Item', d.sales_order_item, 'work_order_qty')
-			self.assertEqual(so_wo_qty, d.qty)
+		for plan_reference in pln.prod_plan_references:
+			so_items.append(plan_reference.sales_order_item)
+			so_wo_qty = frappe.db.get_value('Sales Order Item', plan_reference.sales_order_item, 'work_order_qty')
+			self.assertEqual(so_wo_qty, plan_reference.qty)
+
 		wo_doc.cancel()
-		for s in so_items:
-			so_wo_qty = frappe.db.get_value('Sales Order Item', s, 'work_order_qty')
+		for so_item in so_items:
+			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)
diff --git a/erpnext/manufacturing/doctype/production_plan_item_reference/production_plan_item_reference.json b/erpnext/manufacturing/doctype/production_plan_item_reference/production_plan_item_reference.json
index 19e813c..84dee4a 100644
--- a/erpnext/manufacturing/doctype/production_plan_item_reference/production_plan_item_reference.json
+++ b/erpnext/manufacturing/doctype/production_plan_item_reference/production_plan_item_reference.json
@@ -5,19 +5,13 @@
  "editable_grid": 1,
  "engine": "InnoDB",
  "field_order": [
-  "item_ref",
+  "item_reference",
   "sales_order",
   "sales_order_item",
   "qty"
  ],
  "fields": [
   {
-   "fieldname": "item_ref",
-   "fieldtype": "Data",
-   "in_list_view": 1,
-   "label": "Item Reference"
-  },
-  {
    "fieldname": "sales_order",
    "fieldtype": "Link",
    "in_list_view": 1,
@@ -35,12 +29,18 @@
    "fieldtype": "Data",
    "in_list_view": 1,
    "label": "qty"
+  },
+  {
+   "fieldname": "item_reference",
+   "fieldtype": "Data",
+   "in_list_view": 1,
+   "label": "Item Reference"
   }
  ],
  "index_web_pages_for_search": 1,
  "istable": 1,
  "links": [],
- "modified": "2021-04-23 16:55:22.161418",
+ "modified": "2021-05-07 17:03:49.707487",
  "modified_by": "Administrator",
  "module": "Manufacturing",
  "name": "Production Plan Item Reference",
diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py
index d9956e5..bb6450b 100644
--- a/erpnext/manufacturing/doctype/work_order/work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/work_order.py
@@ -240,10 +240,8 @@
 			frappe.throw(_("Work-in-Progress Warehouse is required before Submit"))
 		if not self.fg_warehouse:
 			frappe.throw(_("For Warehouse is required before Submit"))
-
-		prod_plan = frappe.get_doc('Production Plan', self.production_plan)
 		
-		if prod_plan.prod_plan_ref:
+		if self.production_plan and frappe.db.exists('Production Plan Item Reference',{'parent':self.production_plan}):
 			self.update_work_order_qty_in_combined_so()
 		else:
 			self.update_work_order_qty_in_so()
@@ -256,12 +254,10 @@
 
 	def on_cancel(self):
 		self.validate_cancel()
-
 		frappe.db.set(self,'status', 'Cancelled')
-		prod_plan = frappe.get_doc('Production Plan', self.production_plan)
 
-		if prod_plan.prod_plan_ref:
-			self.update_work_order_combined_on_cancel()
+		if self.production_plan and frappe.db.exists('Production Plan Item Reference',{'parent':self.production_plan}):
+			self.update_work_order_qty_in_combined_so()
 		else:
 			self.update_work_order_qty_in_so()
 			
@@ -381,24 +377,16 @@
 				total_bundle_qty = 1
 
 		prod_plan = frappe.get_doc('Production Plan', self.production_plan)
-		pp_item = frappe.get_doc('Production Plan Item', self.production_plan_item)
+		item_reference = frappe.get_value('Production Plan Item', self.production_plan_item,'item_reference')
 		
-		for p in prod_plan.prod_plan_ref:
-			if p.item_ref == pp_item.item_reference:
-				work_order_qty = int(p.qty)
+		for plan_reference in prod_plan.prod_plan_references:
+			work_order_qty = 0.0
+			if plan_reference.item_reference == item_reference:
+				if self.docstatus == 1:
+					work_order_qty = cint(plan_reference.qty) / total_bundle_qty
 				frappe.db.set_value('Sales Order Item',
-					p.sales_order_item, 'work_order_qty', flt(work_order_qty/total_bundle_qty, 2))
+					plan_reference.sales_order_item, 'work_order_qty', work_order_qty)
 	
-	def update_work_order_combined_on_cancel(self):
-		prod_plan = frappe.get_doc('Production Plan', self.production_plan)
-		pp_item = frappe.get_doc('Production Plan Item', self.production_plan_item)
-		
-		for p in prod_plan.prod_plan_ref:
-			if p.item_ref == pp_item.item_reference:
-				frappe.db.set_value('Sales Order Item',
-					p.sales_order_item, 'work_order_qty', 0.0)
-
-
 	def update_completed_qty_in_material_request(self):
 		if self.material_request:
 			frappe.get_doc("Material Request", self.material_request).update_completed_qty([self.material_request_item])