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
This commit is contained in:
Saqib 2019-12-09 19:07:05 +05:30 committed by Nabin Hait
parent ae02b4119d
commit 5998034b02
2 changed files with 13 additions and 5 deletions

View File

@ -610,13 +610,19 @@ def get_asset_account(account_name, asset=None, asset_category=None, company=Non
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

View File

@ -95,7 +95,8 @@ class PurchaseReceipt(BuyingController):
# 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 @@ class PurchaseReceipt(BuyingController):
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)