mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
revert(stock): price Moving Average purchase returns at the moving average on repost
Reverts #60368. Keeping the purchase rate on repost lets a back-dated return take out more value than the warehouse holds, leaving positive qty at a negative stock value. Transfers from that warehouse then post to Stock Adjustment. SRBNB clears either way: a purchase return debits it at the purchase amount and books any gap to the expense account.
This commit is contained in:
@@ -5902,50 +5902,6 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
self.assertEqual(frappe.db.count("Stock Ledger Entry", {"voucher_no": pr.name}), sle_before)
|
||||
self.assertEqual(frappe.db.count("GL Entry", {"voucher_no": pr.name}), gle_before)
|
||||
|
||||
def test_moving_average_purchase_return_keeps_its_rate_on_repost(self):
|
||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||
|
||||
item = make_item(properties={"valuation_method": "Moving Average"}).name
|
||||
company = "_Test Company with perpetual inventory"
|
||||
warehouse = "Stores - TCP1"
|
||||
|
||||
pr = make_purchase_receipt(
|
||||
item_code=item,
|
||||
qty=10,
|
||||
rate=100,
|
||||
company=company,
|
||||
warehouse=warehouse,
|
||||
posting_date=add_days(today(), -3),
|
||||
)
|
||||
pr_return = make_purchase_receipt(
|
||||
item_code=item,
|
||||
qty=-5,
|
||||
rate=100,
|
||||
company=company,
|
||||
warehouse=warehouse,
|
||||
is_return=1,
|
||||
return_against=pr.name,
|
||||
posting_date=add_days(today(), -1),
|
||||
)
|
||||
|
||||
make_stock_entry(
|
||||
item_code=item,
|
||||
target=warehouse,
|
||||
qty=10,
|
||||
rate=300,
|
||||
company=company,
|
||||
posting_date=add_days(today(), -5),
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{"voucher_no": pr_return.name, "is_cancelled": 0},
|
||||
"stock_value_difference",
|
||||
),
|
||||
-500,
|
||||
)
|
||||
|
||||
def test_return_allowed_when_purchase_order_required(self):
|
||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_return
|
||||
|
||||
|
||||
@@ -575,10 +575,10 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin):
|
||||
return_pr.submit()
|
||||
|
||||
expected_sles = [
|
||||
{"outgoing_rate": 200.0, "stock_value_difference": -80000.0, "qty_after_transaction": 600.0},
|
||||
{"outgoing_rate": 200.0, "stock_value_difference": -20000.0, "qty_after_transaction": 500.0},
|
||||
{"outgoing_rate": 200.0, "stock_value_difference": -60000.0, "qty_after_transaction": 200.0},
|
||||
{"outgoing_rate": 200.0, "stock_value_difference": -20000.0, "qty_after_transaction": 100.0},
|
||||
{"outgoing_rate": 190.0, "valuation_rate": 190.0, "qty_after_transaction": 600.0},
|
||||
{"outgoing_rate": 190.0, "valuation_rate": 190.0, "qty_after_transaction": 500.0},
|
||||
{"outgoing_rate": 190.0, "valuation_rate": 190.0, "qty_after_transaction": 200.0},
|
||||
{"outgoing_rate": 190.0, "valuation_rate": 190.0, "qty_after_transaction": 100.0},
|
||||
]
|
||||
|
||||
for _ in range(2):
|
||||
|
||||
@@ -1560,7 +1560,6 @@ class update_entries_after:
|
||||
|
||||
if (
|
||||
self.valuation_method == "Moving Average"
|
||||
and sle.voucher_type in ("Delivery Note", "Sales Invoice")
|
||||
and not sle.get("serial_no")
|
||||
and not sle.get("batch_no")
|
||||
and not sle.get("serial_and_batch_bundle")
|
||||
|
||||
Reference in New Issue
Block a user