mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 13:24:47 +00:00
feat: validate negative stock for inventory dimension (#37373)
* feat: validate negative stock for inventory dimension * test: test case for validate negative stock for inv dimension
This commit is contained in:
@@ -13,6 +13,7 @@ from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, now, nowdat
|
||||
|
||||
import erpnext
|
||||
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
|
||||
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions
|
||||
from erpnext.stock.utils import (
|
||||
get_incoming_outgoing_rate_for_cancel,
|
||||
get_or_make_bin,
|
||||
@@ -582,6 +583,13 @@ class update_entries_after(object):
|
||||
):
|
||||
sle.outgoing_rate = get_incoming_rate_for_inter_company_transfer(sle)
|
||||
|
||||
dimensions = get_inventory_dimensions()
|
||||
has_dimensions = False
|
||||
if dimensions:
|
||||
for dimension in dimensions:
|
||||
if sle.get(dimension.get("fieldname")):
|
||||
has_dimensions = True
|
||||
|
||||
if get_serial_nos(sle.serial_no):
|
||||
self.get_serialized_values(sle)
|
||||
self.wh_data.qty_after_transaction += flt(sle.actual_qty)
|
||||
@@ -596,7 +604,7 @@ class update_entries_after(object):
|
||||
):
|
||||
self.update_batched_values(sle)
|
||||
else:
|
||||
if sle.voucher_type == "Stock Reconciliation" and not sle.batch_no:
|
||||
if sle.voucher_type == "Stock Reconciliation" and not sle.batch_no and not has_dimensions:
|
||||
# assert
|
||||
self.wh_data.valuation_rate = sle.valuation_rate
|
||||
self.wh_data.qty_after_transaction = sle.qty_after_transaction
|
||||
@@ -1186,7 +1194,7 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
|
||||
return sle[0] if sle else frappe._dict()
|
||||
|
||||
|
||||
def get_previous_sle(args, for_update=False):
|
||||
def get_previous_sle(args, for_update=False, extra_cond=None):
|
||||
"""
|
||||
get the last sle on or before the current time-bucket,
|
||||
to get actual qty before transaction, this function
|
||||
@@ -1201,7 +1209,9 @@ def get_previous_sle(args, for_update=False):
|
||||
}
|
||||
"""
|
||||
args["name"] = args.get("sle", None) or ""
|
||||
sle = get_stock_ledger_entries(args, "<=", "desc", "limit 1", for_update=for_update)
|
||||
sle = get_stock_ledger_entries(
|
||||
args, "<=", "desc", "limit 1", for_update=for_update, extra_cond=extra_cond
|
||||
)
|
||||
return sle and sle[0] or {}
|
||||
|
||||
|
||||
@@ -1213,6 +1223,7 @@ def get_stock_ledger_entries(
|
||||
for_update=False,
|
||||
debug=False,
|
||||
check_serial_no=True,
|
||||
extra_cond=None,
|
||||
):
|
||||
"""get stock ledger entries filtered by specific posting datetime conditions"""
|
||||
conditions = " and timestamp(posting_date, posting_time) {0} timestamp(%(posting_date)s, %(posting_time)s)".format(
|
||||
@@ -1250,6 +1261,9 @@ def get_stock_ledger_entries(
|
||||
if operator in (">", "<=") and previous_sle.get("name"):
|
||||
conditions += " and name!=%(name)s"
|
||||
|
||||
if extra_cond:
|
||||
conditions += f"{extra_cond}"
|
||||
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select *, timestamp(posting_date, posting_time) as "timestamp"
|
||||
|
||||
Reference in New Issue
Block a user