fix: ask for asset related accounts only when needed (backport #36960) (#36972)

fix: ask for asset related accounts only when needed (#36960)

* fix: only ask for asset_received_but_not_billed account when needed

* chore: remove unnecessary if condition

* fix: only ask for expenses_included_in_asset_valuation account when needed

(cherry picked from commit 174f95d699)

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
This commit is contained in:
mergify[bot]
2023-09-05 18:14:49 +05:30
committed by GitHub
parent 6f40d0cdf6
commit 3a71fa9d96

View File

@@ -261,9 +261,7 @@ class PurchaseInvoice(BuyingController):
stock_not_billed_account = self.get_company_default("stock_received_but_not_billed") stock_not_billed_account = self.get_company_default("stock_received_but_not_billed")
stock_items = self.get_stock_items() stock_items = self.get_stock_items()
asset_items = [d.is_fixed_asset for d in self.items if d.is_fixed_asset] asset_received_but_not_billed = None
if len(asset_items) > 0:
asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed")
if self.update_stock: if self.update_stock:
self.validate_item_code() self.validate_item_code()
@@ -357,6 +355,8 @@ class PurchaseInvoice(BuyingController):
) )
item.expense_account = asset_category_account item.expense_account = asset_category_account
elif item.is_fixed_asset and item.pr_detail: elif item.is_fixed_asset and item.pr_detail:
if not asset_received_but_not_billed:
asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed")
item.expense_account = asset_received_but_not_billed item.expense_account = asset_received_but_not_billed
elif not item.expense_account and for_validate: elif not item.expense_account and for_validate:
throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name)) throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))
@@ -924,8 +924,9 @@ class PurchaseInvoice(BuyingController):
) )
def get_asset_gl_entry(self, gl_entries): def get_asset_gl_entry(self, gl_entries):
arbnb_account = self.get_company_default("asset_received_but_not_billed") arbnb_account = None
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation") eiiav_account = None
asset_eiiav_currency = None
for item in self.get("items"): for item in self.get("items"):
if item.is_fixed_asset: if item.is_fixed_asset:
@@ -937,6 +938,8 @@ class PurchaseInvoice(BuyingController):
"Asset Received But Not Billed", "Asset Received But Not Billed",
"Fixed Asset", "Fixed Asset",
]: ]:
if not arbnb_account:
arbnb_account = self.get_company_default("asset_received_but_not_billed")
item.expense_account = arbnb_account item.expense_account = arbnb_account
if not self.update_stock: if not self.update_stock:
@@ -959,7 +962,10 @@ class PurchaseInvoice(BuyingController):
) )
if item.item_tax_amount: if item.item_tax_amount:
if not eiiav_account or not asset_eiiav_currency:
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
asset_eiiav_currency = get_account_currency(eiiav_account) asset_eiiav_currency = get_account_currency(eiiav_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict( self.get_gl_dict(
{ {
@@ -1002,7 +1008,10 @@ class PurchaseInvoice(BuyingController):
) )
if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)): if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)):
if not eiiav_account or not asset_eiiav_currency:
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
asset_eiiav_currency = get_account_currency(eiiav_account) asset_eiiav_currency = get_account_currency(eiiav_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict( self.get_gl_dict(
{ {
@@ -1022,10 +1031,11 @@ class PurchaseInvoice(BuyingController):
) )
) )
# When update stock is checked
# Assets are bought through this document then it will be linked to this document # Assets are bought through this document then it will be linked to this document
if self.update_stock:
if flt(item.landed_cost_voucher_amount): if flt(item.landed_cost_voucher_amount):
if not eiiav_account:
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
gl_entries.append( gl_entries.append(
self.get_gl_dict( self.get_gl_dict(
{ {
@@ -1060,9 +1070,7 @@ class PurchaseInvoice(BuyingController):
) )
for asset in assets: for asset in assets:
frappe.db.set_value("Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate)) frappe.db.set_value("Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate))
frappe.db.set_value( frappe.db.set_value("Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate))
"Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate)
)
return gl_entries return gl_entries