Skip to content

Commit

Permalink
feat: account heads changed along with journal entry type and descrip… (
Browse files Browse the repository at this point in the history
#42845)

* feat: account heads changed along with journal entry type and description

* feat: added patch for difference_amount for asset value adjustment and refactor

---------

Co-authored-by: “rahulgupta8848” <“[email protected]”>
  • Loading branch information
rahulgupta8848 and “rahulgupta8848” authored Sep 1, 2024
1 parent 9b4bb30 commit d4fdada
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ frappe.provide("erpnext.accounts.dimensions");

frappe.ui.form.on("Asset Value Adjustment", {
setup: function (frm) {
frm.add_fetch("company", "cost_center", "cost_center");
frm.set_query("cost_center", function () {
return {
filters: {
Expand All @@ -22,6 +21,14 @@ frappe.ui.form.on("Asset Value Adjustment", {
},
};
});
frm.set_query("difference_account", function () {
return {
filters: {
company: frm.doc.company,
is_group: 0,
},
};
});
},

onload: function (frm) {
Expand All @@ -37,7 +44,7 @@ frappe.ui.form.on("Asset Value Adjustment", {
},

asset: function (frm) {
frm.trigger("set_current_asset_value");
frm.trigger("set_acc_dimension");
},

finance_book: function (frm) {
Expand All @@ -60,4 +67,15 @@ frappe.ui.form.on("Asset Value Adjustment", {
});
}
},

set_acc_dimension: function (frm) {
if (frm.doc.asset) {
frm.call({
method: "erpnext.assets.doctype.asset_value_adjustment.asset_value_adjustment.get_value_of_accounting_dimensions",
args: {
asset_name: frm.doc.asset,
},
});
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"new_asset_value",
"column_break_11",
"difference_amount",
"difference_account",
"journal_entry",
"accounting_dimensions_section",
"cost_center",
Expand Down Expand Up @@ -54,6 +55,7 @@
"fieldtype": "Link",
"label": "Journal Entry",
"options": "Journal Entry",
"no_copy": 1,
"read_only": 1
},
{
Expand All @@ -79,6 +81,7 @@
"fieldtype": "Currency",
"in_list_view": 1,
"label": "New Asset Value",
"no_copy": 1,
"reqd": 1
},
{
Expand Down Expand Up @@ -120,12 +123,20 @@
{
"fieldname": "column_break_11",
"fieldtype": "Column Break"
},
{
"fieldname": "difference_account",
"fieldtype": "Link",
"label": "Difference Account",
"no_copy": 1,
"options": "Account",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-03-27 13:06:36.004049",
"modified": "2024-08-13 16:21:18.639208",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Value Adjustment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AssetValueAdjustment(Document):
cost_center: DF.Link | None
current_asset_value: DF.Currency
date: DF.Date
difference_account: DF.Link
difference_amount: DF.Currency
finance_book: DF.Link | None
journal_entry: DF.Link | None
Expand All @@ -47,6 +48,7 @@ def validate(self):

def on_submit(self):
self.make_depreciation_entry()
self.set_value_after_depreciation()
self.update_asset(self.new_asset_value)
add_asset_activity(
self.asset,
Expand Down Expand Up @@ -76,7 +78,10 @@ def validate_date(self):
)

def set_difference_amount(self):
self.difference_amount = flt(self.current_asset_value - self.new_asset_value)
self.difference_amount = flt(self.new_asset_value - self.current_asset_value)

def set_value_after_depreciation(self):
frappe.db.set_value("Asset", self.asset, "value_after_depreciation", self.new_asset_value)

def set_current_asset_value(self):
if not self.current_asset_value and self.asset:
Expand All @@ -85,7 +90,7 @@ def set_current_asset_value(self):
def make_depreciation_entry(self):
asset = frappe.get_doc("Asset", self.asset)
(
_,
fixed_asset_account,
accumulated_depreciation_account,
depreciation_expense_account,
) = get_depreciation_accounts(asset.asset_category, asset.company)
Expand All @@ -95,28 +100,41 @@ def make_depreciation_entry(self):
)

je = frappe.new_doc("Journal Entry")
je.voucher_type = "Depreciation Entry"
je.voucher_type = "Journal Entry"
je.naming_series = depreciation_series
je.posting_date = self.date
je.company = self.company
je.remark = f"Depreciation Entry against {self.asset} worth {self.difference_amount}"
je.remark = f"Revaluation Entry against {self.asset} worth {self.difference_amount}"
je.finance_book = self.finance_book

credit_entry = {
"account": accumulated_depreciation_account,
"credit_in_account_currency": self.difference_amount,
"cost_center": depreciation_cost_center or self.cost_center,
entry_template = {
"cost_center": self.cost_center or depreciation_cost_center,
"reference_type": "Asset",
"reference_name": self.asset,
"reference_name": asset.name,
}

debit_entry = {
"account": depreciation_expense_account,
"debit_in_account_currency": self.difference_amount,
"cost_center": depreciation_cost_center or self.cost_center,
"reference_type": "Asset",
"reference_name": self.asset,
}
if self.difference_amount < 0:
credit_entry = {
"account": fixed_asset_account,
"credit_in_account_currency": -self.difference_amount,
**entry_template,
}
debit_entry = {
"account": self.difference_account,
"debit_in_account_currency": -self.difference_amount,
**entry_template,
}
elif self.difference_amount > 0:
credit_entry = {
"account": self.difference_account,
"credit_in_account_currency": self.difference_amount,
**entry_template,
}
debit_entry = {
"account": fixed_asset_account,
"debit_in_account_currency": self.difference_amount,
**entry_template,
}

accounting_dimensions = get_checks_for_pl_and_bs_accounts()

Expand Down Expand Up @@ -179,3 +197,9 @@ def update_asset(self, asset_value=None):
)
asset.flags.ignore_validate_update_after_submit = True
asset.save()


@frappe.whitelist()
def get_value_of_accounting_dimensions(asset_name):
dimension_fields = [*frappe.get_list("Accounting Dimension", pluck="fieldname"), "cost_center"]
return frappe.db.get_value("Asset", asset_name, fieldname=dimension_fields, as_dict=True)
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def test_asset_depreciation_value_adjustment(self):
self.assertEqual(first_asset_depr_schedule.status, "Cancelled")

expected_gle = (
("_Test Accumulated Depreciations - _TC", 0.0, 4625.29),
("_Test Depreciations - _TC", 4625.29, 0.0),
("_Test Difference Account - _TC", 4625.29, 0.0),
("_Test Fixed Asset - _TC", 0.0, 4625.29),
)

gle = frappe.db.sql(
Expand Down Expand Up @@ -177,8 +177,8 @@ def test_depreciation_after_cancelling_asset_repair(self):

# Test gl entry creted from asset value adjustemnet
expected_gle = (
("_Test Accumulated Depreciations - _TC", 0.0, 5625.29),
("_Test Depreciations - _TC", 5625.29, 0.0),
("_Test Difference Account - _TC", 5625.29, 0.0),
("_Test Fixed Asset - _TC", 0.0, 5625.29),
)

gle = frappe.db.sql(
Expand Down Expand Up @@ -259,6 +259,39 @@ def test_depreciation_after_cancelling_asset_repair(self):

self.assertEqual(schedules, expected_schedules)

def test_difference_amount(self):
pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=120000.0, location="Test Location")

asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, "name")
asset_doc = frappe.get_doc("Asset", asset_name)
asset_doc.calculate_depreciation = 1
asset_doc.available_for_use_date = "2023-01-15"
asset_doc.purchase_date = "2023-01-15"

asset_doc.append(
"finance_books",
{
"expected_value_after_useful_life": 200,
"depreciation_method": "Straight Line",
"total_number_of_depreciations": 12,
"frequency_of_depreciation": 1,
"depreciation_start_date": "2023-01-31",
},
)
asset_doc.submit()

adj_doc = make_asset_value_adjustment(
asset=asset_doc.name,
current_asset_value=54000,
new_asset_value=50000.0,
date="2023-08-21",
)
adj_doc.submit()
difference_amount = adj_doc.new_asset_value - adj_doc.current_asset_value
self.assertEqual(difference_amount, -4000)
asset_doc.load_from_db()
self.assertEqual(asset_doc.value_after_depreciation, 50000.0)


def make_asset_value_adjustment(**args):
args = frappe._dict(args)
Expand All @@ -272,7 +305,22 @@ def make_asset_value_adjustment(**args):
"new_asset_value": args.new_asset_value,
"current_asset_value": args.current_asset_value,
"cost_center": args.cost_center or "Main - _TC",
"difference_account": make_difference_account(),
}
).insert()

return doc


def make_difference_account(**args):
account = "_Test Difference Account - _TC"
if not frappe.db.exists("Account", account):
acc = frappe.new_doc("Account")
acc.account_name = "_Test Difference Account"
acc.parent_account = "Direct Income - _TC"
acc.company = "_Test Company"
acc.is_group = 0
acc.insert()
return acc.name
else:
return account
2 changes: 2 additions & 0 deletions erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@
"Payment Reconciliation",
"Payment Reconciliation Allocation",
"Payment Request",
"Asset Movement Item",
"Asset Depreciation Schedule",
]

get_matching_queries = (
Expand Down
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,4 @@ erpnext.patches.v15_0.do_not_use_batchwise_valuation
erpnext.patches.v15_0.drop_index_posting_datetime_from_sle
erpnext.patches.v15_0.add_disassembly_order_stock_entry_type #1
erpnext.patches.v15_0.set_standard_stock_entry_type
erpnext.patches.v15_0.set_difference_amount_in_asset_value_adjustment
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import frappe


def execute():
AssetValueAdjustment = frappe.qb.DocType("Asset Value Adjustment")

frappe.qb.update(AssetValueAdjustment).set(
AssetValueAdjustment.difference_amount,
AssetValueAdjustment.new_asset_value - AssetValueAdjustment.current_asset_value,
).where(AssetValueAdjustment.docstatus != 2).run()

0 comments on commit d4fdada

Please sign in to comment.