diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index 411e1efe8ea..04e9c32f379 100644 --- a/erpnext/assets/doctype/asset/asset.json +++ b/erpnext/assets/doctype/asset/asset.json @@ -38,7 +38,6 @@ "purchase_date", "section_break_23", "calculate_depreciation", - "allow_monthly_depreciation", "column_break_33", "opening_accumulated_depreciation", "number_of_depreciations_booked", @@ -454,13 +453,6 @@ "fieldname": "dimension_col_break", "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", @@ -503,7 +495,7 @@ "link_fieldname": "asset" } ], - "modified": "2022-01-30 20:19:24.680027", + "modified": "2022-07-20 16:22:44.437579", "modified_by": "Administrator", "module": "Assets", "name": "Asset", @@ -545,4 +537,4 @@ "sort_order": "DESC", "title_field": "asset_name", "track_changes": 1 -} +} \ No newline at end of file diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 4d63a285534..1ce815ae2bd 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -353,61 +353,16 @@ class Asset(AccountsController): 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 - 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( - "schedules", - { - "schedule_date": schedule_date, - "depreciation_amount": depreciation_amount, - "depreciation_method": finance_book.depreciation_method, - "finance_book": finance_book.finance_book, - "finance_book_id": finance_book.idx, - }, - ) + self.append( + "schedules", + { + "schedule_date": schedule_date, + "depreciation_amount": depreciation_amount, + "depreciation_method": finance_book.depreciation_method, + "finance_book": finance_book.finance_book, + "finance_book_id": finance_book.idx, + }, + ) # depreciation schedules need to be cleared before modification due to increase in asset life/asset sales # JE: Journal Entry, FB: Finance Book @@ -853,7 +808,7 @@ class Asset(AccountsController): 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/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 9bfafaf8657..13475f34c39 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -145,6 +145,7 @@ class TestAsset(AssetSetup): def test_is_fixed_asset_set(self): asset = create_asset(is_existing_asset=1) doc = frappe.new_doc("Purchase Invoice") + doc.company = "_Test Company" doc.supplier = "_Test Supplier" 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) 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( calculate_depreciation=1, available_for_use_date="2022-02-15", @@ -715,12 +718,12 @@ class TestDepreciationMethods(AssetSetup): ) expected_schedules = [ - ["2022-02-28", 645.0, 645.0], - ["2022-03-31", 1206.8, 1851.8], - ["2022-04-30", 1051.12, 2902.92], - ["2022-05-31", 915.52, 3818.44], - ["2022-06-30", 797.42, 4615.86], - ["2022-07-15", 384.14, 5000.0], + ["2022-02-28", 647.25, 647.25], + ["2022-03-31", 1210.71, 1857.96], + ["2022-04-30", 1053.99, 2911.95], + ["2022-05-31", 917.55, 3829.5], + ["2022-06-30", 798.77, 4628.27], + ["2022-07-15", 371.73, 5000.0], ] schedules = [ @@ -731,8 +734,8 @@ class TestDepreciationMethods(AssetSetup): ] for d in asset.get("schedules") ] - self.assertEqual(schedules, expected_schedules) + frappe.db.set_default("float_precision", existing_precision) class TestDepreciationBasics(AssetSetup): diff --git a/erpnext/patches.txt b/erpnext/patches.txt index bdc43dd094a..8e8e2b25299 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -368,4 +368,5 @@ erpnext.patches.v13_0.set_per_billed_in_return_delivery_note erpnext.patches.v13_0.update_employee_advance_status erpnext.patches.v13_0.job_card_status_on_hold erpnext.patches.v13_0.add_cost_center_in_loans -erpnext.patches.v13_0.show_india_localisation_deprecation_warning \ No newline at end of file +erpnext.patches.v13_0.show_india_localisation_deprecation_warning +erpnext.patches.v13_0.fix_number_and_frequency_for_monthly_depreciation 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 00000000000..fe645c81b88 --- /dev/null +++ b/erpnext/patches/v13_0/fix_number_and_frequency_for_monthly_depreciation.py @@ -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() diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index c3cf8ad56f4..4e64b7b1833 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -207,6 +207,8 @@ def repost_future_sle( allow_negative_stock=None, 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( voucher_type=voucher_type, voucher_no=voucher_no, doc=doc