feat: account heads changed along with journal entry type and descrip… (#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” <“rahul.gupta@8848digital.com”>
(cherry picked from commit d4fdada83c)
# Conflicts:
# erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.json
# erpnext/patches.txt
This commit is contained in:
@@ -5,7 +5,6 @@ frappe.provide("erpnext.accounts.dimensions");
|
|||||||
|
|
||||||
frappe.ui.form.on("Asset Value Adjustment", {
|
frappe.ui.form.on("Asset Value Adjustment", {
|
||||||
setup: function (frm) {
|
setup: function (frm) {
|
||||||
frm.add_fetch("company", "cost_center", "cost_center");
|
|
||||||
frm.set_query("cost_center", function () {
|
frm.set_query("cost_center", function () {
|
||||||
return {
|
return {
|
||||||
filters: {
|
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) {
|
onload: function (frm) {
|
||||||
@@ -37,7 +44,7 @@ frappe.ui.form.on("Asset Value Adjustment", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
asset: function (frm) {
|
asset: function (frm) {
|
||||||
frm.trigger("set_current_asset_value");
|
frm.trigger("set_acc_dimension");
|
||||||
},
|
},
|
||||||
|
|
||||||
finance_book: function (frm) {
|
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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"new_asset_value",
|
"new_asset_value",
|
||||||
"column_break_11",
|
"column_break_11",
|
||||||
"difference_amount",
|
"difference_amount",
|
||||||
|
"difference_account",
|
||||||
"journal_entry",
|
"journal_entry",
|
||||||
"accounting_dimensions_section",
|
"accounting_dimensions_section",
|
||||||
"cost_center",
|
"cost_center",
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Journal Entry",
|
"label": "Journal Entry",
|
||||||
"options": "Journal Entry",
|
"options": "Journal Entry",
|
||||||
|
"no_copy": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -79,6 +81,7 @@
|
|||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "New Asset Value",
|
"label": "New Asset Value",
|
||||||
|
"no_copy": 1,
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -120,12 +123,24 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "column_break_11",
|
"fieldname": "column_break_11",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "difference_account",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Difference Account",
|
||||||
|
"no_copy": 1,
|
||||||
|
"options": "Account",
|
||||||
|
"reqd": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
|
<<<<<<< HEAD
|
||||||
"modified": "2021-01-22 14:10:23.085181",
|
"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",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset Value Adjustment",
|
"name": "Asset Value Adjustment",
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class AssetValueAdjustment(Document):
|
|||||||
cost_center: DF.Link | None
|
cost_center: DF.Link | None
|
||||||
current_asset_value: DF.Currency
|
current_asset_value: DF.Currency
|
||||||
date: DF.Date
|
date: DF.Date
|
||||||
|
difference_account: DF.Link
|
||||||
difference_amount: DF.Currency
|
difference_amount: DF.Currency
|
||||||
finance_book: DF.Link | None
|
finance_book: DF.Link | None
|
||||||
journal_entry: DF.Link | None
|
journal_entry: DF.Link | None
|
||||||
@@ -47,6 +48,7 @@ class AssetValueAdjustment(Document):
|
|||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.make_depreciation_entry()
|
self.make_depreciation_entry()
|
||||||
|
self.set_value_after_depreciation()
|
||||||
self.update_asset(self.new_asset_value)
|
self.update_asset(self.new_asset_value)
|
||||||
add_asset_activity(
|
add_asset_activity(
|
||||||
self.asset,
|
self.asset,
|
||||||
@@ -76,7 +78,10 @@ class AssetValueAdjustment(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def set_difference_amount(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):
|
def set_current_asset_value(self):
|
||||||
if not self.current_asset_value and self.asset:
|
if not self.current_asset_value and self.asset:
|
||||||
@@ -85,7 +90,7 @@ class AssetValueAdjustment(Document):
|
|||||||
def make_depreciation_entry(self):
|
def make_depreciation_entry(self):
|
||||||
asset = frappe.get_doc("Asset", self.asset)
|
asset = frappe.get_doc("Asset", self.asset)
|
||||||
(
|
(
|
||||||
_,
|
fixed_asset_account,
|
||||||
accumulated_depreciation_account,
|
accumulated_depreciation_account,
|
||||||
depreciation_expense_account,
|
depreciation_expense_account,
|
||||||
) = get_depreciation_accounts(asset.asset_category, asset.company)
|
) = get_depreciation_accounts(asset.asset_category, asset.company)
|
||||||
@@ -95,28 +100,41 @@ class AssetValueAdjustment(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
je = frappe.new_doc("Journal Entry")
|
je = frappe.new_doc("Journal Entry")
|
||||||
je.voucher_type = "Depreciation Entry"
|
je.voucher_type = "Journal Entry"
|
||||||
je.naming_series = depreciation_series
|
je.naming_series = depreciation_series
|
||||||
je.posting_date = self.date
|
je.posting_date = self.date
|
||||||
je.company = self.company
|
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
|
je.finance_book = self.finance_book
|
||||||
|
|
||||||
credit_entry = {
|
entry_template = {
|
||||||
"account": accumulated_depreciation_account,
|
"cost_center": self.cost_center or depreciation_cost_center,
|
||||||
"credit_in_account_currency": self.difference_amount,
|
|
||||||
"cost_center": depreciation_cost_center or self.cost_center,
|
|
||||||
"reference_type": "Asset",
|
"reference_type": "Asset",
|
||||||
"reference_name": self.asset,
|
"reference_name": asset.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
debit_entry = {
|
if self.difference_amount < 0:
|
||||||
"account": depreciation_expense_account,
|
credit_entry = {
|
||||||
"debit_in_account_currency": self.difference_amount,
|
"account": fixed_asset_account,
|
||||||
"cost_center": depreciation_cost_center or self.cost_center,
|
"credit_in_account_currency": -self.difference_amount,
|
||||||
"reference_type": "Asset",
|
**entry_template,
|
||||||
"reference_name": self.asset,
|
}
|
||||||
}
|
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()
|
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.flags.ignore_validate_update_after_submit = True
|
||||||
asset.save()
|
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)
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ class TestAssetValueAdjustment(unittest.TestCase):
|
|||||||
self.assertEqual(first_asset_depr_schedule.status, "Cancelled")
|
self.assertEqual(first_asset_depr_schedule.status, "Cancelled")
|
||||||
|
|
||||||
expected_gle = (
|
expected_gle = (
|
||||||
("_Test Accumulated Depreciations - _TC", 0.0, 4625.29),
|
("_Test Difference Account - _TC", 4625.29, 0.0),
|
||||||
("_Test Depreciations - _TC", 4625.29, 0.0),
|
("_Test Fixed Asset - _TC", 0.0, 4625.29),
|
||||||
)
|
)
|
||||||
|
|
||||||
gle = frappe.db.sql(
|
gle = frappe.db.sql(
|
||||||
@@ -177,8 +177,8 @@ class TestAssetValueAdjustment(unittest.TestCase):
|
|||||||
|
|
||||||
# Test gl entry creted from asset value adjustemnet
|
# Test gl entry creted from asset value adjustemnet
|
||||||
expected_gle = (
|
expected_gle = (
|
||||||
("_Test Accumulated Depreciations - _TC", 0.0, 5625.29),
|
("_Test Difference Account - _TC", 5625.29, 0.0),
|
||||||
("_Test Depreciations - _TC", 5625.29, 0.0),
|
("_Test Fixed Asset - _TC", 0.0, 5625.29),
|
||||||
)
|
)
|
||||||
|
|
||||||
gle = frappe.db.sql(
|
gle = frappe.db.sql(
|
||||||
@@ -259,6 +259,39 @@ class TestAssetValueAdjustment(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(schedules, expected_schedules)
|
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):
|
def make_asset_value_adjustment(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
@@ -272,7 +305,22 @@ def make_asset_value_adjustment(**args):
|
|||||||
"new_asset_value": args.new_asset_value,
|
"new_asset_value": args.new_asset_value,
|
||||||
"current_asset_value": args.current_asset_value,
|
"current_asset_value": args.current_asset_value,
|
||||||
"cost_center": args.cost_center or "Main - _TC",
|
"cost_center": args.cost_center or "Main - _TC",
|
||||||
|
"difference_account": make_difference_account(),
|
||||||
}
|
}
|
||||||
).insert()
|
).insert()
|
||||||
|
|
||||||
return doc
|
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
|
||||||
|
|||||||
@@ -562,6 +562,8 @@ accounting_dimension_doctypes = [
|
|||||||
"Payment Reconciliation",
|
"Payment Reconciliation",
|
||||||
"Payment Reconciliation Allocation",
|
"Payment Reconciliation Allocation",
|
||||||
"Payment Request",
|
"Payment Request",
|
||||||
|
"Asset Movement Item",
|
||||||
|
"Asset Depreciation Schedule",
|
||||||
]
|
]
|
||||||
|
|
||||||
get_matching_queries = (
|
get_matching_queries = (
|
||||||
|
|||||||
@@ -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.drop_index_posting_datetime_from_sle
|
||||||
erpnext.patches.v15_0.add_disassembly_order_stock_entry_type #1
|
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_standard_stock_entry_type
|
||||||
|
<<<<<<< HEAD
|
||||||
erpnext.patches.v15_0.link_purchase_item_to_asset_doc
|
erpnext.patches.v15_0.link_purchase_item_to_asset_doc
|
||||||
erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter
|
erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter
|
||||||
erpnext.patches.v15_0.update_task_assignee_email_field_in_asset_maintenance_log
|
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.migrate_checkbox_to_select_for_reconciliation_effect
|
||||||
erpnext.patches.v15_0.sync_auto_reconcile_config
|
erpnext.patches.v15_0.sync_auto_reconcile_config
|
||||||
execute:frappe.db.set_single_value("Accounts Settings", "exchange_gain_loss_posting_date", "Payment")
|
execute:frappe.db.set_single_value("Accounts Settings", "exchange_gain_loss_posting_date", "Payment")
|
||||||
erpnext.patches.v14_0.disable_add_row_in_gross_profit
|
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))
|
||||||
|
|||||||
@@ -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()
|
||||||
Reference in New Issue
Block a user