fix: Removed 'Allow Monthly Depreciation' checkbox
diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json
index 6e6bbf1..991df4e 100644
--- a/erpnext/assets/doctype/asset/asset.json
+++ b/erpnext/assets/doctype/asset/asset.json
@@ -40,7 +40,6 @@
"purchase_date",
"section_break_23",
"calculate_depreciation",
- "allow_monthly_depreciation",
"column_break_33",
"opening_accumulated_depreciation",
"number_of_depreciations_booked",
@@ -457,13 +456,6 @@
"fieldtype": "Column Break"
},
{
- "default": "0",
- "depends_on": "calculate_depreciation",
- "fieldname": "allow_monthly_depreciation",
- "fieldtype": "Check",
- "label": "Allow Monthly Depreciation"
- },
- {
"collapsible": 1,
"collapsible_depends_on": "is_existing_asset",
"fieldname": "purchase_details_section",
@@ -518,7 +510,7 @@
"link_fieldname": "asset"
}
],
- "modified": "2022-01-30 20:19:24.680027",
+ "modified": "2022-07-20 10:15:12.887372",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index a880c2f..a22d70d 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -343,51 +343,13 @@
skip_row = True
if depreciation_amount > 0:
- # With monthly depreciation, each depreciation is divided by months remaining until next date
- if self.allow_monthly_depreciation:
- # month range is 1 to 12
- # In pro rata case, for first and last depreciation, month range would be different
- month_range = (
- months
- if (has_pro_rata and n == 0)
- or (has_pro_rata and n == cint(number_of_pending_depreciations) - 1)
- else finance_book.frequency_of_depreciation
- )
-
- for r in range(month_range):
- if has_pro_rata and n == 0:
- # For first entry of monthly depr
- if r == 0:
- days_until_first_depr = date_diff(monthly_schedule_date, self.available_for_use_date)
- per_day_amt = depreciation_amount / days
- depreciation_amount_for_current_month = per_day_amt * days_until_first_depr
- depreciation_amount -= depreciation_amount_for_current_month
- date = monthly_schedule_date
- amount = depreciation_amount_for_current_month
- else:
- date = add_months(monthly_schedule_date, r)
- amount = depreciation_amount / (month_range - 1)
- elif (has_pro_rata and n == cint(number_of_pending_depreciations) - 1) and r == cint(
- month_range
- ) - 1:
- # For last entry of monthly depr
- date = last_schedule_date
- amount = depreciation_amount / month_range
- else:
- date = add_months(monthly_schedule_date, r)
- amount = depreciation_amount / month_range
-
- self._add_depreciation_row(
- date, amount, finance_book.depreciation_method, finance_book.finance_book, finance_book.idx
- )
- else:
- self._add_depreciation_row(
- schedule_date,
- depreciation_amount,
- finance_book.depreciation_method,
- finance_book.finance_book,
- finance_book.idx,
- )
+ self._add_depreciation_row(
+ schedule_date,
+ depreciation_amount,
+ finance_book.depreciation_method,
+ finance_book.finance_book,
+ finance_book.idx,
+ )
def _add_depreciation_row(
self, schedule_date, depreciation_amount, depreciation_method, finance_book, finance_book_id
@@ -854,10 +816,8 @@
return args.get("rate_of_depreciation")
value = flt(args.get("expected_value_after_useful_life")) / flt(self.gross_purchase_amount)
-
depreciation_rate = math.pow(value, 1.0 / flt(args.get("total_number_of_depreciations"), 2))
-
- return 100 * (1 - flt(depreciation_rate, float_precision))
+ return flt((100 * (1 - depreciation_rate)), float_precision)
def get_pro_rata_amt(self, row, depreciation_amount, from_date, to_date):
days = date_diff(to_date, from_date)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index c3476f9..34122a5 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -347,3 +347,4 @@
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
erpnext.patches.v14_0.crm_ux_cleanup
erpnext.patches.v14_0.remove_india_localisation # 14-07-2022
+erpnext.patches.v13_0.fix_number_and_frequency_for_monthly_depreciation
\ No newline at end of file
diff --git a/erpnext/patches/v13_0/fix_number_and_frequency_for_monthly_depreciation.py b/erpnext/patches/v13_0/fix_number_and_frequency_for_monthly_depreciation.py
new file mode 100644
index 0000000..e827058
--- /dev/null
+++ b/erpnext/patches/v13_0/fix_number_and_frequency_for_monthly_depreciation.py
@@ -0,0 +1,14 @@
+import frappe
+
+
+def execute():
+ assets = frappe.get_all("Asset", filters={"allow_monthly_depreciation": 1})
+
+ for d in assets:
+ print(d.name)
+ asset_doc = frappe.get_doc("Asset", d.name)
+ for i in asset_doc.get("finance_books"):
+ if i.frequency_of_depreciation != 1:
+ i.total_number_of_depreciations *= i.frequency_of_depreciation
+ i.frequency_of_depreciation = 1
+ i.db_update()