fix: warning message for negative stock (backport #42683) (#42709)

* fix: warning message for negative stock (#42683)

(cherry picked from commit deccb007c1)

# Conflicts:
#	erpnext/stock/stock_ledger.py

* chore: fix conflicts

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-08-12 11:20:44 +05:30
committed by GitHub
parent a43136da5d
commit e44daf73fb

View File

@@ -4,10 +4,10 @@
import json
import frappe
from frappe import _
from frappe import _, bold
from frappe.model.meta import get_field_precision
from frappe.query_builder.functions import Sum
from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, now, nowdate
from frappe.utils import cint, cstr, flt, format_date, get_link_to_form, getdate, now, nowdate
import erpnext
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
@@ -542,11 +542,31 @@ class update_entries_after:
return self.distinct_item_warehouses[key].dependent_voucher_detail_nos
def validate_previous_sle_qty(self, sle):
previous_sle = self.data[sle.warehouse].previous_sle
if previous_sle and previous_sle.get("qty_after_transaction") < 0 and sle.get("actual_qty") > 0:
frappe.msgprint(
_(
"The stock for the item {0} in the {1} warehouse was negative on the {2}. You should create a positive entry {3} before the date {4} and time {5} to post the correct valuation rate. For more details, please read the <a href='https://docs.erpnext.com/docs/user/manual/en/stock-adjustment-cogs-with-negative-stock'>documentation<a>."
).format(
bold(sle.item_code),
bold(sle.warehouse),
bold(format_date(previous_sle.posting_date)),
sle.voucher_no,
bold(format_date(previous_sle.posting_date)),
bold(previous_sle.posting_time),
),
title=_("Warning on Negative Stock"),
indicator="blue",
)
def process_sle(self, sle):
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
# previous sle data for this warehouse
self.wh_data = self.data[sle.warehouse]
self.validate_previous_sle_qty(sle)
self.affected_transactions.add((sle.voucher_type, sle.voucher_no))
if (sle.serial_no and not self.via_landed_cost_voucher) or not cint(self.allow_negative_stock):