Other 2 improvement areas
- Batch creating stock ledger and general ledger entries instead of one by one
Currently there is only one table for stock ledger entry and general ledger(gl) entry respectively, in other word not like transactions split by master and child tables such as Purchase Order as master, Purchase Order Item as child, normally when auto creating stock ledger and general ledger entries for one original transaction, there are many sle and gle entries to be created, at the moment the sle and gle entries are created one by one, which resulted in many DB calls, for original transactions associated with a lot of items( a lot of gl accounts), same as the proposed db_insert_multi for child table, there can be insert_multi method to handle creating(inserting) multi docs, for the most frequent call to auto create sle and gle entries, it will be a big performance improvement
- Fetch multiple auto names from naming series
At the moment for document with auto name by naming series, even when creating multiple docs for the same transaction , e.g stock ledger entry and general ledger entry, getseries( fetch the auto name) is handled one by one, which resulted in a lot of unnecessary DB calls to the Series table. instead of calling getseries to get one auto name a time, the getseries method can be adapted to accept an input parameter to allow getting multiple auto names, the calling function is to assign internally the returned names accordingly, thus the DB calls to the Series table can be reduced to only 2, one for select the current number, the other is to update the new current number as old number + requested qty.
def getseries(key, digits, doctype=’’):
# series created ?
current = frappe.db.sql(“select
tabSeries where name=%s for update”, (key,))
if current and current is not None:
current = current
# yes, update it
frappe.db.sql(“update tabSeries set current = current+1 where name=%s”, (key,))
current = cint(current) + 1
# no, create it
frappe.db.sql(“insert into tabSeries (name, current) values (%s, 1)”, (key,))
current = 1
return (’%0’+str(digits)+‘d’) % current
Another idea of the auto name for stock ledger and general ledger entry is to use per transaction document number plus sequence number as name. currently a new name is assigned to each record, e.g GLE000001, GLE000002,… actually these 2 gle entries linked to the same original business transaction, logically all the gle entries created by the original transaction are to be assigned same document number(in other ERP system), per the above analysis, In ERPNext there is no separation between master and child table for gle, in order to reduce the DB calls to Series table and also bind one transaction together/assign same document number for one transaction, I would like to propose the sle name to be defined as combination of document number and item/sequence no, e.g as GLE000001-01, GLE000001-02, we only need to get one auto name for a single transaction, also from the name we can easily see which gle entries are actually of the same financial document, auto created by the same original business transaction.