From 939a3121b76a8cc2d194c1c5d48b4c1bfc842a7c Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Mon, 30 Jan 2023 22:10:51 +0530 Subject: [PATCH] fix: disposal_was_made_on_original_schedule_date --- erpnext/assets/doctype/asset/asset.py | 7 +------ erpnext/assets/doctype/asset/depreciation.py | 20 +++++++++++++++++++- erpnext/assets/doctype/asset/test_asset.py | 7 +------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index af32f93cf050..eb8ae92548f2 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -27,6 +27,7 @@ from erpnext.assets.doctype.asset.depreciation import ( get_depreciation_accounts, get_disposal_account_and_cost_center, + is_last_day_of_the_month, ) from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account from erpnext.controllers.accounts_controller import AccountsController @@ -1078,12 +1079,6 @@ def get_total_days(date, frequency): return date_diff(date, period_start_date) -def is_last_day_of_the_month(date): - last_day_of_the_month = get_last_day(date) - - return getdate(last_day_of_the_month) == getdate(date) - - @erpnext.allow_regional def get_depreciation_amount(asset, depreciable_value, row): if row.depreciation_method in ("Straight Line", "Manual"): diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index 66dd2e98dc5a..3f3fcf249c95 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -4,7 +4,16 @@ import frappe from frappe import _ -from frappe.utils import add_months, cint, flt, get_link_to_form, getdate, nowdate, today +from frappe.utils import ( + add_months, + cint, + flt, + get_last_day, + get_link_to_form, + getdate, + nowdate, + today, +) from frappe.utils.user import get_users_with_role from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( @@ -372,6 +381,9 @@ def disposal_was_made_on_original_schedule_date(asset, schedule, row, posting_da finance_book.depreciation_start_date, row * cint(finance_book.frequency_of_depreciation) ) + if is_last_day_of_the_month(finance_book.depreciation_start_date): + orginal_schedule_date = get_last_day(orginal_schedule_date) + if orginal_schedule_date == posting_date_of_disposal: return True return False @@ -508,3 +520,9 @@ def get_disposal_account_and_cost_center(company): frappe.throw(_("Please set 'Asset Depreciation Cost Center' in Company {0}").format(company)) return disposal_account, depreciation_cost_center + + +def is_last_day_of_the_month(date): + last_day_of_the_month = get_last_day(date) + + return getdate(last_day_of_the_month) == getdate(date) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index d133cebedb82..35b2750ed213 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -18,6 +18,7 @@ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.assets.doctype.asset.asset import make_sales_invoice, update_maintenance_status from erpnext.assets.doctype.asset.depreciation import ( + is_last_day_of_the_month, post_depreciation_entries, restore_asset, scrap_asset, @@ -1529,9 +1530,3 @@ def set_depreciation_settings_in_company(): def enable_cwip_accounting(asset_category, enable=1): frappe.db.set_value("Asset Category", asset_category, "enable_cwip_accounting", enable) - - -def is_last_day_of_the_month(dt): - last_day_of_the_month = get_last_day(dt) - - return getdate(dt) == getdate(last_day_of_the_month)