fix(asset): skip missing checkbox columns in asset type patch (#58416)

(cherry picked from commit 6bdc18b753)

# Conflicts:
#	erpnext/patches/v16_0/migrate_asset_type_checkboxes_to_select.py
This commit is contained in:
Raffael Meyer
2026-08-26 02:46:20 +02:00
committed by Mergify
parent 7238ecb306
commit 9ce6e6c5c4

View File

@@ -3,6 +3,7 @@ from frappe.query_builder import Case
def execute():
<<<<<<< HEAD
required_columns = [
"is_existing_asset",
"is_composite_asset",
@@ -14,12 +15,21 @@ def execute():
return
Asset = frappe.qb.DocType("Asset")
=======
# v15 sites never had is_composite_component; only migrate columns that exist.
column_values = (
("is_existing_asset", "Existing Asset"),
("is_composite_asset", "Composite Asset"),
("is_composite_component", "Composite Component"),
)
existing = [(col, value) for col, value in column_values if frappe.db.has_column("Asset", col)]
if not existing:
return
>>>>>>> 6bdc18b (fix(asset): skip missing checkbox columns in asset type patch (#58416))
frappe.qb.update(Asset).set(
Asset.asset_type,
Case()
.when(Asset.is_existing_asset == 1, "Existing Asset")
.when(Asset.is_composite_asset == 1, "Composite Asset")
.when(Asset.is_composite_component == 1, "Composite Component")
.else_(""),
).run()
Asset = frappe.qb.DocType("Asset")
case = Case()
for column, value in existing:
case = case.when(getattr(Asset, column) == 1, value)
frappe.qb.update(Asset).set(Asset.asset_type, case.else_("")).run()