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_qty, 1)
|
||||
|
||||
wo.load_from_db()
|
||||
self.assertEqual(wo.status, "In Process")
|
||||
|
||||
@timeout(seconds=60)
|
||||
def test_job_card_scrap_item(self):
|
||||
items = [
|
||||
|
@ -246,21 +246,11 @@ class WorkOrder(Document):
|
||||
status = "Draft"
|
||||
elif self.docstatus == 1:
|
||||
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"
|
||||
if stock_entries:
|
||||
if flt(self.material_transferred_for_manufacturing) > 0:
|
||||
status = "In Process"
|
||||
produced_qty = stock_entries.get("Manufacture")
|
||||
if flt(produced_qty) >= flt(self.qty):
|
||||
status = "Completed"
|
||||
if flt(self.produced_qty) >= flt(self.qty):
|
||||
status = "Completed"
|
||||
else:
|
||||
status = "Cancelled"
|
||||
|
||||
@ -309,12 +299,15 @@ class WorkOrder(Document):
|
||||
|
||||
def get_transferred_or_manufactured_qty(self, purpose):
|
||||
table = frappe.qb.DocType("Stock Entry")
|
||||
query = (
|
||||
frappe.qb.from_(table)
|
||||
.select(Sum(table.fg_completed_qty))
|
||||
.where((table.work_order == self.name) & (table.docstatus == 1) & (table.purpose == purpose))
|
||||
query = frappe.qb.from_(table).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])
|
||||
|
||||
def set_process_loss_qty(self):
|
||||
@ -346,6 +339,7 @@ class WorkOrder(Document):
|
||||
|
||||
produced_qty = total_qty[0][0] if total_qty else 0
|
||||
|
||||
self.update_status()
|
||||
production_plan.run_method(
|
||||
"update_produced_pending_qty", produced_qty, self.production_plan_item
|
||||
)
|
||||
|
@ -1244,7 +1244,6 @@ class StockEntry(StockController):
|
||||
if self.work_order:
|
||||
pro_doc = frappe.get_doc("Work Order", self.work_order)
|
||||
_validate_work_order(pro_doc)
|
||||
pro_doc.run_method("update_status")
|
||||
|
||||
if self.fg_completed_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.update_batch_produced_qty(self)
|
||||
|
||||
pro_doc.run_method("update_status")
|
||||
if not pro_doc.operations:
|
||||
pro_doc.set_actual_dates()
|
||||
|
||||
@ -1494,9 +1494,10 @@ class StockEntry(StockController):
|
||||
return
|
||||
|
||||
self.process_loss_qty = 0.0
|
||||
self.process_loss_percentage = frappe.get_cached_value(
|
||||
"BOM", self.bom_no, "process_loss_percentage"
|
||||
)
|
||||
if not self.process_loss_percentage:
|
||||
self.process_loss_percentage = frappe.get_cached_value(
|
||||
"BOM", self.bom_no, "process_loss_percentage"
|
||||
)
|
||||
|
||||
if self.process_loss_percentage:
|
||||
self.process_loss_qty = flt(
|
||||
|
Loading…
x
Reference in New Issue
Block a user