Merge pull request #31637 from nabinhait/asset-monthly-depreciation

fix: Removed 'Allow Monthly Depreciation' checkbox
This commit is contained in:
Nabin Hait 2022-07-20 15:38:17 +05:30 committed by GitHub
commit 4951a1f0e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 65 deletions

View File

@ -40,7 +40,6 @@
"purchase_date", "purchase_date",
"section_break_23", "section_break_23",
"calculate_depreciation", "calculate_depreciation",
"allow_monthly_depreciation",
"column_break_33", "column_break_33",
"opening_accumulated_depreciation", "opening_accumulated_depreciation",
"number_of_depreciations_booked", "number_of_depreciations_booked",
@ -456,13 +455,6 @@
"fieldname": "dimension_col_break", "fieldname": "dimension_col_break",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{
"default": "0",
"depends_on": "calculate_depreciation",
"fieldname": "allow_monthly_depreciation",
"fieldtype": "Check",
"label": "Allow Monthly Depreciation"
},
{ {
"collapsible": 1, "collapsible": 1,
"collapsible_depends_on": "is_existing_asset", "collapsible_depends_on": "is_existing_asset",
@ -518,7 +510,7 @@
"link_fieldname": "asset" "link_fieldname": "asset"
} }
], ],
"modified": "2022-01-30 20:19:24.680027", "modified": "2022-07-20 10:15:12.887372",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset", "name": "Asset",

View File

@ -343,51 +343,13 @@ class Asset(AccountsController):
skip_row = True skip_row = True
if depreciation_amount > 0: if depreciation_amount > 0:
# With monthly depreciation, each depreciation is divided by months remaining until next date self._add_depreciation_row(
if self.allow_monthly_depreciation: schedule_date,
# month range is 1 to 12 depreciation_amount,
# In pro rata case, for first and last depreciation, month range would be different finance_book.depreciation_method,
month_range = ( finance_book.finance_book,
months finance_book.idx,
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,
)
def _add_depreciation_row( def _add_depreciation_row(
self, schedule_date, depreciation_amount, depreciation_method, finance_book, finance_book_id self, schedule_date, depreciation_amount, depreciation_method, finance_book, finance_book_id
@ -854,10 +816,8 @@ class Asset(AccountsController):
return args.get("rate_of_depreciation") return args.get("rate_of_depreciation")
value = flt(args.get("expected_value_after_useful_life")) / flt(self.gross_purchase_amount) 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)) depreciation_rate = math.pow(value, 1.0 / flt(args.get("total_number_of_depreciations"), 2))
return flt((100 * (1 - depreciation_rate)), float_precision)
return 100 * (1 - flt(depreciation_rate, float_precision))
def get_pro_rata_amt(self, row, depreciation_amount, from_date, to_date): def get_pro_rata_amt(self, row, depreciation_amount, from_date, to_date):
days = date_diff(to_date, from_date) days = date_diff(to_date, from_date)

View File

@ -721,12 +721,12 @@ class TestDepreciationMethods(AssetSetup):
) )
expected_schedules = [ expected_schedules = [
["2022-02-28", 645.0, 645.0], ["2022-02-28", 647.25, 647.25],
["2022-03-31", 1206.8, 1851.8], ["2022-03-31", 1210.71, 1857.96],
["2022-04-30", 1051.12, 2902.92], ["2022-04-30", 1053.99, 2911.95],
["2022-05-31", 915.52, 3818.44], ["2022-05-31", 917.55, 3829.5],
["2022-06-30", 797.42, 4615.86], ["2022-06-30", 798.77, 4628.27],
["2022-07-15", 384.14, 5000.0], ["2022-07-15", 371.73, 5000.0],
] ]
schedules = [ schedules = [
@ -737,7 +737,6 @@ class TestDepreciationMethods(AssetSetup):
] ]
for d in asset.get("schedules") for d in asset.get("schedules")
] ]
self.assertEqual(schedules, expected_schedules) self.assertEqual(schedules, expected_schedules)

View File

@ -347,3 +347,4 @@ erpnext.patches.v14_0.copy_is_subcontracted_value_to_is_old_subcontracting_flow
erpnext.patches.v14_0.migrate_gl_to_payment_ledger erpnext.patches.v14_0.migrate_gl_to_payment_ledger
erpnext.patches.v14_0.crm_ux_cleanup erpnext.patches.v14_0.crm_ux_cleanup
erpnext.patches.v14_0.remove_india_localisation # 14-07-2022 erpnext.patches.v14_0.remove_india_localisation # 14-07-2022
erpnext.patches.v13_0.fix_number_and_frequency_for_monthly_depreciation

View File

@ -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()

View File

@ -208,6 +208,8 @@ def repost_future_sle(
via_landed_cost_voucher=False, via_landed_cost_voucher=False,
doc=None, doc=None,
): ):
if not args:
args = [] # set args to empty list if None to avoid enumerate error
items_to_be_repost = get_items_to_be_repost( items_to_be_repost = get_items_to_be_repost(
voucher_type=voucher_type, voucher_no=voucher_no, doc=doc voucher_type=voucher_type, voucher_no=voucher_no, doc=doc
@ -303,7 +305,7 @@ def get_items_to_be_repost(voucher_type=None, voucher_no=None, doc=None):
group_by="item_code, warehouse", group_by="item_code, warehouse",
) )
return items_to_be_repost return items_to_be_repost or []
def get_distinct_item_warehouse(args=None, doc=None): def get_distinct_item_warehouse(args=None, doc=None):