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

This commit is contained in:
Khushi Rawat
2024-06-25 15:30:17 +05:30
committed by GitHub
parent 97c9941143
commit 5738d93f95

View File

@@ -659,10 +659,7 @@ class BuyingController(SubcontractingController):
return return
if self.doctype in ["Purchase Receipt", "Purchase Invoice"]: if self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
field = "purchase_invoice" if self.doctype == "Purchase Invoice" else "purchase_receipt"
self.process_fixed_asset() self.process_fixed_asset()
self.update_fixed_asset(field)
if self.doctype in ["Purchase Order", "Purchase Receipt"] and not frappe.db.get_single_value( if self.doctype in ["Purchase Order", "Purchase Receipt"] and not frappe.db.get_single_value(
"Buying Settings", "disable_last_purchase_rate" "Buying Settings", "disable_last_purchase_rate"
@@ -774,7 +771,7 @@ class BuyingController(SubcontractingController):
if not row.asset_location: if not row.asset_location:
frappe.throw(_("Row {0}: Enter location for the asset item {1}").format(row.idx, row.item_code)) 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 "Item", row.item_code, ["asset_naming_series", "asset_category"], as_dict=1
) )
asset_quantity = row.qty if is_grouped_asset else 1 asset_quantity = row.qty if is_grouped_asset else 1
@@ -803,7 +800,7 @@ class BuyingController(SubcontractingController):
asset.flags.ignore_validate = True asset.flags.ignore_validate = True
asset.flags.ignore_mandatory = True asset.flags.ignore_mandatory = True
asset.set_missing_values() asset.set_missing_values()
asset.insert() asset.db_insert()
return asset.name return asset.name
@@ -829,11 +826,7 @@ class BuyingController(SubcontractingController):
frappe.delete_doc("Asset", asset.name, force=1) frappe.delete_doc("Asset", asset.name, force=1)
continue continue
if self.docstatus in [0, 1] and not asset.get(field): if self.docstatus == 2:
asset.set(field, self.name)
asset.purchase_date = self.posting_date
asset.supplier = self.supplier
elif self.docstatus == 2:
if asset.docstatus == 2: if asset.docstatus == 2:
continue continue
if asset.docstatus == 0: if asset.docstatus == 0: