From ca9c6e1651ac3bdb0e4e4c001d9ad5edbfc5edf6 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 12 Jul 2022 13:00:00 +0530 Subject: [PATCH] test: LCV impact on future stock balancees (cherry picked from commit de9ea70ce369377798734381de99a7be15ab35fd) --- .../test_landed_cost_voucher.py | 67 +++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index 1af99534516..790d284a3dc 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -4,7 +4,7 @@ import frappe from frappe.tests.utils import FrappeTestCase -from frappe.utils import add_to_date, flt, now +from frappe.utils import add_days, add_to_date, flt, now from erpnext.accounts.doctype.account.test_account import create_account, get_inventory_account from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice @@ -120,6 +120,61 @@ class TestLandedCostVoucher(FrappeTestCase): expected_values[gle.account][1], gle.credit, msg=f"incorrect credit for {gle.account}" ) + def test_landed_cost_voucher_stock_impact(self): + "Test impact of LCV on future stock balances." + from erpnext.stock.doctype.item.test_item import make_item + + item = make_item("LCV Stock Item", {"is_stock_item": 1}) + warehouse = "Stores - _TC" + + pr1 = make_purchase_receipt( + item_code=item.name, + warehouse=warehouse, + qty=500, + rate=80, + posting_date=add_days(frappe.utils.nowdate(), -2), + ) + pr2 = make_purchase_receipt( + item_code=item.name, + warehouse=warehouse, + qty=100, + rate=80, + posting_date=frappe.utils.nowdate(), + ) + + last_sle = frappe.db.get_value( # SLE of second PR + "Stock Ledger Entry", + { + "voucher_type": pr2.doctype, + "voucher_no": pr2.name, + "item_code": item.name, + "warehouse": warehouse, + "is_cancelled": 0, + }, + fieldname=["qty_after_transaction", "stock_value"], + as_dict=1, + ) + + create_landed_cost_voucher("Purchase Receipt", pr1.name, pr1.company) + + last_sle_after_landed_cost = frappe.db.get_value( # SLE of second PR after LCV's effect + "Stock Ledger Entry", + { + "voucher_type": pr2.doctype, + "voucher_no": pr2.name, + "item_code": item.name, + "warehouse": warehouse, + "is_cancelled": 0, + }, + fieldname=["qty_after_transaction", "stock_value"], + as_dict=1, + ) + + self.assertEqual( + last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction + ) + self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 50.0) + def test_landed_cost_voucher_against_purchase_invoice(self): pi = make_purchase_invoice( @@ -219,11 +274,11 @@ class TestLandedCostVoucher(FrappeTestCase): landed costs, this should be allowed for serial nos too. Case: - - receipt a serial no @ X rate - - delivery the serial no @ X rate - - add LCV to receipt X + Y - - LCV should be successful - - delivery should reflect X+Y valuation. + - receipt a serial no @ X rate + - delivery the serial no @ X rate + - add LCV to receipt X + Y + - LCV should be successful + - delivery should reflect X+Y valuation. """ serial_no = "LCV_TEST_SR_NO" item_code = "_Test Serialized Item"