From 9d8cb2f57c91b653e2d09be7f5701b061b36ca28 Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Tue, 5 Aug 2025 14:00:27 +0530 Subject: [PATCH 1/6] fix: submit depreciation schedule only for submitted asset (cherry picked from commit a4628c20241494cc0df8d6058b0d0ab9464408d6) # Conflicts: # erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py --- .../asset_depreciation_schedule.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index f9c4913b1a2..bdbf7322757 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -98,9 +98,30 @@ class AssetDepreciationSchedule(Document): ) def on_submit(self): + self.validate_asset() self.db_set("status", "Active") +<<<<<<< HEAD def before_cancel(self): +======= + def validate_asset(self): + asset = frappe.get_doc("Asset", self.asset) + if not asset.calculate_depreciation: + frappe.throw( + _("Asset {0} is not set to calculate depreciation.").format( + get_link_to_form("Asset", self.asset) + ) + ) + if asset.docstatus != 1: + frappe.throw( + _("Asset {0} is not submitted. Please submit the asset before proceeding.").format( + get_link_to_form("Asset", self.asset) + ) + ) + + def on_cancel(self): + self.db_set("status", "Cancelled") +>>>>>>> a4628c2024 (fix: submit depreciation schedule only for submitted asset) if not self.flags.should_not_cancel_depreciation_entries: self.cancel_depreciation_entries() From 37eaa07192f58314fef022442845af05834be499 Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Tue, 5 Aug 2025 14:16:05 +0530 Subject: [PATCH 2/6] fix: validate if journal entry linked to schedule is in draft (cherry picked from commit d5edca202227d83b6694fcbca19d04f82189c184) --- .../asset_depreciation_schedule.py | 6 ++ .../doctype/item_price/test_records.json | 56 ------------------- 2 files changed, 6 insertions(+), 56 deletions(-) delete mode 100644 erpnext/stock/doctype/item_price/test_records.json diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index bdbf7322757..c6750ee99c4 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -128,6 +128,12 @@ class AssetDepreciationSchedule(Document): def cancel_depreciation_entries(self): for d in self.get("depreciation_schedule"): if d.journal_entry: + if d.journal_entry == "Draft": + frappe.throw( + _( + "Cannot cancel Asset Depreciation Schedule {0} as it has a draft journal entry {1}." + ).format(self.name, d.journal_entry) + ) frappe.get_doc("Journal Entry", d.journal_entry).cancel() def on_cancel(self): diff --git a/erpnext/stock/doctype/item_price/test_records.json b/erpnext/stock/doctype/item_price/test_records.json deleted file mode 100644 index afe5ad65b75..00000000000 --- a/erpnext/stock/doctype/item_price/test_records.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "doctype": "Item Price", - "item_code": "_Test Item", - "price_list": "_Test Price List", - "price_list_rate": 100, - "valid_from": "2017-04-18", - "valid_upto": "2017-04-26" - }, - { - "doctype": "Item Price", - "item_code": "_Test Item", - "price_list": "_Test Price List Rest of the World", - "price_list_rate": 10 - }, - { - "doctype": "Item Price", - "item_code": "_Test Item 2", - "price_list": "_Test Price List Rest of the World", - "price_list_rate": 20, - "valid_from": "2017-04-18", - "valid_upto": "2017-04-26", - "customer": "_Test Customer", - "uom": "_Test UOM" - }, - { - "doctype": "Item Price", - "item_code": "_Test Item Home Desktop 100", - "price_list": "_Test Price List", - "price_list_rate": 1000, - "valid_from": "2017-04-10", - "valid_upto": "2017-04-17" - }, - { - "doctype": "Item Price", - "item_code": "_Test Item Home Desktop Manufactured", - "price_list": "_Test Price List", - "price_list_rate": 1000, - "valid_from": "2017-04-10", - "valid_upto": "2017-04-17" - }, - { - "doctype": "Item Price", - "item_code": "_Test Item", - "price_list": "_Test Buying Price List", - "price_list_rate": 100, - "supplier": "_Test Supplier" - }, - { - "doctype": "Item Price", - "item_code": "_Test Item", - "price_list": "_Test Selling Price List", - "price_list_rate": 200, - "customer": "_Test Customer" - } -] From 137d2d4044664d46c9455235d55e7a120f3079dd Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Tue, 5 Aug 2025 14:19:53 +0530 Subject: [PATCH 3/6] chore: add mistakenly removed test records (cherry picked from commit f5a71c6b88b42019e694018348f05e6fa8fbe257) --- .../doctype/item_price/test_records.json | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 erpnext/stock/doctype/item_price/test_records.json diff --git a/erpnext/stock/doctype/item_price/test_records.json b/erpnext/stock/doctype/item_price/test_records.json new file mode 100644 index 00000000000..afe5ad65b75 --- /dev/null +++ b/erpnext/stock/doctype/item_price/test_records.json @@ -0,0 +1,56 @@ +[ + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Price List", + "price_list_rate": 100, + "valid_from": "2017-04-18", + "valid_upto": "2017-04-26" + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Price List Rest of the World", + "price_list_rate": 10 + }, + { + "doctype": "Item Price", + "item_code": "_Test Item 2", + "price_list": "_Test Price List Rest of the World", + "price_list_rate": 20, + "valid_from": "2017-04-18", + "valid_upto": "2017-04-26", + "customer": "_Test Customer", + "uom": "_Test UOM" + }, + { + "doctype": "Item Price", + "item_code": "_Test Item Home Desktop 100", + "price_list": "_Test Price List", + "price_list_rate": 1000, + "valid_from": "2017-04-10", + "valid_upto": "2017-04-17" + }, + { + "doctype": "Item Price", + "item_code": "_Test Item Home Desktop Manufactured", + "price_list": "_Test Price List", + "price_list_rate": 1000, + "valid_from": "2017-04-10", + "valid_upto": "2017-04-17" + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Buying Price List", + "price_list_rate": 100, + "supplier": "_Test Supplier" + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Selling Price List", + "price_list_rate": 200, + "customer": "_Test Customer" + } +] From 497247d89acfc5e52bbd1782d18a31834267ea75 Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Tue, 5 Aug 2025 14:34:39 +0530 Subject: [PATCH 4/6] chore: fetch docstatus to validate (cherry picked from commit d6fb99916e1d33ccd63675401211acc15a2bcb0a) --- .../asset_depreciation_schedule/asset_depreciation_schedule.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index c6750ee99c4..c4180fa68c0 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -128,7 +128,8 @@ class AssetDepreciationSchedule(Document): def cancel_depreciation_entries(self): for d in self.get("depreciation_schedule"): if d.journal_entry: - if d.journal_entry == "Draft": + je_status = frappe.db.get_value("Journal Entry", d.journal_entry, "docstatus") + if je_status == 0: frappe.throw( _( "Cannot cancel Asset Depreciation Schedule {0} as it has a draft journal entry {1}." From 4f14651a4220d1ae9fde0e2d5364603ecc607369 Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Tue, 5 Aug 2025 15:06:57 +0530 Subject: [PATCH 5/6] chore: resolved conflicts --- .../asset_depreciation_schedule.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index c4180fa68c0..53a9d1dba09 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -101,9 +101,6 @@ class AssetDepreciationSchedule(Document): self.validate_asset() self.db_set("status", "Active") -<<<<<<< HEAD - def before_cancel(self): -======= def validate_asset(self): asset = frappe.get_doc("Asset", self.asset) if not asset.calculate_depreciation: @@ -121,7 +118,6 @@ class AssetDepreciationSchedule(Document): def on_cancel(self): self.db_set("status", "Cancelled") ->>>>>>> a4628c2024 (fix: submit depreciation schedule only for submitted asset) if not self.flags.should_not_cancel_depreciation_entries: self.cancel_depreciation_entries() From 35f826c4997ccdca0891605b17b518dca00937ff Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Tue, 5 Aug 2025 15:54:11 +0530 Subject: [PATCH 6/6] chore: remove duplicate code --- .../asset_depreciation_schedule/asset_depreciation_schedule.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index 53a9d1dba09..e1413096af3 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -133,9 +133,6 @@ class AssetDepreciationSchedule(Document): ) frappe.get_doc("Journal Entry", d.journal_entry).cancel() - def on_cancel(self): - self.db_set("status", "Cancelled") - def update_shift_depr_schedule(self): if not self.shift_based or self.docstatus != 0: return