Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect Material Transferred for Manufacturing qty (backport #44823) #44832

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions erpnext/manufacturing/doctype/job_card/job_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,9 @@ def set_transferred_qty(self, update_status=False):
if doc.transfer_material_against == "Job Card" and not doc.skip_transfer:
min_qty = []
for d in doc.operations:
if d.completed_qty:
min_qty.append(d.completed_qty)
completed_qty = flt(d.completed_qty) + flt(d.process_loss_qty)
if completed_qty:
min_qty.append(completed_qty)
else:
min_qty = []
break
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
Loading