Skip to content

Commit

Permalink
fix: warning message for negative stock (#42683)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Aug 11, 2024
1 parent 2a999e8 commit deccb00
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import json

import frappe
from frappe import _, scrub
from frappe import _, bold, scrub
from frappe.model.meta import get_field_precision
from frappe.query_builder.functions import Sum
from frappe.utils import (
add_to_date,
cint,
cstr,
flt,
format_date,
get_link_to_form,
getdate,
now,
Expand Down Expand Up @@ -746,9 +747,29 @@ def get_dependent_voucher_detail_nos(self, key):

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):
# 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):
Expand Down

0 comments on commit deccb00

Please sign in to comment.