Skip to content

Commit

Permalink
fix: set expense account as Assets RBNB only if it is booked in linke…
Browse files Browse the repository at this point in the history
…d PR (backport #41368) (#41673)

fix: set expense account as Assets RBNB only if it is booked in linked PR (#41368)

* fix: set expense account as Assets RBNB only if it is booked in linked PR

* fix: broken translations

(cherry picked from commit 014486d)

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
  • Loading branch information
mergify[bot] and nabinhait authored May 29, 2024
1 parent d29686f commit 0a0970e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def validate_duplicate_pos_invoices(self):
for key, value in pos_occurences.items():
if len(value) > 1:
error_list.append(
_(f"{frappe.bold(key)} is added multiple times on rows: {frappe.bold(value)}")
_("{0} is added multiple times on rows: {1}").format(frappe.bold(key), frappe.bold(value))
)

if error_list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def validate_duplicate_pos_invoices(self):
for key, value in pos_occurences.items():
if len(value) > 1:
error_list.append(
_(f"{frappe.bold(key)} is added multiple times on rows: {frappe.bold(value)}")
_("{0} is added multiple times on rows: {1}").format(frappe.bold(key), frappe.bold(value))
)

if error_list:
Expand Down
52 changes: 33 additions & 19 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def set_expense_account(self, for_validate=False):
stock_not_billed_account = self.get_company_default("stock_received_but_not_billed")
stock_items = self.get_stock_items()

asset_received_but_not_billed = None
asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed")

if self.update_stock:
self.validate_item_code()
Expand Down Expand Up @@ -531,26 +531,40 @@ def set_expense_account(self, for_validate=False):
frappe.msgprint(msg, title=_("Expense Head Changed"))

item.expense_account = stock_not_billed_account
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
elif item.is_fixed_asset:
account_type = (
"capital_work_in_progress_account"
if is_cwip_accounting_enabled(item.asset_category)
else "fixed_asset_account"
)
asset_category_account = get_asset_category_account(
account_type, item=item.item_code, company=self.company
)
if not asset_category_account:
form_link = get_link_to_form("Asset Category", item.asset_category)
throw(
_("Please set Fixed Asset Account in {} against {}.").format(form_link, self.company),
title=_("Missing Account"),
account = None
if item.pr_detail:
# check if 'Asset Received But Not Billed' account is credited in Purchase receipt or not
arbnb_booked_in_pr = frappe.db.get_value(
"GL Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": item.purchase_receipt,
"account": asset_received_but_not_billed,
},
"name",
)
item.expense_account = asset_category_account
if arbnb_booked_in_pr:
account = asset_received_but_not_billed

if not account:
account_type = (
"capital_work_in_progress_account"
if is_cwip_accounting_enabled(item.asset_category)
else "fixed_asset_account"
)
account = get_asset_category_account(
account_type, item=item.item_code, company=self.company
)
if not account:
form_link = get_link_to_form("Asset Category", item.asset_category)
throw(
_("Please set Fixed Asset Account in {} against {}.").format(
form_link, self.company
),
title=_("Missing Account"),
)
item.expense_account = account
elif not item.expense_account and for_validate:
throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))

Expand Down

0 comments on commit 0a0970e

Please sign in to comment.