refactor: variable names and refactored cancel function into submit function
This commit is contained in:
parent
90c667205a
commit
50f52dfbcb
@ -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",
|
||||
@ -320,13 +320,6 @@
|
||||
"fieldtype": "Check",
|
||||
"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",
|
||||
@ -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",
|
||||
|
@ -172,7 +172,7 @@ class ProductionPlan(Document):
|
||||
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,14 +217,14 @@ class ProductionPlan(Document):
|
||||
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
|
||||
|
||||
|
@ -167,8 +167,8 @@ class TestProductionPlan(unittest.TestCase):
|
||||
})
|
||||
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 @@ class TestProductionPlan(unittest.TestCase):
|
||||
|
||||
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)
|
||||
|
@ -5,18 +5,12 @@
|
||||
"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",
|
||||
@ -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",
|
||||
|
@ -241,9 +241,7 @@ class WorkOrder(Document):
|
||||
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 @@ class WorkOrder(Document):
|
||||
|
||||
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,23 +377,15 @@ class WorkOrder(Document):
|
||||
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))
|
||||
|
||||
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)
|
||||
|
||||
plan_reference.sales_order_item, 'work_order_qty', work_order_qty)
|
||||
|
||||
def update_completed_qty_in_material_request(self):
|
||||
if self.material_request:
|
||||
|
Loading…
x
Reference in New Issue
Block a user