mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-09 15:29:30 +00:00
* fix(stock): allow creating stock closing balances (#58590)
(cherry picked from commit 2918e98a2b)
# Conflicts:
# erpnext/stock/doctype/stock_closing_entry/test_stock_closing_entry.py
* chore: fix conflicts
Removed redundant test cases and cleaned up the test structure for StockClosingEntry.
---------
Co-authored-by: Krishna Pramod Shirsath <91021227+krishna-254@users.noreply.github.com>
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -189,7 +189,7 @@ class StockClosingEntry(Document):
|
|||||||
new_doc.posting_datetime = get_combine_datetime(self.to_date, new_doc.posting_time)
|
new_doc.posting_datetime = get_combine_datetime(self.to_date, new_doc.posting_time)
|
||||||
new_doc.stock_closing_entry = self.name
|
new_doc.stock_closing_entry = self.name
|
||||||
new_doc.company = self.company
|
new_doc.company = self.company
|
||||||
new_doc.save()
|
new_doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
def get_prepared_data(self):
|
def get_prepared_data(self):
|
||||||
if attachments := get_attachments(self.doctype, self.name):
|
if attachments := get_attachments(self.doctype, self.name):
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
|
||||||
# import frappe
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
from frappe.core.doctype.user_permission.test_user_permission import create_user
|
||||||
|
from frappe.utils import today
|
||||||
|
|
||||||
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
from erpnext.tests.utils import ERPNextTestSuite
|
from erpnext.tests.utils import ERPNextTestSuite
|
||||||
|
|
||||||
# On ERPNextTestSuite, the doctype test records and all
|
# On ERPNextTestSuite, the doctype test records and all
|
||||||
# link-field test record depdendencies are recursively loaded
|
# link-field test record depdendencies are recursively loaded
|
||||||
# Use these module variables to add/remove to/from that list
|
# Use these module variables to add/remove to/from that list
|
||||||
|
|
||||||
|
COMPANY = "_Test Company"
|
||||||
|
WAREHOUSE = "_Test Warehouse - _TC"
|
||||||
|
|
||||||
|
|
||||||
class TestStockClosingEntry(ERPNextTestSuite):
|
class TestStockClosingEntry(ERPNextTestSuite):
|
||||||
"""
|
"""
|
||||||
@@ -16,4 +24,40 @@ class TestStockClosingEntry(ERPNextTestSuite):
|
|||||||
Use this class for testing interactions between multiple components.
|
Use this class for testing interactions between multiple components.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
def make_stock_closing_entry(self, from_date, to_date):
|
||||||
|
entry = frappe.get_doc(
|
||||||
|
doctype="Stock Closing Entry",
|
||||||
|
company=COMPANY,
|
||||||
|
from_date=from_date,
|
||||||
|
to_date=to_date,
|
||||||
|
).submit()
|
||||||
|
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})
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user