From 3fc3305251162108183e5348b961c0ebee31700f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 11 Apr 2017 16:00:48 +0530 Subject: [PATCH 1/3] bom traversing: argument mutable issue --- erpnext/manufacturing/doctype/bom/bom.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index abb2817e4f..b8a8ae8aea 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -281,12 +281,15 @@ class BOM(WebsiteGenerator): return bom_list - def traverse_tree(self, bom_list=[]): + def traverse_tree(self, bom_list=None): def _get_children(bom_no): return [cstr(d[0]) for d in frappe.db.sql("""select bom_no from `tabBOM Item` where parent = %s and ifnull(bom_no, '') != ''""", bom_no)] count = 0 + if not bom_list: + bom_list = [] + if self.name not in bom_list: bom_list.append(self.name) From 8a019807572447a6aa0f431d50137a32d43b1580 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 18 Apr 2017 13:11:10 +0530 Subject: [PATCH 2/3] Unlink Journal Entry reference from Asset --- .../accounts/doctype/journal_entry/journal_entry.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index a471c48c57..b9b8fc2968 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -72,6 +72,7 @@ class JournalEntry(AccountsController): self.update_expense_claim() self.update_employee_loan() self.unlink_advance_entry_reference() + self.unlink_asset_reference() def unlink_advance_entry_reference(self): for d in self.get("accounts"): @@ -81,6 +82,18 @@ class JournalEntry(AccountsController): d.reference_type = '' d.reference_name = '' d.db_update() + + def unlink_asset_reference(self): + for d in self.get("accounts"): + if d.reference_type=="Asset" and d.reference_name: + asset = frappe.get_doc("Asset", d.reference_name) + for s in asset.get("schedules"): + if s.journal_entry == self.name: + s.db_set("journal_entry", None) + asset.value_after_depreciation += s.depreciation_amount + + asset.db_set("value_after_depreciation", asset.value_after_depreciation) + asset.set_status() def validate_party(self): for d in self.get("accounts"): From 117be7ddd5208ad1eece3e4e61c4dbdf77b13aad Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 18 Apr 2017 14:02:07 +0530 Subject: [PATCH 3/3] Added a settings in Accounts Settings to disable booking depreciation entry automatically --- .../accounts_settings/accounts_settings.json | 64 +++++++++++++++++-- .../accounts/doctype/asset/depreciation.py | 4 ++ erpnext/accounts/doctype/asset/test_asset.py | 22 ++++++- erpnext/demo/user/fixed_asset.py | 3 + erpnext/patches.txt | 3 +- ...ooking_asset_depreciation_automatically.py | 9 +++ 6 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v8_0/enable_booking_asset_depreciation_automatically.py diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 7a4d40d6ee..4f268a24cc 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -1,5 +1,6 @@ { "allow_copy": 0, + "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, "beta": 0, @@ -25,7 +26,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Make Accounting Entry For Every Stock Movement", "length": 0, "no_copy": 0, @@ -33,6 +36,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -51,7 +55,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Accounts Frozen Upto", "length": 0, "no_copy": 0, @@ -59,6 +65,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -77,7 +84,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Role Allowed to Set Frozen Accounts & Edit Frozen Entries", "length": 0, "no_copy": 0, @@ -86,6 +95,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -103,7 +113,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, + "in_standard_filter": 0, "length": 0, "no_copy": 0, "permlevel": 0, @@ -111,6 +123,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -129,7 +142,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Credit Controller", "length": 0, "no_copy": 0, @@ -138,6 +153,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -155,7 +171,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Check Supplier Invoice Number Uniqueness", "length": 0, "no_copy": 0, @@ -164,6 +182,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -181,7 +200,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Make Payment via Journal Entry", "length": 0, "no_copy": 0, @@ -190,6 +211,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -208,7 +230,9 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Unlink Payment on Cancellation of Invoice", "length": 0, "no_copy": 0, @@ -217,6 +241,37 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "1", + "fieldname": "book_asset_depreciation_entry_automatically", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Book Asset Depreciation Entry Automatically", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -224,18 +279,18 @@ "unique": 0 } ], + "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, - "icon": "fa fa-cog", + "icon": "icon-cog", "idx": 1, "image_view": 0, "in_create": 0, - "in_dialog": 0, "is_submittable": 0, "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2016-10-20 16:12:38.595075", + "modified": "2017-04-18 13:35:59.166250", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", @@ -251,7 +306,6 @@ "export": 0, "if_owner": 0, "import": 0, - "is_custom": 0, "permlevel": 0, "print": 1, "read": 1, @@ -266,6 +320,8 @@ "quick_entry": 1, "read_only": 0, "read_only_onload": 0, + "show_name_in_global_search": 0, "sort_order": "ASC", + "track_changes": 1, "track_seen": 0 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/asset/depreciation.py b/erpnext/accounts/doctype/asset/depreciation.py index 15c155c7ac..397342dc46 100644 --- a/erpnext/accounts/doctype/asset/depreciation.py +++ b/erpnext/accounts/doctype/asset/depreciation.py @@ -8,6 +8,10 @@ from frappe import _ from frappe.utils import flt, today, getdate def post_depreciation_entries(date=None): + # Return if automatic booking of asset depreciation is disabled + if not frappe.db.get_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically"): + return + if not date: date = today() for asset in get_depreciable_assets(date): diff --git a/erpnext/accounts/doctype/asset/test_asset.py b/erpnext/accounts/doctype/asset/test_asset.py index 51496b918c..000bc5ccd2 100644 --- a/erpnext/accounts/doctype/asset/test_asset.py +++ b/erpnext/accounts/doctype/asset/test_asset.py @@ -166,6 +166,23 @@ class TestAsset(unittest.TestCase): self.assertEqual(gle, expected_gle) self.assertEqual(asset.get("value_after_depreciation"), 70000) + + def test_depreciation_entry_cancellation(self): + asset = frappe.get_doc("Asset", "Macbook Pro 1") + asset.submit() + post_depreciation_entries(date="2021-01-01") + + asset.load_from_db() + + # cancel depreciation entry + depr_entry = asset.get("schedules")[0].journal_entry + self.assertTrue(depr_entry) + frappe.get_doc("Journal Entry", depr_entry).cancel() + + asset.load_from_db() + depr_entry = asset.get("schedules")[0].journal_entry + self.assertFalse(depr_entry) + def test_scrap_asset(self): asset = frappe.get_doc("Asset", "Macbook Pro 1") @@ -297,4 +314,7 @@ def set_depreciation_settings_in_company(): company.depreciation_expense_account = "_Test Depreciations - _TC" company.disposal_account = "_Test Gain/Loss on Asset Disposal - _TC" company.depreciation_cost_center = "_Test Cost Center - _TC" - company.save() \ No newline at end of file + company.save() + + # Enable booking asset depreciation entry automatically + frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1) \ No newline at end of file diff --git a/erpnext/demo/user/fixed_asset.py b/erpnext/demo/user/fixed_asset.py index bf3199ea5f..b2db39c9f0 100644 --- a/erpnext/demo/user/fixed_asset.py +++ b/erpnext/demo/user/fixed_asset.py @@ -18,6 +18,9 @@ def work(): # fixed_asset.work() already run return + # Enable booking asset depreciation entry automatically + frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1) + # post depreciation entries as on today post_depreciation_entries() diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 522c4fca9c..6881fd6db4 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -386,4 +386,5 @@ execute:frappe.delete_doc('DocType', 'Purchase Common') erpnext.patches.v8_0.update_stock_qty_value_in_purchase_invoice erpnext.patches.v8_0.update_supplier_address_in_stock_entry erpnext.patches.v8_0.rename_is_sample_item_to_allow_zero_valuation_rate -erpnext.patches.v8_0.set_null_to_serial_nos_for_disabled_sales_invoices \ No newline at end of file +erpnext.patches.v8_0.set_null_to_serial_nos_for_disabled_sales_invoices +erpnext.patches.v8_0.enable_booking_asset_depreciation_automatically \ No newline at end of file diff --git a/erpnext/patches/v8_0/enable_booking_asset_depreciation_automatically.py b/erpnext/patches/v8_0/enable_booking_asset_depreciation_automatically.py new file mode 100644 index 0000000000..1088d702dd --- /dev/null +++ b/erpnext/patches/v8_0/enable_booking_asset_depreciation_automatically.py @@ -0,0 +1,9 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.db.set_value("Accounts Settings", None, + "book_asset_depreciation_entry_automatically", 1) \ No newline at end of file