From bbecd36a5dd65bb138c9f8b2528abd92cf886745 Mon Sep 17 00:00:00 2001 From: rahulgupta8848 <147691594+rahulgupta8848@users.noreply.github.com> Date: Sun, 1 Sep 2024 10:39:48 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20account=20heads=20changed=20along=20wit?= =?UTF-8?q?h=20journal=20entry=20type=20and=20descrip=E2=80=A6=20(#42845)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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” <“rahul.gupta@8848digital.com”> (cherry picked from commit d4fdada83cf0fc2580b4267b137296e30133bdef) # Conflicts: # erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.json # erpnext/patches.txt --- .../asset_value_adjustment.js | 22 +++++++- .../asset_value_adjustment.json | 15 +++++ .../asset_value_adjustment.py | 56 +++++++++++++------ .../test_asset_value_adjustment.py | 56 +++++++++++++++++-- erpnext/hooks.py | 2 + erpnext/patches.txt | 6 +- ...erence_amount_in_asset_value_adjustment.py | 10 ++++ 7 files changed, 144 insertions(+), 23 deletions(-) create mode 100644 erpnext/patches/v15_0/set_difference_amount_in_asset_value_adjustment.py diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js index 7fbe6d0bd12..4435b2b1845 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js @@ -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: { @@ -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) { @@ -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) { @@ -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, + }, + }); + } + }, }); diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.json b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.json index 57e04e2567f..e2695979bd2 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.json +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.json @@ -17,6 +17,7 @@ "new_asset_value", "column_break_11", "difference_amount", + "difference_account", "journal_entry", "accounting_dimensions_section", "cost_center", @@ -54,6 +55,7 @@ "fieldtype": "Link", "label": "Journal Entry", "options": "Journal Entry", + "no_copy": 1, "read_only": 1 }, { @@ -79,6 +81,7 @@ "fieldtype": "Currency", "in_list_view": 1, "label": "New Asset Value", + "no_copy": 1, "reqd": 1 }, { @@ -120,12 +123,24 @@ { "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": [], +<<<<<<< HEAD "modified": "2021-01-22 14:10:23.085181", +======= + "modified": "2024-08-13 16:21:18.639208", +>>>>>>> d4fdada83c (feat: account heads changed along with journal entry type and descrip… (#42845)) "modified_by": "Administrator", "module": "Assets", "name": "Asset Value Adjustment", diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py index 9b0212b037f..6766b827f7f 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py @@ -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 @@ -47,6 +48,7 @@ class AssetValueAdjustment(Document): 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, @@ -76,7 +78,10 @@ class AssetValueAdjustment(Document): ) 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: @@ -85,7 +90,7 @@ class AssetValueAdjustment(Document): 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) @@ -95,28 +100,41 @@ class AssetValueAdjustment(Document): ) 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() @@ -179,3 +197,9 @@ class AssetValueAdjustment(Document): ) 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) diff --git a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py index 963be704524..82fa3ba17e9 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py @@ -93,8 +93,8 @@ class TestAssetValueAdjustment(unittest.TestCase): 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( @@ -177,8 +177,8 @@ class TestAssetValueAdjustment(unittest.TestCase): # 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( @@ -259,6 +259,39 @@ class TestAssetValueAdjustment(unittest.TestCase): 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) @@ -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 diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 653679bfb56..2b23cca886e 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -562,6 +562,8 @@ accounting_dimension_doctypes = [ "Payment Reconciliation", "Payment Reconciliation Allocation", "Payment Request", + "Asset Movement Item", + "Asset Depreciation Schedule", ] get_matching_queries = ( diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d3651ee7060..6ddae058e55 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -378,6 +378,7 @@ erpnext.patches.v14_0.update_reports_with_range 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 +<<<<<<< HEAD erpnext.patches.v15_0.link_purchase_item_to_asset_doc erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter erpnext.patches.v15_0.update_task_assignee_email_field_in_asset_maintenance_log @@ -391,4 +392,7 @@ erpnext.patches.v15_0.rename_manufacturing_settings_field erpnext.patches.v15_0.migrate_checkbox_to_select_for_reconciliation_effect erpnext.patches.v15_0.sync_auto_reconcile_config execute:frappe.db.set_single_value("Accounts Settings", "exchange_gain_loss_posting_date", "Payment") -erpnext.patches.v14_0.disable_add_row_in_gross_profit \ No newline at end of file +erpnext.patches.v14_0.disable_add_row_in_gross_profit +======= +erpnext.patches.v15_0.set_difference_amount_in_asset_value_adjustment +>>>>>>> d4fdada83c (feat: account heads changed along with journal entry type and descrip… (#42845)) diff --git a/erpnext/patches/v15_0/set_difference_amount_in_asset_value_adjustment.py b/erpnext/patches/v15_0/set_difference_amount_in_asset_value_adjustment.py new file mode 100644 index 00000000000..bec344e5c86 --- /dev/null +++ b/erpnext/patches/v15_0/set_difference_amount_in_asset_value_adjustment.py @@ -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()