From fb1b30fac4620bcccf3835a92b8e795232cf5091 Mon Sep 17 00:00:00 2001 From: Devansh Shetty Date: Mon, 15 Sep 2025 14:25:40 +0000 Subject: [PATCH] fix: create_asset_depreciation_schedules_from_assets override the patch --- rohit_common/__init__.py | 7 +++++++ rohit_common/before_migrate_patches.py | 6 +++--- .../patches/asset_depr_schedule_patch_utils.py | 15 +++++++++++++++ rohit_common/rohit_common/validations/asset.py | 4 ++-- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 rohit_common/patches/asset_depr_schedule_patch_utils.py diff --git a/rohit_common/__init__.py b/rohit_common/__init__.py index d5793af..0bb3cca 100644 --- a/rohit_common/__init__.py +++ b/rohit_common/__init__.py @@ -1 +1,8 @@ __version__ = "15.0.0" + +# Monkey-patch AssetDepreciationSchedule to add set_draft_asset_depr_schedule_details + +from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import AssetDepreciationSchedule +from rohit_common.patches.asset_depr_schedule_patch_utils import set_draft_asset_depr_schedule_details +AssetDepreciationSchedule.set_draft_asset_depr_schedule_details = set_draft_asset_depr_schedule_details + diff --git a/rohit_common/before_migrate_patches.py b/rohit_common/before_migrate_patches.py index 57f158e..b001204 100644 --- a/rohit_common/before_migrate_patches.py +++ b/rohit_common/before_migrate_patches.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- + import frappe import erpnext - def execute (): add_default_company_fy() @@ -10,8 +10,8 @@ def add_default_company_fy(): fyd = frappe.db.get_list('Fiscal Year', fields=['name'], order_by='year_start_date asc') def_comp = erpnext.get_default_company() for fy in fyd: - fyc = frappe.db.get_list("Fiscal Year Company", filters={"parent": fy.name, - "parentfield": "companies", + fyc = frappe.db.get_list("Fiscal Year Company", filters={"parent": fy.name, + "parentfield": "companies", "parenttype": "Fiscal Year"}) if not fyc: print(f"No Company defined for FY {fy.name} so setting to Default Company {def_comp}") diff --git a/rohit_common/patches/asset_depr_schedule_patch_utils.py b/rohit_common/patches/asset_depr_schedule_patch_utils.py new file mode 100644 index 0000000..c6d8ae4 --- /dev/null +++ b/rohit_common/patches/asset_depr_schedule_patch_utils.py @@ -0,0 +1,15 @@ +def set_draft_asset_depr_schedule_details(self, asset_doc, row): + self.asset = asset_doc.name + self.finance_book = row.finance_book + self.finance_book_id = row.idx + self.opening_accumulated_depreciation = asset_doc.opening_accumulated_depreciation or 0 + self.opening_number_of_booked_depreciations = asset_doc.opening_number_of_booked_depreciations or 0 + self.gross_purchase_amount = asset_doc.gross_purchase_amount + self.depreciation_method = row.depreciation_method + self.total_number_of_depreciations = row.total_number_of_depreciations + self.frequency_of_depreciation = row.frequency_of_depreciation + self.rate_of_depreciation = row.rate_of_depreciation + self.expected_value_after_useful_life = row.expected_value_after_useful_life + self.daily_prorata_based = row.daily_prorata_based + self.shift_based = row.shift_based + self.status = "Draft" \ No newline at end of file diff --git a/rohit_common/rohit_common/validations/asset.py b/rohit_common/rohit_common/validations/asset.py index 1e2f7b9..460e96f 100644 --- a/rohit_common/rohit_common/validations/asset.py +++ b/rohit_common/rohit_common/validations/asset.py @@ -46,8 +46,8 @@ def validate(doc, method): for d in fb_list: doc.append("finance_books", d) #frappe.throw("Finance Book Entry is Mandatory") - base_dep_date = get_next_dep_date(doc, dep_freq, tot_no_of_deps) - make_dep_schedule(doc, base_dep_date, exp_val_aft_life, dep_freq, tot_no_of_deps) + # base_dep_date = get_next_dep_date(doc, dep_freq, tot_no_of_deps) + # make_dep_schedule(doc, base_dep_date, exp_val_aft_life, dep_freq, tot_no_of_deps) def autoname(doc, method): if doc.get_automatic_name == 1: