fix: Removed 'Allow Monthly Depreciation' checkbox and fixed wdv depreciation rate
This commit is contained in:
@@ -38,7 +38,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",
|
||||||
@@ -454,13 +453,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",
|
||||||
@@ -503,7 +495,7 @@
|
|||||||
"link_fieldname": "asset"
|
"link_fieldname": "asset"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2022-01-30 20:19:24.680027",
|
"modified": "2022-07-20 16:22:44.437579",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Assets",
|
"module": "Assets",
|
||||||
"name": "Asset",
|
"name": "Asset",
|
||||||
|
|||||||
@@ -353,51 +353,6 @@ 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
|
|
||||||
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
|
|
||||||
if (has_pro_rata and n == 0 and not self.number_of_depreciations_booked) or (
|
|
||||||
has_pro_rata and n == cint(number_of_pending_depreciations) - 1
|
|
||||||
):
|
|
||||||
month_range = months
|
|
||||||
else:
|
|
||||||
month_range = finance_book.frequency_of_depreciation
|
|
||||||
|
|
||||||
for r in range(month_range):
|
|
||||||
if has_pro_rata and n == 0 and not self.number_of_depreciations_booked:
|
|
||||||
# For first entry of monthly depr
|
|
||||||
if r == 0:
|
|
||||||
days_until_first_depr = date_diff(monthly_schedule_date, self.available_for_use_date) + 1
|
|
||||||
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.append(
|
|
||||||
"schedules",
|
|
||||||
{
|
|
||||||
"schedule_date": date,
|
|
||||||
"depreciation_amount": amount,
|
|
||||||
"depreciation_method": finance_book.depreciation_method,
|
|
||||||
"finance_book": finance_book.finance_book,
|
|
||||||
"finance_book_id": finance_book.idx,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.append(
|
self.append(
|
||||||
"schedules",
|
"schedules",
|
||||||
{
|
{
|
||||||
@@ -853,7 +808,7 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
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 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):
|
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)
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ class TestAsset(AssetSetup):
|
|||||||
def test_is_fixed_asset_set(self):
|
def test_is_fixed_asset_set(self):
|
||||||
asset = create_asset(is_existing_asset=1)
|
asset = create_asset(is_existing_asset=1)
|
||||||
doc = frappe.new_doc("Purchase Invoice")
|
doc = frappe.new_doc("Purchase Invoice")
|
||||||
|
doc.company = "_Test Company"
|
||||||
doc.supplier = "_Test Supplier"
|
doc.supplier = "_Test Supplier"
|
||||||
doc.append("items", {"item_code": "Macbook Pro", "qty": 1, "asset": asset.name})
|
doc.append("items", {"item_code": "Macbook Pro", "qty": 1, "asset": asset.name})
|
||||||
|
|
||||||
@@ -702,6 +703,8 @@ class TestDepreciationMethods(AssetSetup):
|
|||||||
self.assertEquals(asset.finance_books[0].value_after_depreciation, 98000.0)
|
self.assertEquals(asset.finance_books[0].value_after_depreciation, 98000.0)
|
||||||
|
|
||||||
def test_monthly_depreciation_by_wdv_method(self):
|
def test_monthly_depreciation_by_wdv_method(self):
|
||||||
|
existing_precision = frappe.db.get_default("float_precision")
|
||||||
|
frappe.db.set_default("float_precision", 3)
|
||||||
asset = create_asset(
|
asset = create_asset(
|
||||||
calculate_depreciation=1,
|
calculate_depreciation=1,
|
||||||
available_for_use_date="2022-02-15",
|
available_for_use_date="2022-02-15",
|
||||||
@@ -715,12 +718,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 = [
|
||||||
@@ -731,8 +734,8 @@ 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)
|
||||||
|
frappe.db.set_default("float_precision", existing_precision)
|
||||||
|
|
||||||
|
|
||||||
class TestDepreciationBasics(AssetSetup):
|
class TestDepreciationBasics(AssetSetup):
|
||||||
|
|||||||
@@ -369,3 +369,4 @@ erpnext.patches.v13_0.update_employee_advance_status
|
|||||||
erpnext.patches.v13_0.job_card_status_on_hold
|
erpnext.patches.v13_0.job_card_status_on_hold
|
||||||
erpnext.patches.v13_0.add_cost_center_in_loans
|
erpnext.patches.v13_0.add_cost_center_in_loans
|
||||||
erpnext.patches.v13_0.show_india_localisation_deprecation_warning
|
erpnext.patches.v13_0.show_india_localisation_deprecation_warning
|
||||||
|
erpnext.patches.v13_0.fix_number_and_frequency_for_monthly_depreciation
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
if not frappe.db.has_column("Asset", "allow_monthly_depreciation"):
|
||||||
|
return
|
||||||
|
|
||||||
|
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()
|
||||||
@@ -207,6 +207,8 @@ def repost_future_sle(
|
|||||||
allow_negative_stock=None,
|
allow_negative_stock=None,
|
||||||
via_landed_cost_voucher=False,
|
via_landed_cost_voucher=False,
|
||||||
):
|
):
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user