mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-26 18:18:30 +00:00
perf: data import for stock entries (#42711)
(cherry picked from commit 1511280464)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
from frappe.permissions import add_user_permission, remove_user_permission
|
from frappe.permissions import add_user_permission, remove_user_permission
|
||||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
from frappe.utils import add_days, flt, nowtime, today
|
from frappe.utils import add_days, cstr, flt, get_time, getdate, nowtime, today
|
||||||
|
|
||||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||||
from erpnext.stock.doctype.item.test_item import (
|
from erpnext.stock.doctype.item.test_item import (
|
||||||
@@ -1780,6 +1780,74 @@ class TestStockEntry(FrappeTestCase):
|
|||||||
frappe.db.set_value("Serial and Batch Bundle", sbb, "type_of_transaction", "Inward")
|
frappe.db.set_value("Serial and Batch Bundle", sbb, "type_of_transaction", "Inward")
|
||||||
self.assertRaises(frappe.ValidationError, se.submit)
|
self.assertRaises(frappe.ValidationError, se.submit)
|
||||||
|
|
||||||
|
def test_stock_entry_for_same_posting_date_and_time(self):
|
||||||
|
warehouse = "_Test Warehouse - _TC"
|
||||||
|
item_code = "Test Stock Entry For Same Posting Datetime 1"
|
||||||
|
make_item(item_code, {"is_stock_item": 1})
|
||||||
|
posting_date = nowdate()
|
||||||
|
posting_time = nowtime()
|
||||||
|
|
||||||
|
for index in range(25):
|
||||||
|
se = make_stock_entry(
|
||||||
|
item_code=item_code,
|
||||||
|
qty=1,
|
||||||
|
to_warehouse=warehouse,
|
||||||
|
posting_date=posting_date,
|
||||||
|
posting_time=posting_time,
|
||||||
|
do_not_submit=True,
|
||||||
|
purpose="Material Receipt",
|
||||||
|
basic_rate=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
se.append(
|
||||||
|
"items",
|
||||||
|
{
|
||||||
|
"item_code": item_code,
|
||||||
|
"item_name": se.items[0].item_name,
|
||||||
|
"description": se.items[0].description,
|
||||||
|
"t_warehouse": se.items[0].t_warehouse,
|
||||||
|
"basic_rate": 100,
|
||||||
|
"qty": 1,
|
||||||
|
"stock_qty": 1,
|
||||||
|
"conversion_factor": 1,
|
||||||
|
"expense_account": se.items[0].expense_account,
|
||||||
|
"cost_center": se.items[0].cost_center,
|
||||||
|
"uom": se.items[0].uom,
|
||||||
|
"stock_uom": se.items[0].stock_uom,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
se.remarks = f"The current number is {cstr(index)}"
|
||||||
|
|
||||||
|
se.submit()
|
||||||
|
|
||||||
|
sles = frappe.get_all(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
fields=[
|
||||||
|
"posting_date",
|
||||||
|
"posting_time",
|
||||||
|
"actual_qty",
|
||||||
|
"qty_after_transaction",
|
||||||
|
"incoming_rate",
|
||||||
|
"stock_value_difference",
|
||||||
|
"stock_value",
|
||||||
|
],
|
||||||
|
filters={"item_code": item_code, "warehouse": warehouse},
|
||||||
|
order_by="creation",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(sles), 50)
|
||||||
|
i = 0
|
||||||
|
for sle in sles:
|
||||||
|
i += 1
|
||||||
|
self.assertEqual(getdate(sle.posting_date), getdate(posting_date))
|
||||||
|
self.assertEqual(get_time(sle.posting_time), get_time(posting_time))
|
||||||
|
self.assertEqual(sle.actual_qty, 1)
|
||||||
|
self.assertEqual(sle.qty_after_transaction, i)
|
||||||
|
self.assertEqual(sle.incoming_rate, 100)
|
||||||
|
self.assertEqual(sle.stock_value_difference, 100)
|
||||||
|
self.assertEqual(sle.stock_value, 100 * i)
|
||||||
|
|
||||||
|
|
||||||
def make_serialized_item(**args):
|
def make_serialized_item(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|||||||
@@ -1043,6 +1043,8 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin):
|
|||||||
self.assertEqual(50, _get_stock_credit(final_consumption))
|
self.assertEqual(50, _get_stock_credit(final_consumption))
|
||||||
|
|
||||||
def test_tie_breaking(self):
|
def test_tie_breaking(self):
|
||||||
|
from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import repost_entries
|
||||||
|
|
||||||
frappe.flags.dont_execute_stock_reposts = True
|
frappe.flags.dont_execute_stock_reposts = True
|
||||||
self.addCleanup(frappe.flags.pop, "dont_execute_stock_reposts")
|
self.addCleanup(frappe.flags.pop, "dont_execute_stock_reposts")
|
||||||
|
|
||||||
@@ -1085,6 +1087,7 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin):
|
|||||||
self.assertEqual([10, 11], ordered_qty_after_transaction())
|
self.assertEqual([10, 11], ordered_qty_after_transaction())
|
||||||
|
|
||||||
first.cancel()
|
first.cancel()
|
||||||
|
repost_entries()
|
||||||
self.assertEqual([1], ordered_qty_after_transaction())
|
self.assertEqual([1], ordered_qty_after_transaction())
|
||||||
|
|
||||||
backdated = make_stock_entry(
|
backdated = make_stock_entry(
|
||||||
|
|||||||
@@ -647,6 +647,7 @@ class update_entries_after:
|
|||||||
and (
|
and (
|
||||||
posting_datetime = %(posting_datetime)s
|
posting_datetime = %(posting_datetime)s
|
||||||
)
|
)
|
||||||
|
and creation = %(creation)s
|
||||||
order by
|
order by
|
||||||
creation ASC
|
creation ASC
|
||||||
for update
|
for update
|
||||||
@@ -1526,6 +1527,11 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
|
|||||||
voucher_no = args.get("voucher_no")
|
voucher_no = args.get("voucher_no")
|
||||||
voucher_condition = f"and voucher_no != '{voucher_no}'"
|
voucher_condition = f"and voucher_no != '{voucher_no}'"
|
||||||
|
|
||||||
|
elif args.get("creation"):
|
||||||
|
creation = args.get("creation")
|
||||||
|
operator = "<="
|
||||||
|
voucher_condition = f"and creation < '{creation}'"
|
||||||
|
|
||||||
sle = frappe.db.sql(
|
sle = frappe.db.sql(
|
||||||
f"""
|
f"""
|
||||||
select *, posting_datetime as "timestamp"
|
select *, posting_datetime as "timestamp"
|
||||||
|
|||||||
Reference in New Issue
Block a user