From 8a5da5e2f2801cf3a1889c61a217da300bb6f2af Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Wed, 16 Oct 2024 23:44:02 +0530 Subject: [PATCH 1/2] chore: use selectbox instead of checkbox --- .../accounts_settings/accounts_settings.json | 10 +++++++++- .../accounts_settings/accounts_settings.py | 3 +++ .../asset_depreciation_schedule.py | 5 ++++- .../test_asset_depreciation_schedule.py | 16 ++++++++++++---- erpnext/patches.txt | 1 + .../patches/v15_0/update_checkbox_to_select.py | 13 +++++++++++++ 6 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v15_0/update_checkbox_to_select.py diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index ea08b973e45..3ffc629f2fa 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -59,6 +59,7 @@ "assets_tab", "asset_settings_section", "calculate_depr_using_total_days", + "calculate_daily_depreciation_using", "column_break_gjcc", "book_asset_depreciation_entry_automatically", "closing_settings_tab", @@ -508,6 +509,13 @@ "fieldname": "use_supplier_invoice_number_in_fec", "fieldtype": "Check", "label": "Use supplier invoice number in FEC" + }, + { + "default": "Total years in depreciation period", + "fieldname": "calculate_daily_depreciation_using", + "fieldtype": "Select", + "label": "Calculate Daily Pro-rata Depreciation Using", + "options": "Total days in depreciation period\nTotal years in depreciation period" } ], "icon": "uil uil-setting", @@ -515,7 +523,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-09-12 16:15:48.241124", + "modified": "2024-10-16 15:41:03.548766", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py index ea8511b92db..269e54574b5 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py @@ -33,6 +33,9 @@ class AccountsSettings(Document): book_deferred_entries_based_on: DF.Literal["Days", "Months"] book_deferred_entries_via_journal_entry: DF.Check book_tax_discount_loss: DF.Check + calculate_daily_depreciation_using: DF.Literal[ + "Total days in depreciation period", "Total years in depreciation period" + ] calculate_depr_using_total_days: DF.Check check_supplier_invoice_uniqueness: DF.Check credit_controller: DF.Link | None diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index 6ebed219e6c..164e7027beb 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -730,7 +730,10 @@ def get_daily_prorata_based_straight_line_depr( def get_daily_depr_amount(asset, row, schedule_idx, amount): - if cint(frappe.db.get_single_value("Accounts Settings", "calculate_depr_using_total_days")): + if ( + frappe.db.get_single_value("Accounts Settings", "calculate_daily_depreciation_using") + == "Total days in depreciation period" + ): total_days = ( date_diff( get_last_day( diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py index c9fa0ba59da..c25a9faec67 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py @@ -76,7 +76,9 @@ class TestAssetDepreciationSchedule(FrappeTestCase): self.assertEqual(schedules, expected_schedules) def test_schedule_for_slm_for_existing_asset_daily_pro_rata_enabled(self): - frappe.db.set_single_value("Accounts Settings", "calculate_depr_using_total_days", 1) + frappe.db.set_single_value( + "Accounts Settings", "calculate_daily_depreciation_using", "Total days in depreciation period" + ) asset = create_asset( calculate_depreciation=1, depreciation_method="Straight Line", @@ -114,7 +116,9 @@ class TestAssetDepreciationSchedule(FrappeTestCase): for d in get_depr_schedule(asset.name, "Draft") ] self.assertEqual(schedules, expected_schedules) - frappe.db.set_single_value("Accounts Settings", "calculate_depr_using_total_days", 0) + frappe.db.set_single_value( + "Accounts Settings", "calculate_daily_depreciation_using", "Total years in depreciation period" + ) def test_schedule_for_slm_for_existing_asset(self): asset = create_asset( @@ -187,7 +191,9 @@ class TestAssetDepreciationSchedule(FrappeTestCase): # Enable Checkbox to Calculate depreciation using total days in depreciation period def test_daily_prorata_based_depr_after_enabling_configuration(self): - frappe.db.set_single_value("Accounts Settings", "calculate_depr_using_total_days", 1) + frappe.db.set_single_value( + "Accounts Settings", "calculate_daily_depreciation_using", "Total days in depreciation period" + ) asset = create_asset( calculate_depreciation=1, @@ -245,7 +251,9 @@ class TestAssetDepreciationSchedule(FrappeTestCase): for d in get_depr_schedule(asset.name, "Draft") ] self.assertEqual(schedules, expected_schedule) - frappe.db.set_single_value("Accounts Settings", "calculate_depr_using_total_days", 0) + frappe.db.set_single_value( + "Accounts Settings", "calculate_daily_depreciation_using", "Total years in depreciation period" + ) # Test for Written Down Value Method # Frequency of deprciation = 3 diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 8ff0719344e..ab58841df45 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -408,3 +408,4 @@ erpnext.patches.v15_0.update_invoice_remarks erpnext.patches.v15_0.add_disassembly_order_stock_entry_type #1 erpnext.patches.v15_0.set_standard_stock_entry_type erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter +erpnext.patches.v15_0.update_checkbox_to_select #1 diff --git a/erpnext/patches/v15_0/update_checkbox_to_select.py b/erpnext/patches/v15_0/update_checkbox_to_select.py new file mode 100644 index 00000000000..85ba58fd904 --- /dev/null +++ b/erpnext/patches/v15_0/update_checkbox_to_select.py @@ -0,0 +1,13 @@ +import frappe +from frappe.utils import cint + + +def execute(): + if cint(frappe.db.get_single_value("Accounts Settings", "calculate_depr_using_total_days")): + frappe.db.set_single_value( + "Accounts Settings", "calculate_daily_depreciation_using", "Total days in depreciation period" + ) + else: + frappe.db.set_single_value( + "Accounts Settings", "calculate_daily_depreciation_using", "Total years in depreciation period" + ) -- GitLab From 1c99ccfe34f849d20fd83a5dd305d2e40ab06c5e Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Mon, 21 Oct 2024 04:40:55 +0530 Subject: [PATCH 2/2] fix: removed checkbox --- .../accounts_settings/accounts_settings.json | 11 ++--------- .../doctype/accounts_settings/accounts_settings.py | 1 - erpnext/patches.txt | 1 - erpnext/patches/v15_0/update_checkbox_to_select.py | 13 ------------- 4 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 erpnext/patches/v15_0/update_checkbox_to_select.py diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 3ffc629f2fa..0e2d02ce044 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -58,7 +58,6 @@ "post_change_gl_entries", "assets_tab", "asset_settings_section", - "calculate_depr_using_total_days", "calculate_daily_depreciation_using", "column_break_gjcc", "book_asset_depreciation_entry_automatically", @@ -491,13 +490,6 @@ "fieldname": "column_break_gjcc", "fieldtype": "Column Break" }, - { - "default": "0", - "description": "Enable this option to calculate daily depreciation by considering the total number of days in the entire depreciation period, (including leap years) while using daily pro-rata based depreciation", - "fieldname": "calculate_depr_using_total_days", - "fieldtype": "Check", - "label": "Calculate daily depreciation using total days in depreciation period" - }, { "fieldname": "france_section", "fieldtype": "Section Break", @@ -512,6 +504,7 @@ }, { "default": "Total years in depreciation period", + "description": "This field lets you select your preferred method for calculating pro rata depreciation. Each approach has different implication. For detailed explanations, please refer to the Documentation.", "fieldname": "calculate_daily_depreciation_using", "fieldtype": "Select", "label": "Calculate Daily Pro-rata Depreciation Using", @@ -523,7 +516,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-10-16 15:41:03.548766", + "modified": "2024-10-21 04:29:02.556355", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py index 269e54574b5..c11406dff88 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py @@ -36,7 +36,6 @@ class AccountsSettings(Document): calculate_daily_depreciation_using: DF.Literal[ "Total days in depreciation period", "Total years in depreciation period" ] - calculate_depr_using_total_days: DF.Check check_supplier_invoice_uniqueness: DF.Check credit_controller: DF.Link | None default_payment_days: DF.Int diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ab58841df45..8ff0719344e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -408,4 +408,3 @@ erpnext.patches.v15_0.update_invoice_remarks erpnext.patches.v15_0.add_disassembly_order_stock_entry_type #1 erpnext.patches.v15_0.set_standard_stock_entry_type erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter -erpnext.patches.v15_0.update_checkbox_to_select #1 diff --git a/erpnext/patches/v15_0/update_checkbox_to_select.py b/erpnext/patches/v15_0/update_checkbox_to_select.py deleted file mode 100644 index 85ba58fd904..00000000000 --- a/erpnext/patches/v15_0/update_checkbox_to_select.py +++ /dev/null @@ -1,13 +0,0 @@ -import frappe -from frappe.utils import cint - - -def execute(): - if cint(frappe.db.get_single_value("Accounts Settings", "calculate_depr_using_total_days")): - frappe.db.set_single_value( - "Accounts Settings", "calculate_daily_depreciation_using", "Total days in depreciation period" - ) - else: - frappe.db.set_single_value( - "Accounts Settings", "calculate_daily_depreciation_using", "Total years in depreciation period" - ) -- GitLab