refactor: created separate function to update work_order on cancel
This commit is contained in:
parent
56f697052c
commit
93c22ebbb9
@ -242,8 +242,8 @@ class WorkOrder(Document):
|
|||||||
frappe.throw(_("For Warehouse is required before Submit"))
|
frappe.throw(_("For Warehouse is required before Submit"))
|
||||||
|
|
||||||
prod_plan = frappe.get_doc('Production Plan', self.production_plan)
|
prod_plan = frappe.get_doc('Production Plan', self.production_plan)
|
||||||
pp_ref = prod_plan.prod_plan_ref
|
|
||||||
if pp_ref:
|
if prod_plan.prod_plan_ref:
|
||||||
self.update_work_order_qty_in_combined_so()
|
self.update_work_order_qty_in_combined_so()
|
||||||
else:
|
else:
|
||||||
self.update_work_order_qty_in_so()
|
self.update_work_order_qty_in_so()
|
||||||
@ -259,9 +259,9 @@ class WorkOrder(Document):
|
|||||||
|
|
||||||
frappe.db.set(self,'status', 'Cancelled')
|
frappe.db.set(self,'status', 'Cancelled')
|
||||||
prod_plan = frappe.get_doc('Production Plan', self.production_plan)
|
prod_plan = frappe.get_doc('Production Plan', self.production_plan)
|
||||||
pp_ref = prod_plan.prod_plan_ref
|
|
||||||
if pp_ref:
|
if prod_plan.prod_plan_ref:
|
||||||
self.update_work_order_qty_in_combined_so(cancel = True)
|
self.update_work_order_combined_on_cancel()
|
||||||
else:
|
else:
|
||||||
self.update_work_order_qty_in_so()
|
self.update_work_order_qty_in_so()
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ class WorkOrder(Document):
|
|||||||
frappe.db.set_value('Sales Order Item',
|
frappe.db.set_value('Sales Order Item',
|
||||||
self.sales_order_item, 'work_order_qty', flt(work_order_qty/total_bundle_qty, 2))
|
self.sales_order_item, 'work_order_qty', flt(work_order_qty/total_bundle_qty, 2))
|
||||||
|
|
||||||
def update_work_order_qty_in_combined_so(self, cancel = None):
|
def update_work_order_qty_in_combined_so(self):
|
||||||
total_bundle_qty = 1
|
total_bundle_qty = 1
|
||||||
if self.product_bundle_item:
|
if self.product_bundle_item:
|
||||||
total_bundle_qty = frappe.db.sql(""" select sum(qty) from
|
total_bundle_qty = frappe.db.sql(""" select sum(qty) from
|
||||||
@ -381,14 +381,22 @@ class WorkOrder(Document):
|
|||||||
total_bundle_qty = 1
|
total_bundle_qty = 1
|
||||||
|
|
||||||
prod_plan = frappe.get_doc('Production Plan', self.production_plan)
|
prod_plan = frappe.get_doc('Production Plan', self.production_plan)
|
||||||
pp_ref = prod_plan.prod_plan_ref
|
|
||||||
pp_item = frappe.get_doc('Production Plan Item', self.production_plan_item)
|
pp_item = frappe.get_doc('Production Plan Item', self.production_plan_item)
|
||||||
item_ref = pp_item.item_reference
|
|
||||||
for p in pp_ref:
|
for p in prod_plan.prod_plan_ref:
|
||||||
if p.item_ref == item_ref:
|
if p.item_ref == pp_item.item_reference:
|
||||||
work_order_qty = int(p.qty) if not cancel else 0
|
work_order_qty = int(p.qty)
|
||||||
frappe.db.set_value('Sales Order Item',
|
frappe.db.set_value('Sales Order Item',
|
||||||
p.sales_order_item, 'work_order_qty', flt(work_order_qty/total_bundle_qty, 2))
|
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)
|
||||||
|
|
||||||
|
|
||||||
def update_completed_qty_in_material_request(self):
|
def update_completed_qty_in_material_request(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user