* fix: reposting not fixing valuation rate for sales return using movin… (#38895) fix: reposting not fixing valuation rate for sales return using moving average method (cherry picked from commit 3a668bbe9694fdd6e8265869c6943e42f889ac41) # Conflicts: # erpnext/stock/stock_ledger.py * chore: fix conflicts --------- Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
parent
61219ca4ce
commit
07175367d8
@ -438,7 +438,9 @@ class SellingController(StockController):
|
|||||||
# Get incoming rate based on original item cost based on valuation method
|
# Get incoming rate based on original item cost based on valuation method
|
||||||
qty = flt(d.get("stock_qty") or d.get("actual_qty"))
|
qty = flt(d.get("stock_qty") or d.get("actual_qty"))
|
||||||
|
|
||||||
if not d.incoming_rate:
|
if not d.incoming_rate or (
|
||||||
|
get_valuation_method(d.item_code) == "Moving Average" and self.get("is_return")
|
||||||
|
):
|
||||||
d.incoming_rate = get_incoming_rate(
|
d.incoming_rate = get_incoming_rate(
|
||||||
{
|
{
|
||||||
"item_code": d.item_code,
|
"item_code": d.item_code,
|
||||||
|
|||||||
@ -1425,6 +1425,59 @@ class TestDeliveryNote(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertAlmostEqual(dn1.items[0].incoming_rate, 250.0)
|
self.assertAlmostEqual(dn1.items[0].incoming_rate, 250.0)
|
||||||
|
|
||||||
|
def test_sales_return_valuation_for_moving_average_case2(self):
|
||||||
|
# Make DN return
|
||||||
|
# Make Bakcdated Purchase Receipt and check DN return valuation rate
|
||||||
|
# The rate should be recalculate based on the backdated purchase receipt
|
||||||
|
frappe.flags.print_debug_messages = False
|
||||||
|
item_code = make_item(
|
||||||
|
"_Test Item Sales Return with MA Case2",
|
||||||
|
{"is_stock_item": 1, "valuation_method": "Moving Average", "stock_uom": "Nos"},
|
||||||
|
).name
|
||||||
|
|
||||||
|
make_stock_entry(
|
||||||
|
item_code=item_code,
|
||||||
|
target="_Test Warehouse - _TC",
|
||||||
|
qty=5,
|
||||||
|
basic_rate=100.0,
|
||||||
|
posting_date=add_days(nowdate(), -5),
|
||||||
|
)
|
||||||
|
|
||||||
|
dn = create_delivery_note(
|
||||||
|
item_code=item_code,
|
||||||
|
warehouse="_Test Warehouse - _TC",
|
||||||
|
qty=5,
|
||||||
|
rate=500,
|
||||||
|
posting_date=add_days(nowdate(), -4),
|
||||||
|
)
|
||||||
|
|
||||||
|
returned_dn = create_delivery_note(
|
||||||
|
is_return=1,
|
||||||
|
item_code=item_code,
|
||||||
|
return_against=dn.name,
|
||||||
|
qty=-5,
|
||||||
|
rate=500,
|
||||||
|
company=dn.company,
|
||||||
|
warehouse="_Test Warehouse - _TC",
|
||||||
|
expense_account="Cost of Goods Sold - _TC",
|
||||||
|
cost_center="Main - _TC",
|
||||||
|
posting_date=add_days(nowdate(), -1),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertAlmostEqual(returned_dn.items[0].incoming_rate, 100.0)
|
||||||
|
|
||||||
|
# Make backdated purchase receipt
|
||||||
|
make_stock_entry(
|
||||||
|
item_code=item_code,
|
||||||
|
target="_Test Warehouse - _TC",
|
||||||
|
qty=5,
|
||||||
|
basic_rate=200.0,
|
||||||
|
posting_date=add_days(nowdate(), -3),
|
||||||
|
)
|
||||||
|
|
||||||
|
returned_dn.reload()
|
||||||
|
self.assertAlmostEqual(returned_dn.items[0].incoming_rate, 200.0)
|
||||||
|
|
||||||
|
|
||||||
def create_delivery_note(**args):
|
def create_delivery_note(**args):
|
||||||
dn = frappe.new_doc("Delivery Note")
|
dn = frappe.new_doc("Delivery Note")
|
||||||
|
|||||||
@ -25,6 +25,7 @@ from erpnext.stock.doctype.stock_reservation_entry.stock_reservation_entry impor
|
|||||||
)
|
)
|
||||||
from erpnext.stock.utils import (
|
from erpnext.stock.utils import (
|
||||||
get_incoming_outgoing_rate_for_cancel,
|
get_incoming_outgoing_rate_for_cancel,
|
||||||
|
get_incoming_rate,
|
||||||
get_or_make_bin,
|
get_or_make_bin,
|
||||||
get_stock_balance,
|
get_stock_balance,
|
||||||
get_valuation_method,
|
get_valuation_method,
|
||||||
@ -841,6 +842,26 @@ class update_entries_after(object):
|
|||||||
get_rate_for_return, # don't move this import to top
|
get_rate_for_return, # don't move this import to top
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.valuation_method == "Moving Average":
|
||||||
|
rate = get_incoming_rate(
|
||||||
|
{
|
||||||
|
"item_code": sle.item_code,
|
||||||
|
"warehouse": sle.warehouse,
|
||||||
|
"posting_date": sle.posting_date,
|
||||||
|
"posting_time": sle.posting_time,
|
||||||
|
"qty": sle.actual_qty,
|
||||||
|
"serial_no": sle.get("serial_no"),
|
||||||
|
"batch_no": sle.get("batch_no"),
|
||||||
|
"serial_and_batch_bundle": sle.get("serial_and_batch_bundle"),
|
||||||
|
"company": sle.company,
|
||||||
|
"voucher_type": sle.voucher_type,
|
||||||
|
"voucher_no": sle.voucher_no,
|
||||||
|
"allow_zero_valuation": self.allow_zero_rate,
|
||||||
|
"sle": sle.name,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
rate = get_rate_for_return(
|
rate = get_rate_for_return(
|
||||||
sle.voucher_type,
|
sle.voucher_type,
|
||||||
sle.voucher_no,
|
sle.voucher_no,
|
||||||
@ -848,7 +869,6 @@ class update_entries_after(object):
|
|||||||
voucher_detail_no=sle.voucher_detail_no,
|
voucher_detail_no=sle.voucher_detail_no,
|
||||||
sle=sle,
|
sle=sle,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif (
|
elif (
|
||||||
sle.voucher_type in ["Purchase Receipt", "Purchase Invoice"]
|
sle.voucher_type in ["Purchase Receipt", "Purchase Invoice"]
|
||||||
and sle.voucher_detail_no
|
and sle.voucher_detail_no
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user