Skip to content

Commit

Permalink
fix: incorrect Material Transferred for Manufacturing qty (#44823)
Browse files Browse the repository at this point in the history
(cherry picked from commit fe0036e)

# Conflicts:
#	erpnext/manufacturing/doctype/job_card/job_card.py
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Dec 23, 2024
1 parent 4869847 commit 3d19af8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
27 changes: 27 additions & 0 deletions erpnext/manufacturing/doctype/job_card/job_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,33 @@ def set_transferred_qty(self, update_status=False):

self.set_status(update_status)

<<<<<<< HEAD
=======
if self.work_order and not frappe.get_cached_value(
"Work Order", self.work_order, "track_semi_finished_goods"
):
self.set_transferred_qty_in_work_order()

def set_transferred_qty_in_work_order(self):
doc = frappe.get_doc("Work Order", self.work_order)

qty = 0.0
if doc.transfer_material_against == "Job Card" and not doc.skip_transfer:
min_qty = []
for d in doc.operations:
completed_qty = flt(d.completed_qty) + flt(d.process_loss_qty)
if completed_qty:
min_qty.append(completed_qty)
else:
min_qty = []
break

if min_qty:
qty = min(min_qty)

doc.db_set("material_transferred_for_manufacturing", qty)

>>>>>>> fe0036e707 (fix: incorrect Material Transferred for Manufacturing qty (#44823))
def set_status(self, update_status=False):
if self.status == "On Hold" and self.docstatus == 0:
return
Expand Down
55 changes: 55 additions & 0 deletions erpnext/manufacturing/doctype/work_order/test_work_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from frappe.utils import add_days, add_months, add_to_date, cint, flt, now, today

from erpnext.manufacturing.doctype.job_card.job_card import JobCardCancelError
from erpnext.manufacturing.doctype.job_card.job_card import make_stock_entry as make_stock_entry_from_jc
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
from erpnext.manufacturing.doctype.work_order.work_order import (
CapacityError,
Expand Down Expand Up @@ -505,6 +506,60 @@ def test_job_card(self):
for stock_entry in stock_entries:
stock_entry.cancel()

def test_work_order_material_transferred_qty_with_process_loss(self):
stock_entries = []
bom = frappe.get_doc("BOM", {"docstatus": 1, "with_operations": 1, "company": "_Test Company"})

work_order = make_wo_order_test_record(
item=bom.item,
qty=2,
bom_no=bom.name,
source_warehouse="_Test Warehouse - _TC",
transfer_material_against="Job Card",
)

self.assertEqual(work_order.qty, 2)

for row in work_order.required_items:
stock_entry_doc = test_stock_entry.make_stock_entry(
item_code=row.item_code, target="_Test Warehouse - _TC", qty=row.required_qty, basic_rate=100
)
stock_entries.append(stock_entry_doc)

job_cards = frappe.get_all(
"Job Card", filters={"work_order": work_order.name}, order_by="creation asc"
)

for row in job_cards:
transfer_entry_1 = make_stock_entry_from_jc(row.name)
transfer_entry_1.submit()

doc = frappe.get_doc("Job Card", row.name)
for row in doc.scheduled_time_logs:
doc.append(
"time_logs",
{
"from_time": row.from_time,
"to_time": row.to_time,
"time_in_mins": row.time_in_mins,
"completed_qty": 1,
},
)

doc.save()
doc.submit()

self.assertEqual(doc.total_completed_qty, 1)
self.assertEqual(doc.process_loss_qty, 1)

work_order.reload()

self.assertEqual(work_order.material_transferred_for_manufacturing, 2)

for row in work_order.operations:
self.assertEqual(row.completed_qty, 1)
self.assertEqual(row.process_loss_qty, 1)

def test_capcity_planning(self):
frappe.db.set_single_value(
"Manufacturing Settings", {"disable_capacity_planning": 0, "capacity_planning_for_days": 1}
Expand Down

0 comments on commit 3d19af8

Please sign in to comment.