From 253a0675924526811c990079eb845b7ea0fcd002 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 4 Apr 2025 13:38:45 +0530 Subject: [PATCH 1/2] fix: stock entry repack amount calculation (cherry picked from commit 544ceb93cd23045499246d2f21b1ab6419aeff44) # Conflicts: # erpnext/stock/stock_ledger.py --- .../doctype/stock_entry/test_stock_entry.py | 53 +++++++++++++++++++ erpnext/stock/stock_ledger.py | 9 ++++ 2 files changed, 62 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index bb7d944e639..53c739599ff 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -1835,6 +1835,59 @@ class TestStockEntry(FrappeTestCase): self.assertEqual(sle.stock_value_difference, 100) self.assertEqual(sle.stock_value, 100 * i) + def test_stock_entry_amount(self): + warehouse = "_Test Warehouse - _TC" + rm_item_code = "Test Stock Entry Amount 1" + make_item(rm_item_code, {"is_stock_item": 1}) + + fg_item_code = "Test Repack Stock Entry Amount 1" + make_item(fg_item_code, {"is_stock_item": 1}) + + make_stock_entry( + item_code=rm_item_code, + qty=1, + to_warehouse=warehouse, + basic_rate=200, + posting_date=nowdate(), + ) + + se = make_stock_entry( + item_code=rm_item_code, + qty=1, + purpose="Repack", + basic_rate=100, + do_not_save=True, + ) + + se.items[0].s_warehouse = warehouse + se.append( + "items", + { + "item_code": fg_item_code, + "qty": 1, + "t_warehouse": warehouse, + "uom": "Nos", + "conversion_factor": 1.0, + }, + ) + se.set_stock_entry_type() + se.submit() + + self.assertEqual(se.items[0].amount, 200) + self.assertEqual(se.items[0].basic_amount, 200) + + make_stock_entry( + item_code=rm_item_code, + qty=1, + to_warehouse=warehouse, + basic_rate=300, + posting_date=add_days(nowdate(), -1), + ) + + se.reload() + self.assertEqual(se.items[0].amount, 300) + self.assertEqual(se.items[0].basic_amount, 300) + def make_serialized_item(**args): args = frappe._dict(args) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 58c2fb51339..1fe77823aee 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -864,7 +864,16 @@ class update_entries_after: stock_entry.calculate_rate_and_amount(reset_outgoing_rate=False, raise_error_if_no_rate=False) stock_entry.db_update() for d in stock_entry.items: +<<<<<<< HEAD if d.name == voucher_detail_no or (not d.s_warehouse and d.t_warehouse): +======= + # Update only the row that matches the voucher_detail_no or the row containing the FG/Scrap Item. + if ( + d.name == voucher_detail_no + or (not d.s_warehouse and d.t_warehouse) + or stock_entry.purpose in ["Manufacture", "Repack"] + ): +>>>>>>> 544ceb93cd (fix: stock entry repack amount calculation) d.db_update() def update_rate_on_delivery_and_sales_return(self, sle, outgoing_rate): From 3f3fb323cfc99b616ec2ccb4292707ae9f606fed Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 14 Apr 2025 18:02:24 +0530 Subject: [PATCH 2/2] chore: fix conflicts --- erpnext/stock/stock_ledger.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 1fe77823aee..08a8262b246 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -864,16 +864,12 @@ class update_entries_after: stock_entry.calculate_rate_and_amount(reset_outgoing_rate=False, raise_error_if_no_rate=False) stock_entry.db_update() for d in stock_entry.items: -<<<<<<< HEAD - if d.name == voucher_detail_no or (not d.s_warehouse and d.t_warehouse): -======= # Update only the row that matches the voucher_detail_no or the row containing the FG/Scrap Item. if ( d.name == voucher_detail_no or (not d.s_warehouse and d.t_warehouse) or stock_entry.purpose in ["Manufacture", "Repack"] ): ->>>>>>> 544ceb93cd (fix: stock entry repack amount calculation) d.db_update() def update_rate_on_delivery_and_sales_return(self, sle, outgoing_rate):