Skip to content

Commit

Permalink
perf: code optimization to handle large asset creation (#42018)
Browse files Browse the repository at this point in the history
  • Loading branch information
khushi8112 authored Jun 25, 2024
1 parent 97c9941 commit 5738d93
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 @@ -774,7 +771,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 @@ -803,7 +800,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 @@ -829,11 +826,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 5738d93

Please sign in to comment.