perf: Performance optmization for Purchase Invoice submission (backport #40263) (#41946)

* perf: Optimization for providional gl entries

(cherry picked from commit d7b738ff61)

# Conflicts:
#	erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py

* perf: Performance optimization for validating budget

(cherry picked from commit f204d810bb)

# Conflicts:
#	erpnext/accounts/doctype/budget/budget.py

* perf: Cached accounting dimensions details

(cherry picked from commit 8cd8b8f885)

* perf: Optimzed code for merging similar gl entries

(cherry picked from commit aa75a60142)

* fix: linter issues

(cherry picked from commit acc0b2faf8)

* perf: Cache accounting dimension filter map

(cherry picked from commit e4bd173875)

# Conflicts:
#	erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py

* fix: minor fixes

(cherry picked from commit 5cd9bf3bda)

* perf: skip unnecessary validation while transaction  cancellation

(cherry picked from commit 05385e4acb)

* perf: refactored handling provisional gl entries for non-stock items

(cherry picked from commit 49c74369a5)

# Conflicts:
#	erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py

* perf: validate expense against budget only if budget exists

(cherry picked from commit c15b2d5490)

* perf: Get bin details only for stock items

(cherry picked from commit 6ff9e6ee84)

# Conflicts:
#	erpnext/stock/get_item_details.py

* fix: added index for price_list column in Item Price

(cherry picked from commit d279e23623)

# Conflicts:
#	erpnext/stock/doctype/item_price/item_price.json

* perf: Caching in checking allowance for qty and amount

(cherry picked from commit 8d682fa884)

* perf: Caching in gl entry

(cherry picked from commit b07769d8d7)

# Conflicts:
#	erpnext/accounts/doctype/gl_entry/gl_entry.py

* chore: resolve conflicts

* chore: resolve conflict in purchase_invoice.py

---------

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
Co-authored-by: ruthra kumar <ruthra@erpnext.com>
This commit is contained in:
mergify[bot]
2024-06-27 17:32:43 +05:30
committed by GitHub
parent 8a91bf3154
commit d396c18689
14 changed files with 254 additions and 251 deletions

View File

@@ -7,7 +7,7 @@ import copy
import frappe
from frappe import _
from frappe.model.meta import get_field_precision
from frappe.utils import cint, cstr, flt, formatdate, getdate, now
from frappe.utils import cint, flt, formatdate, getdate, now
import erpnext
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
@@ -228,11 +228,13 @@ def get_cost_center_allocation_data(company, posting_date):
def merge_similar_entries(gl_map, precision=None):
merged_gl_map = []
accounting_dimensions = get_accounting_dimensions()
merge_properties = get_merge_properties(accounting_dimensions)
for entry in gl_map:
entry.merge_key = get_merge_key(entry, merge_properties)
# if there is already an entry in this account then just add it
# to that entry
same_head = check_if_in_list(entry, merged_gl_map, accounting_dimensions)
same_head = check_if_in_list(entry, merged_gl_map)
if same_head:
same_head.debit = flt(same_head.debit) + flt(entry.debit)
same_head.debit_in_account_currency = flt(same_head.debit_in_account_currency) + flt(
@@ -273,34 +275,35 @@ def merge_similar_entries(gl_map, precision=None):
return merged_gl_map
def check_if_in_list(gle, gl_map, dimensions=None):
account_head_fieldnames = [
"voucher_detail_no",
"party",
"against_voucher",
def get_merge_properties(dimensions=None):
merge_properties = [
"account",
"cost_center",
"against_voucher_type",
"party",
"party_type",
"voucher_detail_no",
"against_voucher",
"against_voucher_type",
"project",
"finance_book",
"voucher_no",
]
if dimensions:
account_head_fieldnames = account_head_fieldnames + dimensions
merge_properties.extend(dimensions)
return merge_properties
def get_merge_key(entry, merge_properties):
merge_key = []
for fieldname in merge_properties:
merge_key.append(entry.get(fieldname, ""))
return tuple(merge_key)
def check_if_in_list(gle, gl_map):
for e in gl_map:
same_head = True
if e.account != gle.account:
same_head = False
continue
for fieldname in account_head_fieldnames:
if cstr(e.get(fieldname)) != cstr(gle.get(fieldname)):
same_head = False
break
if same_head:
if e.merge_key == gle.merge_key:
return e