From 3d19af81ba53d2cad2cdb7360df17d887718c8d0 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 23 Dec 2024 10:57:47 +0530 Subject: [PATCH 1/2] fix: incorrect Material Transferred for Manufacturing qty (#44823) (cherry picked from commit fe0036e707252f5842444a5cb728410cb81fe6ca) # Conflicts: # erpnext/manufacturing/doctype/job_card/job_card.py --- .../doctype/job_card/job_card.py | 27 +++++++++ .../doctype/work_order/test_work_order.py | 55 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index 586371090770..e4188bc60fc4 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -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 diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index 6ee3f73eb084..f8ddf0074283 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -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, @@ -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} From 93846626b174cd1093710ec7beacc26a70530087 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 23 Dec 2024 13:14:09 +0530 Subject: [PATCH 2/2] chore: fix conflicts --- .../doctype/job_card/job_card.py | 32 ++----------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index e4188bc60fc4..011df3258eed 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -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 @@ -957,33 +958,6 @@ 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