fix: stock entry repack amount calculation

(cherry picked from commit 544ceb93cd)
This commit is contained in:
Rohit Waghchaure
2025-04-04 13:38:45 +05:30
committed by Mergify
parent 51c18217fa
commit 8c61639062
2 changed files with 58 additions and 1 deletions

View File

@@ -1907,6 +1907,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)

View File

@@ -1238,7 +1238,11 @@ class update_entries_after:
stock_entry.db_update()
for d in stock_entry.items:
# 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):
if (
d.name == voucher_detail_no
or (not d.s_warehouse and d.t_warehouse)
or stock_entry.purpose in ["Manufacture", "Repack"]
):
d.db_update()
def update_rate_on_delivery_and_sales_return(self, sle, outgoing_rate):