Skip to content

Commit

Permalink
fix: reposting has not changed valuation rate
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Jul 1, 2023
1 parent 7d010ad commit 22f343c
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
114 changes: 114 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,120 @@ def test_purchase_return_valuation_with_rejected_qty(self):

self.assertEqual(abs(data["stock_value_difference"]), 400.00)

def test_purchase_receipt_with_backdated_landed_cost_vouucher(self):
from erpnext.controllers.sales_and_purchase_return import make_return_doc
from erpnext.stock.doctype.landed_cost_voucher.test_landed_cost_voucher import (
create_landed_cost_voucher,
)
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry

item_code = "_Test Purchase Item With Landed Cost"
create_item(item_code)

warehouse = create_warehouse("_Test Purchase Warehouse With Landed Cost")
warehouse1 = create_warehouse("_Test Purchase Warehouse With Landed Cost 1")
warehouse2 = create_warehouse("_Test Purchase Warehouse With Landed Cost 2")
warehouse3 = create_warehouse("_Test Purchase Warehouse With Landed Cost 3")

pr = make_purchase_receipt(
item_code=item_code,
warehouse=warehouse,
posting_date=add_days(today(), -10),
posting_time="10:59:59",
qty=100,
rate=275.00,
)

pr_return = make_return_doc("Purchase Receipt", pr.name)
pr_return.posting_date = add_days(today(), -9)
pr_return.items[0].qty = 2 * -1
pr_return.submit()

ste1 = make_stock_entry(
purpose="Material Transfer",
posting_date=add_days(today(), -8),
source=warehouse,
target=warehouse1,
item_code=item_code,
qty=20,
company=pr.company,
)

ste1.reload()
self.assertEqual(ste1.valuation_rate, 275.00)

ste2 = make_stock_entry(
purpose="Material Transfer",
posting_date=add_days(today(), -7),
source=warehouse,
target=warehouse2,
item_code=item_code,
qty=20,
company=pr.company,
)

ste2.reload()
self.assertEqual(ste2.valuation_rate, 275.00)

ste3 = make_stock_entry(
purpose="Material Transfer",
posting_date=add_days(today(), -6),
source=warehouse,
target=warehouse3,
item_code=item_code,
qty=20,
company=pr.company,
)

ste3.reload()
self.assertEqual(ste3.valuation_rate, 275.00)

ste4 = make_stock_entry(
purpose="Material Transfer",
posting_date=add_days(today(), -5),
source=warehouse1,
target=warehouse,
item_code=item_code,
qty=20,
company=pr.company,
)

ste4.reload()
self.assertEqual(ste4.valuation_rate, 275.00)

ste5 = make_stock_entry(
purpose="Material Transfer",
posting_date=add_days(today(), -4),
source=warehouse,
target=warehouse1,
item_code=item_code,
qty=20,
company=pr.company,
)

ste5.reload()
self.assertEqual(ste5.valuation_rate, 275.00)

create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company, charges=2500 * -1)

pr.reload()
valuation_rate = pr.items[0].valuation_rate

ste1.reload()
self.assertEqual(ste1.items[0].valuation_rate, valuation_rate)

ste2.reload()
self.assertEqual(ste2.items[0].valuation_rate, valuation_rate)

ste3.reload()
self.assertEqual(ste3.items[0].valuation_rate, valuation_rate)

ste4.reload()
self.assertEqual(ste4.items[0].valuation_rate, valuation_rate)

ste5.reload()
self.assertEqual(ste5.items[0].valuation_rate, valuation_rate)


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
Expand Down
6 changes: 6 additions & 0 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def get_dependent_entries_to_fix(self, entries_to_fix, sle):
def update_distinct_item_warehouses(self, dependant_sle):
key = (dependant_sle.item_code, dependant_sle.warehouse)
val = frappe._dict({"sle": dependant_sle})

if key not in self.distinct_item_warehouses:
self.distinct_item_warehouses[key] = val
self.new_items_found = True
Expand All @@ -524,6 +525,9 @@ def update_distinct_item_warehouses(self, dependant_sle):
val.sle_changed = True
self.distinct_item_warehouses[key] = val
self.new_items_found = True
elif self.distinct_item_warehouses[key].get("reposting_status"):
self.distinct_item_warehouses[key] = val
self.new_items_found = True

def process_sle(self, sle):
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
Expand Down Expand Up @@ -1255,6 +1259,8 @@ def get_sle_by_voucher_detail_no(voucher_detail_no, excluded_sle=None):
[
"item_code",
"warehouse",
"actual_qty",
"qty_after_transaction",
"posting_date",
"posting_time",
"timestamp(posting_date, posting_time) as timestamp",
Expand Down

0 comments on commit 22f343c

Please sign in to comment.