fix: error message displays asset category as None (#19873)
* fix: error message displays asset category as None
* fix: asset gl_entries doesn't considers asset category's cwip account
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index d32f834..3e7f683 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -610,13 +610,19 @@
if asset:
account = get_asset_category_account(account_name, asset=asset,
asset_category = asset_category, company = company)
+
+ if not asset and not account:
+ account = get_asset_category_account(account_name, asset_category = asset_category, company = company)
if not account:
account = frappe.get_cached_value('Company', company, account_name)
if not account:
- frappe.throw(_("Set {0} in asset category {1} or company {2}")
- .format(account_name.replace('_', ' ').title(), asset_category, company))
+ if not asset_category:
+ frappe.throw(_("Set {0} in company {2}").format(account_name.replace('_', ' ').title(), company))
+ else:
+ frappe.throw(_("Set {0} in asset category {1} or company {2}")
+ .format(account_name.replace('_', ' ').title(), asset_category, company))
return account
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index d0fae6a..9b73d0f 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -95,7 +95,8 @@
# check cwip accounts before making auto assets
# Improves UX by not giving messages of "Assets Created" before throwing error of not finding arbnb account
arbnb_account = self.get_company_default("asset_received_but_not_billed")
- cwip_account = get_asset_account("capital_work_in_progress_account", company = self.company)
+ cwip_account = get_asset_account("capital_work_in_progress_account", asset_category = item.asset_category, \
+ company = self.company)
break
def validate_with_previous_doc(self):
@@ -364,8 +365,9 @@
def add_asset_gl_entries(self, item, gl_entries):
arbnb_account = self.get_company_default("asset_received_but_not_billed")
- # This returns company's default cwip account
- cwip_account = get_asset_account("capital_work_in_progress_account", company = self.company)
+ # This returns category's cwip account if not then fallback to company's default cwip account
+ cwip_account = get_asset_account("capital_work_in_progress_account", asset_category = item.asset_category, \
+ company = self.company)
asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)