Skip to content

Commit

Permalink
Merge pull request frappe#33548 from rohitwaghchaure/fixed-incorrect-…
Browse files Browse the repository at this point in the history
…wo-status

fix: incorrect status in the work order
  • Loading branch information
rohitwaghchaure authored Jan 6, 2023
2 parents 51b082b + b0baba8 commit 525f054
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
3 changes: 3 additions & 0 deletions erpnext/manufacturing/doctype/work_order/test_work_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ def test_wo_completion_with_pl_bom(self):
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 = [
Expand Down
28 changes: 11 additions & 17 deletions erpnext/manufacturing/doctype/work_order/work_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,11 @@ def get_status(self, status=None):
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"

Expand Down Expand Up @@ -309,12 +299,15 @@ def update_work_order_qty(self):

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):
Expand Down Expand Up @@ -346,6 +339,7 @@ def update_production_plan_status(self):

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
)
Expand Down
9 changes: 5 additions & 4 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,14 +1244,14 @@ def _validate_work_order(pro_doc):
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")
if self.purpose == "Manufacture":
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()

Expand Down Expand Up @@ -1494,9 +1494,10 @@ def set_process_loss_qty(self):
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(
Expand Down

0 comments on commit 525f054

Please sign in to comment.