Skip to content

Commit

Permalink
chore: fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Feb 27, 2024
1 parent 2221e2d commit 66e6229
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import frappe
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, cint, cstr, flt, today, nowtime
from frappe.utils import add_days, cint, cstr, flt, nowtime, today
from pypika import functions as fn

import erpnext
Expand Down
27 changes: 15 additions & 12 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,18 +1398,21 @@ def get_valuation_rate(
)

# Get valuation rate from last sle for the same item and warehouse
if last_valuation_rate := frappe.db.sql(
"""select valuation_rate
from `tabStock Ledger Entry` force index (item_warehouse)
where
item_code = %s
AND warehouse = %s
AND valuation_rate >= 0
AND is_cancelled = 0
AND NOT (voucher_no = %s AND voucher_type = %s)
order by posting_datetime desc, name desc limit 1""",
(item_code, warehouse, voucher_no, voucher_type),
):
if not last_valuation_rate or last_valuation_rate[0][0] is None:
last_valuation_rate = frappe.db.sql(
"""select valuation_rate
from `tabStock Ledger Entry` force index (item_warehouse)
where
item_code = %s
AND warehouse = %s
AND valuation_rate >= 0
AND is_cancelled = 0
AND NOT (voucher_no = %s AND voucher_type = %s)
order by posting_datetime desc, name desc limit 1""",
(item_code, warehouse, voucher_no, voucher_type),
)

if last_valuation_rate:
return flt(last_valuation_rate[0][0])

# If negative stock allowed, and item delivered without any incoming entry,
Expand Down

0 comments on commit 66e6229

Please sign in to comment.