feat(naming): Deferred naming for Stock Ledger Entry and GL Entry
For fast lockless insertions use hash as autonaming method for temporarily naming Stock Ledger Entry and GL Entry In an hourly run scheduled job rename these entries using autoname options
This commit is contained in:
parent
fdd5d54d41
commit
7bc692d48d
File diff suppressed because it is too large
Load Diff
@ -6,14 +6,21 @@ import frappe, erpnext
|
||||
from frappe import _
|
||||
from frappe.utils import flt, fmt_money, getdate, formatdate
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.naming import set_name_from_naming_options
|
||||
from erpnext.accounts.party import validate_party_gle_currency, validate_party_frozen_disabled
|
||||
from erpnext.accounts.utils import get_account_currency
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
from erpnext.exceptions import InvalidAccountCurrency
|
||||
|
||||
exclude_from_linked_with = True
|
||||
|
||||
class GLEntry(Document):
|
||||
def autoname(self):
|
||||
"""
|
||||
Temporarily name doc for fast insertion
|
||||
name will be changed using autoname options (in a scheduled job)
|
||||
"""
|
||||
self.name = frappe.generate_hash(txt="", length=10)
|
||||
|
||||
def validate(self):
|
||||
self.flags.ignore_submit_comment = True
|
||||
self.check_mandatory()
|
||||
@ -231,3 +238,17 @@ def update_against_account(voucher_type, voucher_no):
|
||||
|
||||
if d.against != new_against:
|
||||
frappe.db.set_value("GL Entry", d.name, "against", new_against)
|
||||
|
||||
|
||||
def rename_gle_sle_docs():
|
||||
for doctype in ["GL Entry", "Stock Ledger Entry"]:
|
||||
rename_temporarily_named_docs(doctype)
|
||||
|
||||
def rename_temporarily_named_docs(doctype):
|
||||
"""Rename temporarily named docs using autoname options"""
|
||||
docs_to_rename = frappe.get_all(doctype, {"to_rename": "1"}, order_by="creation")
|
||||
for doc in docs_to_rename:
|
||||
oldname = doc.name
|
||||
set_name_from_naming_options(frappe.get_meta(doctype).autoname, doc)
|
||||
newname = doc.name
|
||||
frappe.db.sql("""UPDATE `tab{}` SET name = %s, to_rename = 0 where name = %s""".format(doctype), (newname, oldname))
|
||||
|
@ -3,7 +3,9 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe, unittest
|
||||
from frappe.model.naming import parse_naming_series
|
||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||
from erpnext.accounts.doctype.gl_entry.gl_entry import rename_gle_sle_docs
|
||||
|
||||
class TestGLEntry(unittest.TestCase):
|
||||
def test_round_off_entry(self):
|
||||
@ -23,3 +25,32 @@ class TestGLEntry(unittest.TestCase):
|
||||
and debit = 0 and credit = '.01'""", jv.name)
|
||||
|
||||
self.assertTrue(round_off_entry)
|
||||
|
||||
def test_rename_entries(self):
|
||||
je = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, submit=True)
|
||||
rename_gle_sle_docs()
|
||||
naming_series = parse_naming_series(parts=frappe.get_meta("GL Entry").autoname.split(".")[:-1])
|
||||
|
||||
je = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 100, submit=True)
|
||||
|
||||
gl_entries = frappe.get_all("GL Entry",
|
||||
fields=["name", "to_rename"],
|
||||
filters={"voucher_type": "Journal Entry", "voucher_no": je.name},
|
||||
order_by="creation"
|
||||
)
|
||||
self.assertTrue(all(entry.to_rename == 1 for entry in gl_entries))
|
||||
old_naming_series_current_value = frappe.db.sql("SELECT current from tabSeries where name = %s", naming_series)[0][0]
|
||||
|
||||
rename_gle_sle_docs()
|
||||
|
||||
new_gl_entries = frappe.get_all("GL Entry",
|
||||
fields=["name", "to_rename"],
|
||||
filters={"voucher_type": "Journal Entry", "voucher_no": je.name},
|
||||
order_by="creation"
|
||||
)
|
||||
self.assertTrue(all(entry.to_rename == 0 for entry in new_gl_entries))
|
||||
|
||||
self.assertTrue(all(new.name != old.name for new, old in zip(gl_entries, new_gl_entries)))
|
||||
|
||||
new_naming_series_current_value = frappe.db.sql("SELECT current from tabSeries where name = %s", naming_series)[0][0]
|
||||
self.assertEquals(old_naming_series_current_value + 2, new_naming_series_current_value)
|
||||
|
@ -235,7 +235,9 @@ scheduler_events = {
|
||||
"hourly": [
|
||||
'erpnext.hr.doctype.daily_work_summary_group.daily_work_summary_group.trigger_emails',
|
||||
"erpnext.accounts.doctype.subscription.subscription.process_all",
|
||||
"erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_mws_settings.schedule_get_order_details"
|
||||
"erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_mws_settings.schedule_get_order_details",
|
||||
"erpnext.accounts.doctype.gl_entry.gl_entry.rename_gle_sle_docs",
|
||||
|
||||
],
|
||||
"daily": [
|
||||
"erpnext.stock.reorder_item.reorder_item",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,13 @@ class StockFreezeError(frappe.ValidationError): pass
|
||||
exclude_from_linked_with = True
|
||||
|
||||
class StockLedgerEntry(Document):
|
||||
def autoname(self):
|
||||
"""
|
||||
Temporarily name doc for fast insertion
|
||||
name will be changed using autoname options (in a scheduled job)
|
||||
"""
|
||||
self.name = frappe.generate_hash(txt="", length=10)
|
||||
|
||||
def validate(self):
|
||||
self.flags.ignore_submit_comment = True
|
||||
from erpnext.stock.utils import validate_warehouse_company
|
||||
@ -132,4 +139,4 @@ def on_doctype_update():
|
||||
|
||||
frappe.db.add_index("Stock Ledger Entry", ["voucher_no", "voucher_type"])
|
||||
frappe.db.add_index("Stock Ledger Entry", ["batch_no", "item_code", "warehouse"])
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user