mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-13 17:20:36 +00:00
fix(stock): use correct field when reading previous stock closing balance
`StockClosing.get_sle_entries` filtered `Stock Closing Balance` by a
`closing_stock_balance` column that does not exist; the link field back to
the closing entry is `stock_closing_entry`. As a result every Stock
Closing Entry created after the first one failed with
`OperationalError (1054, "Unknown column 'closing_stock_balance'")`, since
the previous-balance branch only runs once an earlier closing exists.
Fixes #54819
(cherry picked from commit 8e627db785)
# Conflicts:
# erpnext/stock/doctype/stock_closing_entry/test_stock_closing_entry.py
This commit is contained in:
@@ -331,7 +331,7 @@ class StockClosing:
|
|||||||
],
|
],
|
||||||
filters={
|
filters={
|
||||||
"company": self.company,
|
"company": self.company,
|
||||||
"closing_stock_balance": self.last_closing_balance.name,
|
"stock_closing_entry": self.last_closing_balance.name,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
@@ -8,11 +9,18 @@ from frappe.core.doctype.user_permission.test_user_permission import create_user
|
|||||||
from frappe.utils import today
|
from frappe.utils import today
|
||||||
|
|
||||||
from erpnext.stock.doctype.item.test_item import make_item
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
|
=======
|
||||||
|
import frappe
|
||||||
|
from frappe.utils import add_days, today
|
||||||
|
|
||||||
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
|
from erpnext.stock.doctype.stock_closing_entry.stock_closing_entry import StockClosing
|
||||||
|
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||||
|
>>>>>>> 8e627db (fix(stock): use correct field when reading previous stock closing balance)
|
||||||
from erpnext.tests.utils import ERPNextTestSuite
|
from erpnext.tests.utils import ERPNextTestSuite
|
||||||
|
|
||||||
# On ERPNextTestSuite, the doctype test records and all
|
COMPANY = "_Test Company"
|
||||||
# link-field test record depdendencies are recursively loaded
|
WAREHOUSE = "_Test Warehouse - _TC"
|
||||||
# Use these module variables to add/remove to/from that list
|
|
||||||
|
|
||||||
COMPANY = "_Test Company"
|
COMPANY = "_Test Company"
|
||||||
WAREHOUSE = "_Test Warehouse - _TC"
|
WAREHOUSE = "_Test Warehouse - _TC"
|
||||||
@@ -24,6 +32,38 @@ class TestStockClosingEntry(ERPNextTestSuite):
|
|||||||
Use this class for testing interactions between multiple components.
|
Use this class for testing interactions between multiple components.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
def test_closing_entry_reads_previous_closing_balance(self):
|
||||||
|
"""A closing entry created after another one must read the previous balance.
|
||||||
|
|
||||||
|
Regression for the query that filtered `Stock Closing Balance` by a
|
||||||
|
non-existent `closing_stock_balance` column, raising an OperationalError
|
||||||
|
for every closing entry created after the first one.
|
||||||
|
"""
|
||||||
|
item = make_item(properties={"is_stock_item": 1}).name
|
||||||
|
first_date = add_days(today(), -10)
|
||||||
|
|
||||||
|
# A submitted closing entry makes the next closing look up its balance.
|
||||||
|
self.make_stock_closing_entry(first_date, first_date)
|
||||||
|
|
||||||
|
second_from_date = add_days(first_date, 1)
|
||||||
|
make_stock_entry(
|
||||||
|
item_code=item,
|
||||||
|
to_warehouse=WAREHOUSE,
|
||||||
|
qty=10,
|
||||||
|
rate=100,
|
||||||
|
posting_date=second_from_date,
|
||||||
|
company=COMPANY,
|
||||||
|
)
|
||||||
|
|
||||||
|
closing = StockClosing(COMPANY, second_from_date, add_days(second_from_date, 1))
|
||||||
|
entries = closing.get_sle_entries()
|
||||||
|
|
||||||
|
self.assertEqual(closing.last_closing_balance.name, self.last_closing_entry)
|
||||||
|
self.assertIn(item, {row.item_code for row in entries})
|
||||||
|
|
||||||
|
>>>>>>> 8e627db (fix(stock): use correct field when reading previous stock closing balance)
|
||||||
def make_stock_closing_entry(self, from_date, to_date):
|
def make_stock_closing_entry(self, from_date, to_date):
|
||||||
entry = frappe.get_doc(
|
entry = frappe.get_doc(
|
||||||
doctype="Stock Closing Entry",
|
doctype="Stock Closing Entry",
|
||||||
@@ -33,6 +73,7 @@ class TestStockClosingEntry(ERPNextTestSuite):
|
|||||||
).submit()
|
).submit()
|
||||||
self.last_closing_entry = entry.name
|
self.last_closing_entry = entry.name
|
||||||
return entry
|
return entry
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
def test_non_administrator_can_generate_closing_balance(self):
|
def test_non_administrator_can_generate_closing_balance(self):
|
||||||
item = make_item(properties={"is_stock_item": 1}).name
|
item = make_item(properties={"is_stock_item": 1}).name
|
||||||
@@ -61,3 +102,5 @@ class TestStockClosingEntry(ERPNextTestSuite):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
frappe.db.exists("Stock Closing Balance", {"stock_closing_entry": entry.name, "item_code": item})
|
frappe.db.exists("Stock Closing Balance", {"stock_closing_entry": entry.name, "item_code": item})
|
||||||
)
|
)
|
||||||
|
=======
|
||||||
|
>>>>>>> 8e627db (fix(stock): use correct field when reading previous stock closing balance)
|
||||||
|
|||||||
Reference in New Issue
Block a user