fix: incorrect status in the work order
This commit is contained in:
parent
f4a1218467
commit
b0baba84a0
@ -890,6 +890,9 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
self.assertEqual(se.process_loss_percentage, 10)
|
self.assertEqual(se.process_loss_percentage, 10)
|
||||||
self.assertEqual(se.process_loss_qty, 1)
|
self.assertEqual(se.process_loss_qty, 1)
|
||||||
|
|
||||||
|
wo.load_from_db()
|
||||||
|
self.assertEqual(wo.status, "In Process")
|
||||||
|
|
||||||
@timeout(seconds=60)
|
@timeout(seconds=60)
|
||||||
def test_job_card_scrap_item(self):
|
def test_job_card_scrap_item(self):
|
||||||
items = [
|
items = [
|
||||||
|
|||||||
@ -246,20 +246,10 @@ class WorkOrder(Document):
|
|||||||
status = "Draft"
|
status = "Draft"
|
||||||
elif self.docstatus == 1:
|
elif self.docstatus == 1:
|
||||||
if status != "Stopped":
|
if status != "Stopped":
|
||||||
stock_entries = frappe._dict(
|
|
||||||
frappe.db.sql(
|
|
||||||
"""select purpose, sum(fg_completed_qty)
|
|
||||||
from `tabStock Entry` where work_order=%s and docstatus=1
|
|
||||||
group by purpose""",
|
|
||||||
self.name,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
status = "Not Started"
|
status = "Not Started"
|
||||||
if stock_entries:
|
if flt(self.material_transferred_for_manufacturing) > 0:
|
||||||
status = "In Process"
|
status = "In Process"
|
||||||
produced_qty = stock_entries.get("Manufacture")
|
if flt(self.produced_qty) >= flt(self.qty):
|
||||||
if flt(produced_qty) >= flt(self.qty):
|
|
||||||
status = "Completed"
|
status = "Completed"
|
||||||
else:
|
else:
|
||||||
status = "Cancelled"
|
status = "Cancelled"
|
||||||
@ -309,12 +299,15 @@ class WorkOrder(Document):
|
|||||||
|
|
||||||
def get_transferred_or_manufactured_qty(self, purpose):
|
def get_transferred_or_manufactured_qty(self, purpose):
|
||||||
table = frappe.qb.DocType("Stock Entry")
|
table = frappe.qb.DocType("Stock Entry")
|
||||||
query = (
|
query = frappe.qb.from_(table).where(
|
||||||
frappe.qb.from_(table)
|
(table.work_order == self.name) & (table.docstatus == 1) & (table.purpose == purpose)
|
||||||
.select(Sum(table.fg_completed_qty))
|
|
||||||
.where((table.work_order == self.name) & (table.docstatus == 1) & (table.purpose == purpose))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if purpose == "Manufacture":
|
||||||
|
query = query.select(Sum(table.fg_completed_qty) - Sum(table.process_loss_qty))
|
||||||
|
else:
|
||||||
|
query = query.select(Sum(table.fg_completed_qty))
|
||||||
|
|
||||||
return flt(query.run()[0][0])
|
return flt(query.run()[0][0])
|
||||||
|
|
||||||
def set_process_loss_qty(self):
|
def set_process_loss_qty(self):
|
||||||
@ -346,6 +339,7 @@ class WorkOrder(Document):
|
|||||||
|
|
||||||
produced_qty = total_qty[0][0] if total_qty else 0
|
produced_qty = total_qty[0][0] if total_qty else 0
|
||||||
|
|
||||||
|
self.update_status()
|
||||||
production_plan.run_method(
|
production_plan.run_method(
|
||||||
"update_produced_pending_qty", produced_qty, self.production_plan_item
|
"update_produced_pending_qty", produced_qty, self.production_plan_item
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1244,7 +1244,6 @@ class StockEntry(StockController):
|
|||||||
if self.work_order:
|
if self.work_order:
|
||||||
pro_doc = frappe.get_doc("Work Order", self.work_order)
|
pro_doc = frappe.get_doc("Work Order", self.work_order)
|
||||||
_validate_work_order(pro_doc)
|
_validate_work_order(pro_doc)
|
||||||
pro_doc.run_method("update_status")
|
|
||||||
|
|
||||||
if self.fg_completed_qty:
|
if self.fg_completed_qty:
|
||||||
pro_doc.run_method("update_work_order_qty")
|
pro_doc.run_method("update_work_order_qty")
|
||||||
@ -1252,6 +1251,7 @@ class StockEntry(StockController):
|
|||||||
pro_doc.run_method("update_planned_qty")
|
pro_doc.run_method("update_planned_qty")
|
||||||
pro_doc.update_batch_produced_qty(self)
|
pro_doc.update_batch_produced_qty(self)
|
||||||
|
|
||||||
|
pro_doc.run_method("update_status")
|
||||||
if not pro_doc.operations:
|
if not pro_doc.operations:
|
||||||
pro_doc.set_actual_dates()
|
pro_doc.set_actual_dates()
|
||||||
|
|
||||||
@ -1494,6 +1494,7 @@ class StockEntry(StockController):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.process_loss_qty = 0.0
|
self.process_loss_qty = 0.0
|
||||||
|
if not self.process_loss_percentage:
|
||||||
self.process_loss_percentage = frappe.get_cached_value(
|
self.process_loss_percentage = frappe.get_cached_value(
|
||||||
"BOM", self.bom_no, "process_loss_percentage"
|
"BOM", self.bom_no, "process_loss_percentage"
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user