From d00c59830ef476e6ba2c5939f8aeafdc9f6805de Mon Sep 17 00:00:00 2001 From: Marica Date: Tue, 12 Nov 2019 19:17:43 +0530 Subject: [PATCH] feat: Disable CWIP Accounting checkbox added in Company and Asset Category (#19262) * feat: Disable CWIP Accounting checkbox added in Company and Asset Category Asset Settings is removed completely Disable CWIP Accounting checkbox will give priority to Asset Category * fix: Changed checkbox name to 'Enable Capital Work in Progress Accounting' - checkbox will be disabled by default - Enabling it in Company will globally enable it - When globally disabled , it's value on the asset category will be considered * chore: Added patch to set pre-existing CWIP checkbox value into new checkbox * fix(test): Asset * fix: Asset Test and Patch * fix(test): Opening Invoice Creation Tool * Update asset.py * fix: Patch and other fixes --- .../purchase_invoice/purchase_invoice.py | 29 +- erpnext/accounts/general_ledger.py | 12 +- erpnext/assets/doctype/asset/asset.js | 17 +- erpnext/assets/doctype/asset/asset.json | 994 +++++++++--------- erpnext/assets/doctype/asset/asset.py | 21 +- erpnext/assets/doctype/asset/test_asset.py | 41 +- .../asset_category/asset_category.json | 363 ++----- .../doctype/asset_category/asset_category.py | 13 + .../assets/doctype/asset_settings/__init__.py | 0 .../doctype/asset_settings/asset_settings.js | 5 - .../asset_settings/asset_settings.json | 148 --- .../doctype/asset_settings/asset_settings.py | 9 - .../asset_settings/test_asset_settings.js | 23 - .../asset_settings/test_asset_settings.py | 9 - erpnext/config/assets.py | 4 - erpnext/patches.txt | 1 + .../set_cwip_and_delete_asset_settings.py | 22 + erpnext/setup/doctype/company/company.json | 21 +- .../purchase_receipt/purchase_receipt.py | 12 +- 19 files changed, 723 insertions(+), 1021 deletions(-) delete mode 100644 erpnext/assets/doctype/asset_settings/__init__.py delete mode 100644 erpnext/assets/doctype/asset_settings/asset_settings.js delete mode 100644 erpnext/assets/doctype/asset_settings/asset_settings.json delete mode 100644 erpnext/assets/doctype/asset_settings/asset_settings.py delete mode 100644 erpnext/assets/doctype/asset_settings/test_asset_settings.js delete mode 100644 erpnext/assets/doctype/asset_settings/test_asset_settings.py create mode 100644 erpnext/patches/v12_0/set_cwip_and_delete_asset_settings.py diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 9c1a9ece77..f1c490e2cd 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -18,7 +18,7 @@ from erpnext.accounts.general_ledger import make_gl_entries, merge_similar_entri from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt from erpnext.buying.utils import check_on_hold_or_closed_status from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center -from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accounting_disabled +from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accounting_enabled from frappe.model.mapper import get_mapped_doc from six import iteritems from erpnext.accounts.doctype.sales_invoice.sales_invoice import validate_inter_company_party, update_linked_doc,\ @@ -226,6 +226,8 @@ class PurchaseInvoice(BuyingController): # in case of auto inventory accounting, # expense account is always "Stock Received But Not Billed" for a stock item # except epening entry, drop-ship entry and fixed asset items + if item.item_code: + asset_category = frappe.get_cached_value("Item", item.item_code, "asset_category") if auto_accounting_for_stock and item.item_code in stock_items \ and self.is_opening == 'No' and not item.is_fixed_asset \ @@ -236,7 +238,8 @@ class PurchaseInvoice(BuyingController): item.expense_account = warehouse_account[item.warehouse]["account"] else: item.expense_account = stock_not_billed_account - elif item.is_fixed_asset and is_cwip_accounting_disabled(): + + elif item.is_fixed_asset and not is_cwip_accounting_enabled(self.company, asset_category): if not item.asset: frappe.throw(_("Row {0}: asset is required for item {1}") .format(item.idx, item.item_code)) @@ -392,7 +395,8 @@ class PurchaseInvoice(BuyingController): self.make_supplier_gl_entry(gl_entries) self.make_item_gl_entries(gl_entries) - if not is_cwip_accounting_disabled(): + + if self.check_asset_cwip_enabled(): self.get_asset_gl_entry(gl_entries) self.make_tax_gl_entries(gl_entries) @@ -405,6 +409,15 @@ class PurchaseInvoice(BuyingController): return gl_entries + def check_asset_cwip_enabled(self): + # Check if there exists any item with cwip accounting enabled in it's asset category + for item in self.get("items"): + if item.item_code and item.is_fixed_asset: + asset_category = frappe.get_cached_value("Item", item.item_code, "asset_category") + if is_cwip_accounting_enabled(self.company, asset_category): + return 1 + return 0 + def make_supplier_gl_entry(self, gl_entries): # Checked both rounding_adjustment and rounded_total # because rounded_total had value even before introcution of posting GLE based on rounded total @@ -448,6 +461,8 @@ class PurchaseInvoice(BuyingController): for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) + if item.item_code: + asset_category = frappe.get_cached_value("Item", item.item_code, "asset_category") if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items: # warehouse account @@ -490,8 +505,9 @@ class PurchaseInvoice(BuyingController): "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost) }, warehouse_account[self.supplier_warehouse]["account_currency"], item=item)) - elif not item.is_fixed_asset or (item.is_fixed_asset and is_cwip_accounting_disabled()): + elif not item.is_fixed_asset or (item.is_fixed_asset and not is_cwip_accounting_enabled(self.company, + asset_category)): expense_account = (item.expense_account if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account) @@ -532,7 +548,10 @@ class PurchaseInvoice(BuyingController): def get_asset_gl_entry(self, gl_entries): for item in self.get("items"): - if item.is_fixed_asset: + if item.item_code and item.is_fixed_asset : + asset_category = frappe.get_cached_value("Item", item.item_code, "asset_category") + + if item.is_fixed_asset and is_cwip_accounting_enabled(self.company, asset_category) : eiiav_account = self.get_company_default("expenses_included_in_asset_valuation") asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 43d9ad6435..d4dac72601 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -168,14 +168,20 @@ def validate_account_for_perpetual_inventory(gl_map): StockValueAndAccountBalanceOutOfSync) def validate_cwip_accounts(gl_map): - if not cint(frappe.db.get_value("Asset Settings", None, "disable_cwip_accounting")) \ - and gl_map[0].voucher_type == "Journal Entry": + cwip_enabled = cint(frappe.get_cached_value("Company", + gl_map[0].company, "enable_cwip_accounting")) + + if not cwip_enabled: + cwip_enabled = any([cint(ac.enable_cwip_accounting) for ac in frappe.db.get_all("Asset Category","enable_cwip_accounting")]) + + if cwip_enabled and gl_map[0].voucher_type == "Journal Entry": cwip_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount where account_type = 'Capital Work in Progress' and is_group=0""")] for entry in gl_map: if entry.account in cwip_accounts: - frappe.throw(_("Account: {0} is capital Work in progress and can not be updated by Journal Entry").format(entry.account)) + frappe.throw( + _("Account: {0} is capital Work in progress and can not be updated by Journal Entry").format(entry.account)) def round_off_debit_credit(gl_map): precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index c5cad73801..c7390a2ef1 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -203,7 +203,7 @@ frappe.ui.form.on('Asset', { }, opening_accumulated_depreciation: function(frm) { - erpnext.asset.set_accululated_depreciation(frm); + erpnext.asset.set_accumulated_depreciation(frm); }, make_schedules_editable: function(frm) { @@ -282,17 +282,6 @@ frappe.ui.form.on('Asset', { }, calculate_depreciation: function(frm) { - frappe.db.get_value("Asset Settings", {'name':"Asset Settings"}, 'schedule_based_on_fiscal_year', (data) => { - if (data.schedule_based_on_fiscal_year == 1) { - frm.set_df_property("depreciation_method", "options", "\nStraight Line\nManual"); - frm.toggle_reqd("available_for_use_date", true); - frm.toggle_display("frequency_of_depreciation", false); - frappe.db.get_value("Fiscal Year", {'name': frappe.sys_defaults.fiscal_year}, "year_end_date", (data) => { - frm.set_value("next_depreciation_date", data.year_end_date); - }) - } - }) - frm.toggle_reqd("finance_books", frm.doc.calculate_depreciation); }, @@ -371,12 +360,12 @@ frappe.ui.form.on('Depreciation Schedule', { }, depreciation_amount: function(frm, cdt, cdn) { - erpnext.asset.set_accululated_depreciation(frm); + erpnext.asset.set_accumulated_depreciation(frm); } }) -erpnext.asset.set_accululated_depreciation = function(frm) { +erpnext.asset.set_accumulated_depreciation = function(frm) { if(frm.doc.depreciation_method != "Manual") return; var accumulated_depreciation = flt(frm.doc.opening_accumulated_depreciation); diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index c60ec5ec3f..8fda330bb7 100644 --- a/erpnext/assets/doctype/asset/asset.json +++ b/erpnext/assets/doctype/asset/asset.json @@ -1,497 +1,499 @@ { - "allow_import": 1, - "allow_rename": 1, - "autoname": "naming_series:", - "creation": "2016-03-01 17:01:27.920130", - "doctype": "DocType", - "document_type": "Document", - "field_order": [ - "naming_series", - "asset_name", - "item_code", - "item_name", - "asset_category", - "asset_owner", - "asset_owner_company", - "supplier", - "customer", - "image", - "column_break_3", - "company", - "location", - "custodian", - "department", - "purchase_date", - "disposal_date", - "journal_entry_for_scrap", - "accounting_dimensions_section", - "cost_center", - "dimension_col_break", - "section_break_5", - "gross_purchase_amount", - "available_for_use_date", - "column_break_18", - "calculate_depreciation", - "is_existing_asset", - "opening_accumulated_depreciation", - "number_of_depreciations_booked", - "section_break_23", - "finance_books", - "section_break_33", - "depreciation_method", - "value_after_depreciation", - "total_number_of_depreciations", - "column_break_24", - "frequency_of_depreciation", - "next_depreciation_date", - "section_break_14", - "schedules", - "insurance_details", - "policy_number", - "insurer", - "insured_value", - "column_break_48", - "insurance_start_date", - "insurance_end_date", - "comprehensive_insurance", - "section_break_31", - "maintenance_required", - "other_details", - "status", - "booked_fixed_asset", - "column_break_51", - "purchase_receipt", - "purchase_receipt_amount", - "purchase_invoice", - "default_finance_book", - "amended_from" - ], - "fields": [ - { - "fieldname": "naming_series", - "fieldtype": "Select", - "label": "Naming Series", - "options": "ACC-ASS-.YYYY.-" - }, - { - "fieldname": "asset_name", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Asset Name", - "reqd": 1 - }, - { - "fieldname": "item_code", - "fieldtype": "Link", - "in_standard_filter": 1, - "label": "Item Code", - "options": "Item", - "reqd": 1 - }, - { - "fetch_from": "item_code.item_name", - "fieldname": "item_name", - "fieldtype": "Read Only", - "label": "Item Name" - }, - { - "fetch_from": "item_code.asset_category", - "fieldname": "asset_category", - "fieldtype": "Link", - "in_global_search": 1, - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Asset Category", - "options": "Asset Category", - "read_only": 1 - }, - { - "fieldname": "asset_owner", - "fieldtype": "Select", - "label": "Asset Owner", - "options": "\nCompany\nSupplier\nCustomer" - }, - { - "depends_on": "eval:doc.asset_owner == \"Company\"", - "fieldname": "asset_owner_company", - "fieldtype": "Link", - "label": "Asset Owner Company", - "options": "Company" - }, - { - "depends_on": "eval:doc.asset_owner == \"Supplier\"", - "fieldname": "supplier", - "fieldtype": "Link", - "label": "Supplier", - "options": "Supplier" - }, - { - "depends_on": "eval:doc.asset_owner == \"Customer\"", - "fieldname": "customer", - "fieldtype": "Link", - "label": "Customer", - "options": "Customer" - }, - { - "allow_on_submit": 1, - "fieldname": "image", - "fieldtype": "Attach Image", - "hidden": 1, - "label": "Image", - "no_copy": 1, - "print_hide": 1 - }, - { - "fieldname": "column_break_3", - "fieldtype": "Column Break" - }, - { - "fieldname": "company", - "fieldtype": "Link", - "label": "Company", - "options": "Company", - "remember_last_selected_value": 1, - "reqd": 1 - }, - { - "fieldname": "location", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Location", - "options": "Location", - "reqd": 1 - }, - { - "fieldname": "custodian", - "fieldtype": "Link", - "ignore_user_permissions": 1, - "label": "Custodian", - "options": "Employee" - }, - { - "fieldname": "cost_center", - "fieldtype": "Link", - "label": "Cost Center", - "options": "Cost Center" - }, - { - "fieldname": "department", - "fieldtype": "Link", - "label": "Department", - "options": "Department" - }, - { - "fieldname": "purchase_date", - "fieldtype": "Date", - "label": "Purchase Date", - "reqd": 1 - }, - { - "fieldname": "disposal_date", - "fieldtype": "Date", - "label": "Disposal Date", - "read_only": 1 - }, - { - "fieldname": "journal_entry_for_scrap", - "fieldtype": "Link", - "label": "Journal Entry for Scrap", - "no_copy": 1, - "options": "Journal Entry", - "print_hide": 1, - "read_only": 1 - }, - { - "fieldname": "section_break_5", - "fieldtype": "Section Break" - }, - { - "fieldname": "gross_purchase_amount", - "fieldtype": "Currency", - "label": "Gross Purchase Amount", - "options": "Company:company:default_currency", - "reqd": 1 - }, - { - "fieldname": "available_for_use_date", - "fieldtype": "Date", - "label": "Available-for-use Date" - }, - { - "fieldname": "column_break_18", - "fieldtype": "Column Break" - }, - { - "default": "0", - "fieldname": "calculate_depreciation", - "fieldtype": "Check", - "label": "Calculate Depreciation" - }, - { - "default": "0", - "fieldname": "is_existing_asset", - "fieldtype": "Check", - "label": "Is Existing Asset" - }, - { - "depends_on": "is_existing_asset", - "fieldname": "opening_accumulated_depreciation", - "fieldtype": "Currency", - "label": "Opening Accumulated Depreciation", - "no_copy": 1, - "options": "Company:company:default_currency" - }, - { - "depends_on": "eval:(doc.is_existing_asset && doc.opening_accumulated_depreciation)", - "fieldname": "number_of_depreciations_booked", - "fieldtype": "Int", - "label": "Number of Depreciations Booked", - "no_copy": 1 - }, - { - "depends_on": "calculate_depreciation", - "fieldname": "section_break_23", - "fieldtype": "Section Break", - "label": "Depreciation" - }, - { - "fieldname": "finance_books", - "fieldtype": "Table", - "label": "Finance Books", - "options": "Asset Finance Book" - }, - { - "fieldname": "section_break_33", - "fieldtype": "Section Break", - "hidden": 1 - }, - { - "fieldname": "depreciation_method", - "fieldtype": "Select", - "label": "Depreciation Method", - "options": "\nStraight Line\nDouble Declining Balance\nManual" - }, - { - "fieldname": "value_after_depreciation", - "fieldtype": "Currency", - "hidden": 1, - "label": "Value After Depreciation", - "options": "Company:company:default_currency", - "read_only": 1 - }, - { - "fieldname": "total_number_of_depreciations", - "fieldtype": "Int", - "label": "Total Number of Depreciations" - }, - { - "fieldname": "column_break_24", - "fieldtype": "Column Break" - }, - { - "fieldname": "frequency_of_depreciation", - "fieldtype": "Int", - "label": "Frequency of Depreciation (Months)" - }, - { - "fieldname": "next_depreciation_date", - "fieldtype": "Date", - "label": "Next Depreciation Date", - "no_copy": 1 - }, - { - "depends_on": "calculate_depreciation", - "fieldname": "section_break_14", - "fieldtype": "Section Break", - "label": "Depreciation Schedule" - }, - { - "fieldname": "schedules", - "fieldtype": "Table", - "label": "Depreciation Schedules", - "no_copy": 1, - "options": "Depreciation Schedule" - }, - { - "collapsible": 1, - "fieldname": "insurance_details", - "fieldtype": "Section Break", - "label": "Insurance details" - }, - { - "fieldname": "policy_number", - "fieldtype": "Data", - "label": "Policy number" - }, - { - "fieldname": "insurer", - "fieldtype": "Data", - "label": "Insurer" - }, - { - "fieldname": "insured_value", - "fieldtype": "Data", - "label": "Insured value" - }, - { - "fieldname": "column_break_48", - "fieldtype": "Column Break" - }, - { - "fieldname": "insurance_start_date", - "fieldtype": "Date", - "label": "Insurance Start Date" - }, - { - "fieldname": "insurance_end_date", - "fieldtype": "Date", - "label": "Insurance End Date" - }, - { - "fieldname": "comprehensive_insurance", - "fieldtype": "Data", - "label": "Comprehensive Insurance" - }, - { - "fieldname": "section_break_31", - "fieldtype": "Section Break", - "label": "Maintenance" - }, - { - "allow_on_submit": 1, - "default": "0", - "description": "Check if Asset requires Preventive Maintenance or Calibration", - "fieldname": "maintenance_required", - "fieldtype": "Check", - "label": "Maintenance Required" - }, - { - "collapsible": 1, - "fieldname": "other_details", - "fieldtype": "Section Break", - "label": "Other Details" - }, - { - "allow_on_submit": 1, - "default": "Draft", - "fieldname": "status", - "fieldtype": "Select", - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Status", - "no_copy": 1, - "options": "Draft\nSubmitted\nPartially Depreciated\nFully Depreciated\nSold\nScrapped\nIn Maintenance\nOut of Order\nIssue\nReceipt", - "read_only": 1 - }, - { - "default": "0", - "fieldname": "booked_fixed_asset", - "fieldtype": "Check", - "label": "Booked Fixed Asset", - "no_copy": 1, - "read_only": 1 - }, - { - "fieldname": "column_break_51", - "fieldtype": "Column Break" - }, - { - "fieldname": "purchase_receipt", - "fieldtype": "Link", - "label": "Purchase Receipt", - "no_copy": 1, - "options": "Purchase Receipt", - "print_hide": 1, - "read_only": 1 - }, - { - "fieldname": "purchase_receipt_amount", - "fieldtype": "Currency", - "hidden": 1, - "label": "Purchase Receipt Amount", - "no_copy": 1, - "print_hide": 1, - "read_only": 1 - }, - { - "fieldname": "purchase_invoice", - "fieldtype": "Link", - "label": "Purchase Invoice", - "no_copy": 1, - "options": "Purchase Invoice", - "read_only": 1 - }, - { - "fetch_from": "company.default_finance_book", - "fieldname": "default_finance_book", - "fieldtype": "Link", - "hidden": 1, - "label": "Default Finance Book", - "options": "Finance Book", - "read_only": 1 - }, - { - "fieldname": "amended_from", - "fieldtype": "Link", - "label": "Amended From", - "no_copy": 1, - "options": "Asset", - "print_hide": 1, - "read_only": 1 - }, - { - "collapsible": 1, - "fieldname": "accounting_dimensions_section", - "fieldtype": "Section Break", - "label": "Accounting Dimensions" - }, - { - "fieldname": "dimension_col_break", - "fieldtype": "Column Break" - } - ], - "idx": 72, - "image_field": "image", - "is_submittable": 1, - "modified": "2019-05-25 22:26:19.786201", - "modified_by": "Administrator", - "module": "Assets", - "name": "Asset", - "owner": "Administrator", - "permissions": [ - { - "amend": 1, - "cancel": 1, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "import": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Accounts User", - "share": 1, - "submit": 1, - "write": 1 - }, - { - "cancel": 1, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Quality Manager", - "share": 1, - "submit": 1, - "write": 1 - } - ], - "show_name_in_global_search": 1, - "sort_field": "modified", - "sort_order": "DESC", - "title_field": "asset_name" - } \ No newline at end of file + "allow_import": 1, + "allow_rename": 1, + "autoname": "naming_series:", + "creation": "2016-03-01 17:01:27.920130", + "doctype": "DocType", + "document_type": "Document", + "engine": "InnoDB", + "field_order": [ + "naming_series", + "asset_name", + "item_code", + "item_name", + "asset_category", + "asset_owner", + "asset_owner_company", + "supplier", + "customer", + "image", + "column_break_3", + "company", + "location", + "custodian", + "department", + "purchase_date", + "disposal_date", + "journal_entry_for_scrap", + "accounting_dimensions_section", + "cost_center", + "dimension_col_break", + "section_break_5", + "gross_purchase_amount", + "available_for_use_date", + "column_break_18", + "calculate_depreciation", + "is_existing_asset", + "opening_accumulated_depreciation", + "number_of_depreciations_booked", + "section_break_23", + "finance_books", + "section_break_33", + "depreciation_method", + "value_after_depreciation", + "total_number_of_depreciations", + "column_break_24", + "frequency_of_depreciation", + "next_depreciation_date", + "section_break_14", + "schedules", + "insurance_details", + "policy_number", + "insurer", + "insured_value", + "column_break_48", + "insurance_start_date", + "insurance_end_date", + "comprehensive_insurance", + "section_break_31", + "maintenance_required", + "other_details", + "status", + "booked_fixed_asset", + "column_break_51", + "purchase_receipt", + "purchase_receipt_amount", + "purchase_invoice", + "default_finance_book", + "amended_from" + ], + "fields": [ + { + "fieldname": "naming_series", + "fieldtype": "Select", + "label": "Naming Series", + "options": "ACC-ASS-.YYYY.-" + }, + { + "fieldname": "asset_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Asset Name", + "reqd": 1 + }, + { + "fieldname": "item_code", + "fieldtype": "Link", + "in_standard_filter": 1, + "label": "Item Code", + "options": "Item", + "reqd": 1 + }, + { + "fetch_from": "item_code.item_name", + "fieldname": "item_name", + "fieldtype": "Read Only", + "label": "Item Name" + }, + { + "fetch_from": "item_code.asset_category", + "fieldname": "asset_category", + "fieldtype": "Link", + "in_global_search": 1, + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Asset Category", + "options": "Asset Category", + "read_only": 1 + }, + { + "fieldname": "asset_owner", + "fieldtype": "Select", + "label": "Asset Owner", + "options": "\nCompany\nSupplier\nCustomer" + }, + { + "depends_on": "eval:doc.asset_owner == \"Company\"", + "fieldname": "asset_owner_company", + "fieldtype": "Link", + "label": "Asset Owner Company", + "options": "Company" + }, + { + "depends_on": "eval:doc.asset_owner == \"Supplier\"", + "fieldname": "supplier", + "fieldtype": "Link", + "label": "Supplier", + "options": "Supplier" + }, + { + "depends_on": "eval:doc.asset_owner == \"Customer\"", + "fieldname": "customer", + "fieldtype": "Link", + "label": "Customer", + "options": "Customer" + }, + { + "allow_on_submit": 1, + "fieldname": "image", + "fieldtype": "Attach Image", + "hidden": 1, + "label": "Image", + "no_copy": 1, + "print_hide": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "remember_last_selected_value": 1, + "reqd": 1 + }, + { + "fieldname": "location", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Location", + "options": "Location", + "reqd": 1 + }, + { + "fieldname": "custodian", + "fieldtype": "Link", + "ignore_user_permissions": 1, + "label": "Custodian", + "options": "Employee" + }, + { + "fieldname": "cost_center", + "fieldtype": "Link", + "label": "Cost Center", + "options": "Cost Center" + }, + { + "fieldname": "department", + "fieldtype": "Link", + "label": "Department", + "options": "Department" + }, + { + "fieldname": "purchase_date", + "fieldtype": "Date", + "label": "Purchase Date", + "reqd": 1 + }, + { + "fieldname": "disposal_date", + "fieldtype": "Date", + "label": "Disposal Date", + "read_only": 1 + }, + { + "fieldname": "journal_entry_for_scrap", + "fieldtype": "Link", + "label": "Journal Entry for Scrap", + "no_copy": 1, + "options": "Journal Entry", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "section_break_5", + "fieldtype": "Section Break" + }, + { + "fieldname": "gross_purchase_amount", + "fieldtype": "Currency", + "label": "Gross Purchase Amount", + "options": "Company:company:default_currency", + "reqd": 1 + }, + { + "fieldname": "available_for_use_date", + "fieldtype": "Date", + "label": "Available-for-use Date", + "reqd": 1 + }, + { + "fieldname": "column_break_18", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "calculate_depreciation", + "fieldtype": "Check", + "label": "Calculate Depreciation" + }, + { + "default": "0", + "fieldname": "is_existing_asset", + "fieldtype": "Check", + "label": "Is Existing Asset" + }, + { + "depends_on": "is_existing_asset", + "fieldname": "opening_accumulated_depreciation", + "fieldtype": "Currency", + "label": "Opening Accumulated Depreciation", + "no_copy": 1, + "options": "Company:company:default_currency" + }, + { + "depends_on": "eval:(doc.is_existing_asset && doc.opening_accumulated_depreciation)", + "fieldname": "number_of_depreciations_booked", + "fieldtype": "Int", + "label": "Number of Depreciations Booked", + "no_copy": 1 + }, + { + "depends_on": "calculate_depreciation", + "fieldname": "section_break_23", + "fieldtype": "Section Break", + "label": "Depreciation" + }, + { + "fieldname": "finance_books", + "fieldtype": "Table", + "label": "Finance Books", + "options": "Asset Finance Book" + }, + { + "fieldname": "section_break_33", + "fieldtype": "Section Break", + "hidden": 1 + }, + { + "fieldname": "depreciation_method", + "fieldtype": "Select", + "label": "Depreciation Method", + "options": "\nStraight Line\nDouble Declining Balance\nManual" + }, + { + "fieldname": "value_after_depreciation", + "fieldtype": "Currency", + "hidden": 1, + "label": "Value After Depreciation", + "options": "Company:company:default_currency", + "read_only": 1 + }, + { + "fieldname": "total_number_of_depreciations", + "fieldtype": "Int", + "label": "Total Number of Depreciations" + }, + { + "fieldname": "column_break_24", + "fieldtype": "Column Break" + }, + { + "fieldname": "frequency_of_depreciation", + "fieldtype": "Int", + "label": "Frequency of Depreciation (Months)" + }, + { + "fieldname": "next_depreciation_date", + "fieldtype": "Date", + "label": "Next Depreciation Date", + "no_copy": 1 + }, + { + "depends_on": "calculate_depreciation", + "fieldname": "section_break_14", + "fieldtype": "Section Break", + "label": "Depreciation Schedule" + }, + { + "fieldname": "schedules", + "fieldtype": "Table", + "label": "Depreciation Schedules", + "no_copy": 1, + "options": "Depreciation Schedule" + }, + { + "collapsible": 1, + "fieldname": "insurance_details", + "fieldtype": "Section Break", + "label": "Insurance details" + }, + { + "fieldname": "policy_number", + "fieldtype": "Data", + "label": "Policy number" + }, + { + "fieldname": "insurer", + "fieldtype": "Data", + "label": "Insurer" + }, + { + "fieldname": "insured_value", + "fieldtype": "Data", + "label": "Insured value" + }, + { + "fieldname": "column_break_48", + "fieldtype": "Column Break" + }, + { + "fieldname": "insurance_start_date", + "fieldtype": "Date", + "label": "Insurance Start Date" + }, + { + "fieldname": "insurance_end_date", + "fieldtype": "Date", + "label": "Insurance End Date" + }, + { + "fieldname": "comprehensive_insurance", + "fieldtype": "Data", + "label": "Comprehensive Insurance" + }, + { + "fieldname": "section_break_31", + "fieldtype": "Section Break", + "label": "Maintenance" + }, + { + "allow_on_submit": 1, + "default": "0", + "description": "Check if Asset requires Preventive Maintenance or Calibration", + "fieldname": "maintenance_required", + "fieldtype": "Check", + "label": "Maintenance Required" + }, + { + "collapsible": 1, + "fieldname": "other_details", + "fieldtype": "Section Break", + "label": "Other Details" + }, + { + "allow_on_submit": 1, + "default": "Draft", + "fieldname": "status", + "fieldtype": "Select", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Status", + "no_copy": 1, + "options": "Draft\nSubmitted\nPartially Depreciated\nFully Depreciated\nSold\nScrapped\nIn Maintenance\nOut of Order\nIssue\nReceipt", + "read_only": 1 + }, + { + "default": "0", + "fieldname": "booked_fixed_asset", + "fieldtype": "Check", + "label": "Booked Fixed Asset", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_51", + "fieldtype": "Column Break" + }, + { + "fieldname": "purchase_receipt", + "fieldtype": "Link", + "label": "Purchase Receipt", + "no_copy": 1, + "options": "Purchase Receipt", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "purchase_receipt_amount", + "fieldtype": "Currency", + "hidden": 1, + "label": "Purchase Receipt Amount", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "purchase_invoice", + "fieldtype": "Link", + "label": "Purchase Invoice", + "no_copy": 1, + "options": "Purchase Invoice", + "read_only": 1 + }, + { + "fetch_from": "company.default_finance_book", + "fieldname": "default_finance_book", + "fieldtype": "Link", + "hidden": 1, + "label": "Default Finance Book", + "options": "Finance Book", + "read_only": 1 + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Asset", + "print_hide": 1, + "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "accounting_dimensions_section", + "fieldtype": "Section Break", + "label": "Accounting Dimensions" + }, + { + "fieldname": "dimension_col_break", + "fieldtype": "Column Break" + } + ], + "idx": 72, + "image_field": "image", + "is_submittable": 1, + "modified": "2019-10-07 15:34:30.976208", + "modified_by": "Administrator", + "module": "Assets", + "name": "Asset", + "owner": "Administrator", + "permissions": [ + { + "amend": 1, + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "import": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Quality Manager", + "share": 1, + "submit": 1, + "write": 1 + } + ], + "show_name_in_global_search": 1, + "sort_field": "modified", + "sort_order": "DESC", + "title_field": "asset_name" +} \ No newline at end of file diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 6e2bbc1626..94e6f6168e 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -30,7 +30,8 @@ class Asset(AccountsController): self.validate_in_use_date() self.set_status() self.update_stock_movement() - if not self.booked_fixed_asset and not is_cwip_accounting_disabled(): + if not self.booked_fixed_asset and is_cwip_accounting_enabled(self.company, + self.asset_category): self.make_gl_entries() def on_cancel(self): @@ -76,10 +77,13 @@ class Asset(AccountsController): self.set('finance_books', finance_books) def validate_asset_values(self): + if not self.asset_category: + self.asset_category = frappe.get_cached_value("Item", self.item_code, "asset_category") + if not flt(self.gross_purchase_amount): frappe.throw(_("Gross Purchase Amount is mandatory"), frappe.MandatoryError) - if not is_cwip_accounting_disabled(): + if is_cwip_accounting_enabled(self.company, self.asset_category): if not self.is_existing_asset and not (self.purchase_receipt or self.purchase_invoice): frappe.throw(_("Please create purchase receipt or purchase invoice for the item {0}"). format(self.item_code)) @@ -424,7 +428,7 @@ def update_maintenance_status(): asset.set_status('Out of Order') def make_post_gl_entry(): - if is_cwip_accounting_disabled(): + if not is_cwip_accounting_enabled(self.company, self.asset_category): return assets = frappe.db.sql_list(""" select name from `tabAsset` @@ -574,8 +578,13 @@ def make_journal_entry(asset_name): return je -def is_cwip_accounting_disabled(): - return cint(frappe.db.get_single_value("Asset Settings", "disable_cwip_accounting")) +def is_cwip_accounting_enabled(company, asset_category=None): + enable_cwip_in_company = cint(frappe.db.get_value("Company", company, "enable_cwip_accounting")) + + if enable_cwip_in_company or not asset_category: + return enable_cwip_in_company + + return cint(frappe.db.get_value("Asset Category", asset_category, "enable_cwip_accounting")) def get_pro_rata_amt(row, depreciation_amount, from_date, to_date): days = date_diff(to_date, from_date) @@ -587,4 +596,4 @@ def get_total_days(date, frequency): period_start_date = add_months(date, cint(frequency) * -1) - return date_diff(date, period_start_date) \ No newline at end of file + return date_diff(date, period_start_date) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index c09b94fa8e..7085b31e05 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -14,7 +14,6 @@ from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchas class TestAsset(unittest.TestCase): def setUp(self): set_depreciation_settings_in_company() - remove_prorated_depreciation_schedule() create_asset_data() frappe.db.sql("delete from `tabTax Rule`") @@ -70,11 +69,13 @@ class TestAsset(unittest.TestCase): {"voucher_type": "Purchase Invoice", "voucher_no": pi.name})) def test_is_fixed_asset_set(self): + asset = create_asset(is_existing_asset = 1) doc = frappe.new_doc('Purchase Invoice') doc.supplier = '_Test Supplier' doc.append('items', { 'item_code': 'Macbook Pro', - 'qty': 1 + 'qty': 1, + 'asset': asset.name }) doc.set_missing_values() @@ -200,7 +201,6 @@ class TestAsset(unittest.TestCase): self.assertEqual(schedules, expected_schedules) def test_schedule_for_prorated_straight_line_method(self): - set_prorated_depreciation_schedule() pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") @@ -233,8 +233,6 @@ class TestAsset(unittest.TestCase): self.assertEqual(schedules, expected_schedules) - remove_prorated_depreciation_schedule() - def test_depreciation(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") @@ -487,6 +485,8 @@ class TestAsset(unittest.TestCase): from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_purchase_invoice_from_pr) + #frappe.db.set_value("Asset Category","Computers","enable_cwip_accounting", 1) + pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=5000, do_not_submit=True, location="Test Location") @@ -565,6 +565,7 @@ class TestAsset(unittest.TestCase): where voucher_type='Asset' and voucher_no = %s order by account""", asset_doc.name) + self.assertEqual(gle, expected_gle) def test_expense_head(self): @@ -575,7 +576,6 @@ class TestAsset(unittest.TestCase): self.assertEquals('Asset Received But Not Billed - _TC', doc.items[0].expense_account) - def create_asset_data(): if not frappe.db.exists("Asset Category", "Computers"): create_asset_category() @@ -596,15 +596,15 @@ def create_asset(**args): asset = frappe.get_doc({ "doctype": "Asset", - "asset_name": "Macbook Pro 1", + "asset_name": args.asset_name or "Macbook Pro 1", "asset_category": "Computers", - "item_code": "Macbook Pro", - "company": "_Test Company", + "item_code": args.item_code or "Macbook Pro", + "company": args.company or"_Test Company", "purchase_date": "2015-01-01", "calculate_depreciation": 0, "gross_purchase_amount": 100000, "expected_value_after_useful_life": 10000, - "warehouse": "_Test Warehouse - _TC", + "warehouse": args.warehouse or "_Test Warehouse - _TC", "available_for_use_date": "2020-06-06", "location": "Test Location", "asset_owner": "Company", @@ -616,6 +616,9 @@ def create_asset(**args): except frappe.DuplicateEntryError: pass + if args.submit: + asset.submit() + return asset def create_asset_category(): @@ -623,6 +626,7 @@ def create_asset_category(): asset_category.asset_category_name = "Computers" asset_category.total_number_of_depreciations = 3 asset_category.frequency_of_depreciation = 3 + asset_category.enable_cwip_accounting = 1 asset_category.append("accounts", { "company_name": "_Test Company", "fixed_asset_account": "_Test Fixed Asset - _TC", @@ -656,19 +660,4 @@ def set_depreciation_settings_in_company(): company.save() # Enable booking asset depreciation entry automatically - frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1) - -def remove_prorated_depreciation_schedule(): - asset_settings = frappe.get_doc("Asset Settings", "Asset Settings") - asset_settings.schedule_based_on_fiscal_year = 0 - asset_settings.save() - - frappe.db.commit() - -def set_prorated_depreciation_schedule(): - asset_settings = frappe.get_doc("Asset Settings", "Asset Settings") - asset_settings.schedule_based_on_fiscal_year = 1 - asset_settings.number_of_days_in_fiscal_year = 360 - asset_settings.save() - - frappe.db.commit() + frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1) \ No newline at end of file diff --git a/erpnext/assets/doctype/asset_category/asset_category.json b/erpnext/assets/doctype/asset_category/asset_category.json index 882cbe2eaa..7483b41d4d 100644 --- a/erpnext/assets/doctype/asset_category/asset_category.json +++ b/erpnext/assets/doctype/asset_category/asset_category.json @@ -1,284 +1,115 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 1, - "allow_rename": 1, - "autoname": "field:asset_category_name", - "beta": 0, - "creation": "2016-03-01 17:41:39.778765", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "Document", - "editable_grid": 0, - "engine": "InnoDB", + "allow_import": 1, + "allow_rename": 1, + "autoname": "field:asset_category_name", + "creation": "2016-03-01 17:41:39.778765", + "doctype": "DocType", + "document_type": "Document", + "engine": "InnoDB", + "field_order": [ + "asset_category_name", + "column_break_3", + "depreciation_options", + "enable_cwip_accounting", + "finance_book_detail", + "finance_books", + "section_break_2", + "accounts" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "asset_category_name", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Asset Category Name", - "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": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "asset_category_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Asset Category Name", + "reqd": 1, + "unique": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_3", - "fieldtype": "Column Break", - "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, - "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, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "finance_book_detail", - "fieldtype": "Section Break", - "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": "Finance Book Detail", - "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, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "finance_book_detail", + "fieldtype": "Section Break", + "label": "Finance Book Detail" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "finance_books", - "fieldtype": "Table", - "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": "Finance Books", - "length": 0, - "no_copy": 0, - "options": "Asset Finance Book", - "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, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "finance_books", + "fieldtype": "Table", + "label": "Finance Books", + "options": "Asset Finance Book" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "section_break_2", - "fieldtype": "Section Break", - "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": "Accounts", - "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, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "section_break_2", + "fieldtype": "Section Break", + "label": "Accounts" + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "accounts", - "fieldtype": "Table", - "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": "Accounts", - "length": 0, - "no_copy": 0, - "options": "Asset Category Account", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 + "fieldname": "accounts", + "fieldtype": "Table", + "label": "Accounts", + "options": "Asset Category Account", + "reqd": 1 + }, + { + "fieldname": "depreciation_options", + "fieldtype": "Section Break", + "label": "Depreciation Options" + }, + { + "default": "0", + "fieldname": "enable_cwip_accounting", + "fieldtype": "Check", + "label": "Enable Capital Work in Progress Accounting" } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2018-05-12 14:56:04.116425", - "modified_by": "Administrator", - "module": "Assets", - "name": "Asset Category", - "name_case": "", - "owner": "Administrator", + ], + "modified": "2019-10-11 12:19:59.759136", + "modified_by": "Administrator", + "module": "Assets", + "name": "Asset Category", + "owner": "Administrator", "permissions": [ { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 1, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Accounts User", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "import": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1, "write": 1 - }, + }, { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 1, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Accounts Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "import": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "share": 1, "write": 1 - }, + }, { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Quality Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Quality Manager", + "share": 1, "write": 1 } - ], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 1, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 0, - "track_seen": 0 + ], + "show_name_in_global_search": 1, + "sort_field": "modified", + "sort_order": "DESC" } \ No newline at end of file diff --git a/erpnext/assets/doctype/asset_category/asset_category.py b/erpnext/assets/doctype/asset_category/asset_category.py index bbdc6ec2cf..5cb634abcd 100644 --- a/erpnext/assets/doctype/asset_category/asset_category.py +++ b/erpnext/assets/doctype/asset_category/asset_category.py @@ -10,11 +10,24 @@ from frappe.model.document import Document class AssetCategory(Document): def validate(self): + self.validate_finance_books() + self.validate_enable_cwip_accounting() + + def validate_finance_books(self): for d in self.finance_books: for field in ("Total Number of Depreciations", "Frequency of Depreciation"): if cint(d.get(frappe.scrub(field)))<1: frappe.throw(_("Row {0}: {1} must be greater than 0").format(d.idx, field), frappe.MandatoryError) + def validate_enable_cwip_accounting(self): + if self.enable_cwip_accounting : + for d in self.accounts: + cwip = frappe.db.get_value("Company",d.company_name,"enable_cwip_accounting") + if cwip: + frappe.throw(_ + ("CWIP is enabled globally in Company {1}. To enable it in Asset Category, first disable it in {1} ").format( + frappe.bold(d.idx), frappe.bold(d.company_name))) + @frappe.whitelist() def get_asset_category_account(asset, fieldname, account=None, asset_category = None, company = None): if not asset_category and company: diff --git a/erpnext/assets/doctype/asset_settings/__init__.py b/erpnext/assets/doctype/asset_settings/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/assets/doctype/asset_settings/asset_settings.js b/erpnext/assets/doctype/asset_settings/asset_settings.js deleted file mode 100644 index 3b421486c3..0000000000 --- a/erpnext/assets/doctype/asset_settings/asset_settings.js +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Asset Settings', { -}); diff --git a/erpnext/assets/doctype/asset_settings/asset_settings.json b/erpnext/assets/doctype/asset_settings/asset_settings.json deleted file mode 100644 index edc5ce169c..0000000000 --- a/erpnext/assets/doctype/asset_settings/asset_settings.json +++ /dev/null @@ -1,148 +0,0 @@ -{ - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2018-01-03 10:30:32.983381", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "depreciation_options", - "fieldtype": "Section Break", - "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": "Depreciation Options", - "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, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "disable_cwip_accounting", - "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": "Disable CWIP Accounting", - "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, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 1, - "istable": 0, - "max_attachments": 0, - "modified": "2019-05-26 18:31:19.930563", - "modified_by": "Administrator", - "module": "Assets", - "name": "Asset Settings", - "name_case": "", - "owner": "Administrator", - "permissions": [ - { - "amend": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 0, - "role": "System Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - }, - { - "amend": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 0, - "role": "Accounts Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 -} \ No newline at end of file diff --git a/erpnext/assets/doctype/asset_settings/asset_settings.py b/erpnext/assets/doctype/asset_settings/asset_settings.py deleted file mode 100644 index e303ebd23f..0000000000 --- a/erpnext/assets/doctype/asset_settings/asset_settings.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - -from __future__ import unicode_literals -from frappe.model.document import Document - -class AssetSettings(Document): - pass diff --git a/erpnext/assets/doctype/asset_settings/test_asset_settings.js b/erpnext/assets/doctype/asset_settings/test_asset_settings.js deleted file mode 100644 index eac2c928f3..0000000000 --- a/erpnext/assets/doctype/asset_settings/test_asset_settings.js +++ /dev/null @@ -1,23 +0,0 @@ -/* eslint-disable */ -// rename this file from _test_[name] to test_[name] to activate -// and remove above this line - -QUnit.test("test: Asset Settings", function (assert) { - let done = assert.async(); - - // number of asserts - assert.expect(1); - - frappe.run_serially([ - // insert a new Asset Settings - () => frappe.tests.make('Asset Settings', [ - // values to be set - {key: 'value'} - ]), - () => { - assert.equal(cur_frm.doc.key, 'value'); - }, - () => done() - ]); - -}); diff --git a/erpnext/assets/doctype/asset_settings/test_asset_settings.py b/erpnext/assets/doctype/asset_settings/test_asset_settings.py deleted file mode 100644 index 75f146a27e..0000000000 --- a/erpnext/assets/doctype/asset_settings/test_asset_settings.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt -from __future__ import unicode_literals - -import unittest - -class TestAssetSettings(unittest.TestCase): - pass diff --git a/erpnext/config/assets.py b/erpnext/config/assets.py index 3c9452f5a4..4cf7cf0806 100644 --- a/erpnext/config/assets.py +++ b/erpnext/config/assets.py @@ -21,10 +21,6 @@ def get_data(): "name": "Asset Category", "onboard": 1, }, - { - "type": "doctype", - "name": "Asset Settings", - }, { "type": "doctype", "name": "Asset Movement", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index aeb12f51b5..0155b27820 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -640,6 +640,7 @@ erpnext.patches.v12_0.create_default_energy_point_rules erpnext.patches.v12_0.set_produced_qty_field_in_sales_order_for_work_order erpnext.patches.v12_0.generate_leave_ledger_entries erpnext.patches.v12_0.set_default_shopify_app_type +erpnext.patches.v12_0.set_cwip_and_delete_asset_settings erpnext.patches.v12_0.set_expense_account_in_landed_cost_voucher_taxes erpnext.patches.v12_0.replace_accounting_with_accounts_in_home_settings erpnext.patches.v12_0.set_payment_entry_status diff --git a/erpnext/patches/v12_0/set_cwip_and_delete_asset_settings.py b/erpnext/patches/v12_0/set_cwip_and_delete_asset_settings.py new file mode 100644 index 0000000000..3d07fe57a5 --- /dev/null +++ b/erpnext/patches/v12_0/set_cwip_and_delete_asset_settings.py @@ -0,0 +1,22 @@ +from __future__ import unicode_literals +import frappe +from frappe.utils import cint + + +def execute(): + '''Get 'Disable CWIP Accounting value' from Asset Settings, set it in 'Enable Capital Work in Progress Accounting' field + in Company, delete Asset Settings ''' + + if frappe.db.exists("DocType","Asset Settings"): + frappe.reload_doctype("Company") + cwip_value = frappe.db.sql(""" SELECT value FROM `tabSingles` WHERE doctype='Asset Settings' + and field='disable_cwip_accounting' """, as_dict=1) + + companies = [x['name'] for x in frappe.get_all("Company", "name")] + for company in companies: + enable_cwip_accounting = cint(not cint(cwip_value[0]['value'])) + frappe.set_value("Company", company, "enable_cwip_accounting", enable_cwip_accounting) + + frappe.db.sql( + """ DELETE FROM `tabSingles` where doctype = 'Asset Settings' """) + frappe.delete_doc_if_exists("DocType","Asset Settings") \ No newline at end of file diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index bc3418997d..2d181b53ca 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -72,6 +72,7 @@ "stock_received_but_not_billed", "expenses_included_in_valuation", "fixed_asset_depreciation_settings", + "enable_cwip_accounting", "accumulated_depreciation_account", "depreciation_expense_account", "series_for_depreciation_entry", @@ -720,12 +721,18 @@ "fieldtype": "Link", "label": "Default Buying Terms", "options": "Terms and Conditions" + }, + { + "default": "0", + "fieldname": "enable_cwip_accounting", + "fieldtype": "Check", + "label": "Enable Capital Work in Progress Accounting" } ], "icon": "fa fa-building", "idx": 1, "image_field": "company_logo", - "modified": "2019-07-04 22:20:45.104307", + "modified": "2019-10-09 14:42:04.440974", "modified_by": "Administrator", "module": "Setup", "name": "Company", @@ -767,6 +774,18 @@ { "read": 1, "role": "Projects User" + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "share": 1, + "write": 1 } ], "show_name_in_global_search": 1, diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 3362d4b0f5..1bfdca50ea 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -14,7 +14,7 @@ from erpnext.accounts.utils import get_account_currency from frappe.desk.notifications import clear_doctype_notifications from frappe.model.mapper import get_mapped_doc from erpnext.buying.utils import check_on_hold_or_closed_status -from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accounting_disabled +from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accounting_enabled from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account from six import iteritems @@ -338,12 +338,13 @@ class PurchaseReceipt(BuyingController): def get_asset_gl_entry(self, gl_entries, expenses_included_in_valuation=None): arbnb_account, cwip_account = None, None - cwip_disabled = is_cwip_accounting_disabled() - if not expenses_included_in_valuation: expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") for d in self.get("items"): + asset_category = frappe.get_cached_value("Item", d.item_code, "asset_category") + cwip_enabled = is_cwip_accounting_enabled(self.company, asset_category) + if d.is_fixed_asset and not (arbnb_account and cwip_account): arbnb_account = self.get_company_default("asset_received_but_not_billed") @@ -351,8 +352,7 @@ class PurchaseReceipt(BuyingController): cwip_account = get_asset_account("capital_work_in_progress_account", d.asset, company = self.company) - if d.is_fixed_asset and not cwip_disabled: - + if d.is_fixed_asset and cwip_enabled: asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate) base_asset_amount = flt(d.base_net_amount + d.item_tax_amount) @@ -381,7 +381,7 @@ class PurchaseReceipt(BuyingController): if d.is_fixed_asset and flt(d.landed_cost_voucher_amount): asset_account = (get_asset_category_account(d.asset, 'fixed_asset_account', - company = self.company) if cwip_disabled else cwip_account) + company = self.company) if not cwip_enabled else cwip_account) gl_entries.append(self.get_gl_dict({ "account": expenses_included_in_valuation,