fix(stock): allow creating stock closing balances (#58590)

This commit is contained in:
Krishna Pramod Shirsath
2026-09-02 13:54:46 +05:30
committed by GitHub
parent a2071a6fdd
commit 2918e98a2b
2 changed files with 30 additions and 1 deletions

View File

@@ -187,7 +187,7 @@ class StockClosingEntry(Document):
new_doc.posting_datetime = get_combine_datetime(self.to_date, new_doc.posting_time)
new_doc.stock_closing_entry = self.name
new_doc.company = self.company
new_doc.save()
new_doc.save(ignore_permissions=True)
def get_prepared_data(self):
if attachments := get_attachments(self.doctype, self.name):

View File

@@ -4,6 +4,7 @@
from unittest.mock import patch
import frappe
from frappe.core.doctype.user_permission.test_user_permission import create_user
from frappe.utils import add_days, today
from erpnext.stock.doctype.item.test_item import make_item
@@ -60,6 +61,34 @@ class TestStockClosingEntry(ERPNextTestSuite):
self.last_closing_entry = entry.name
return entry
def test_non_administrator_can_generate_closing_balance(self):
item = make_item(properties={"is_stock_item": 1}).name
with patch("erpnext.stock.doctype.stock_closing_entry.stock_closing_entry.enqueue"):
entry = self.make_stock_closing_entry(today(), today())
user = create_user("test_stock_closing_balance@example.com", "Stock User")
self.assertFalse(frappe.has_permission("Stock Closing Balance", "create", user=user.name))
balance = frappe._dict(
item_code=item,
warehouse=WAREHOUSE,
actual_qty=1,
stock_value_difference=100,
fifo_queue=None,
)
with (
patch(
"erpnext.stock.doctype.stock_closing_entry.stock_closing_entry.StockClosing"
) as stock_closing,
self.set_user(user.name),
):
stock_closing.return_value.get_stock_closing_entries.return_value = {(item, WAREHOUSE): balance}
entry.create_stock_closing_balance_entries()
self.assertTrue(
frappe.db.exists("Stock Closing Balance", {"stock_closing_entry": entry.name, "item_code": item})
)
class TestStockClosingEntryDuplicate(ERPNextTestSuite):
"""validate_duplicate blocks a second submitted closing entry whose date range