Skip to content

Commit

Permalink
perf: code optimization to handle large asset creation (backport #42018
Browse files Browse the repository at this point in the history
…) (#42025)

perf: code optimization to handle large asset creation (#42018)

(cherry picked from commit 5738d93)

Co-authored-by: Khushi Rawat <142375893+khushi8112@users.noreply.github.com>
  • Loading branch information
mergify[bot] and khushi8112 authored Jun 26, 2024
1 parent 63b26e6 commit c27f272
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions erpnext/controllers/buying_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,7 @@ def on_submit(self):
return

if self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
field = "purchase_invoice" if self.doctype == "Purchase Invoice" else "purchase_receipt"

self.process_fixed_asset()
self.update_fixed_asset(field)

if self.doctype in ["Purchase Order", "Purchase Receipt"] and not frappe.db.get_single_value(
"Buying Settings", "disable_last_purchase_rate"
Expand Down Expand Up @@ -772,7 +769,7 @@ def make_asset(self, row, is_grouped_asset=False):
if not row.asset_location:
frappe.throw(_("Row {0}: Enter location for the asset item {1}").format(row.idx, row.item_code))

item_data = frappe.db.get_value(
item_data = frappe.get_cached_value(
"Item", row.item_code, ["asset_naming_series", "asset_category"], as_dict=1
)
asset_quantity = row.qty if is_grouped_asset else 1
Expand Down Expand Up @@ -801,7 +798,7 @@ def make_asset(self, row, is_grouped_asset=False):
asset.flags.ignore_validate = True
asset.flags.ignore_mandatory = True
asset.set_missing_values()
asset.insert()
asset.db_insert()

return asset.name

Expand All @@ -827,11 +824,7 @@ def update_fixed_asset(self, field, delete_asset=False):
frappe.delete_doc("Asset", asset.name, force=1)
continue

if self.docstatus in [0, 1] and not asset.get(field):
asset.set(field, self.name)
asset.purchase_date = self.posting_date
asset.supplier = self.supplier
elif self.docstatus == 2:
if self.docstatus == 2:
if asset.docstatus == 2:
continue
if asset.docstatus == 0:
Expand Down

0 comments on commit c27f272

Please sign in to comment.