Merge pull request #5666 from nabinhait/fixed_asset_revisited
Fixed asset revisited
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index cc86159..689c3e9 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -16,7 +16,7 @@
frozen_accounts_modifier = frappe.db.get_value("Accounts Settings", "Accounts Settings",
"frozen_accounts_modifier")
if not frozen_accounts_modifier or frozen_accounts_modifier in frappe.get_roles():
- self.get("__onload").can_freeze_account = True
+ self.set_onload("can_freeze_account", True)
def autoname(self):
# first validate if company exists
diff --git a/erpnext/accounts/doctype/account/account_tree.js b/erpnext/accounts/doctype/account/account_tree.js
index ca2d5f0..db15eef 100644
--- a/erpnext/accounts/doctype/account/account_tree.js
+++ b/erpnext/accounts/doctype/account/account_tree.js
@@ -27,9 +27,9 @@
{fieldtype:'Select', fieldname:'root_type', label:__('Root Type'),
options: ['Asset', 'Liability', 'Equity', 'Income', 'Expense'].join('\n')},
{fieldtype:'Select', fieldname:'account_type', label:__('Account Type'),
- options: ['', 'Bank', 'Cash', 'Stock', 'Tax', 'Chargeable'].join('\n'),
- description: __("Optional. This setting will be used to filter in various transactions."),
- depends_on: 'eval:doc.is_group==1'},
+ options: ['', 'Bank', 'Cash', 'Stock', 'Tax', 'Chargeable', 'Fixed Asset'].join('\n'),
+ description: __("Optional. This setting will be used to filter in various transactions.")
+ },
{fieldtype:'Float', fieldname:'tax_rate', label:__('Tax Rate'),
depends_on: 'eval:doc.is_group==1&&doc.account_type=="Tax"'},
{fieldtype:'Link', fieldname:'warehouse', label:__('Warehouse'), options:"Warehouse",
diff --git a/erpnext/accounts/doctype/asset/asset.js b/erpnext/accounts/doctype/asset/asset.js
index e6d8b3b..38be263 100644
--- a/erpnext/accounts/doctype/asset/asset.js
+++ b/erpnext/accounts/doctype/asset/asset.js
@@ -8,7 +8,9 @@
frm.set_query("item_code", function() {
return {
"filters": {
- "disabled": 0
+ "disabled": 0,
+ "is_fixed_asset": 1,
+ "is_stock_item": 0
}
};
});
@@ -25,7 +27,7 @@
refresh: function(frm) {
frappe.ui.form.trigger("Asset", "is_existing_asset");
frm.toggle_display("next_depreciation_date", frm.doc.docstatus < 1);
-
+
if (frm.doc.docstatus==1) {
if (frm.doc.status=='Submitted' && !frm.doc.is_existing_asset && !frm.doc.purchase_invoice) {
frm.add_custom_button("Make Purchase Invoice", function() {
@@ -103,7 +105,10 @@
},
axis: {
x: {
- type: 'category'
+ type: 'timeseries',
+ tick: {
+ format: "%d-%m-%Y"
+ }
},
y: {
min: 0,
@@ -113,12 +118,49 @@
});
},
+ item_code: function(frm) {
+ if(frm.doc.item_code) {
+ frappe.call({
+ method: "erpnext.accounts.doctype.asset.asset.get_item_details",
+ args: {
+ item_code: frm.doc.item_code
+ },
+ callback: function(r, rt) {
+ if(r.message) {
+ $.each(r.message, function(field, value) {
+ frm.set_value(field, value);
+ })
+ }
+ }
+ })
+ }
+ },
+
is_existing_asset: function(frm) {
frm.toggle_enable("supplier", frm.doc.is_existing_asset);
frm.toggle_reqd("next_depreciation_date", !frm.doc.is_existing_asset);
- }
+ },
});
+frappe.ui.form.on('Depreciation Schedule', {
+ make_depreciation_entry: function(frm, cdt, cdn) {
+ var row = locals[cdt][cdn];
+ if (!row.journal_entry) {
+ frappe.call({
+ method: "erpnext.accounts.doctype.asset.depreciation.make_depreciation_entry",
+ args: {
+ "asset_name": frm.doc.name,
+ "date": row.schedule_date
+ },
+ callback: function(r) {
+ frappe.model.sync(r.message);
+ frm.refresh();
+ }
+ })
+ }
+ }
+})
+
erpnext.asset.make_purchase_invoice = function(frm) {
frappe.call({
args: {
diff --git a/erpnext/accounts/doctype/asset/asset.json b/erpnext/accounts/doctype/asset/asset.json
index fa53aed..612574d 100644
--- a/erpnext/accounts/doctype/asset/asset.json
+++ b/erpnext/accounts/doctype/asset/asset.json
@@ -39,32 +39,6 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "fieldname": "asset_category",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_list_view": 0,
- "label": "Asset Category",
- "length": 0,
- "no_copy": 0,
- "options": "Asset Category",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
- {
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
"fieldname": "item_code",
"fieldtype": "Link",
"hidden": 0,
@@ -91,6 +65,32 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "fieldname": "asset_category",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "label": "Asset Category",
+ "length": 0,
+ "no_copy": 0,
+ "options": "Asset Category",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
"default": "Draft",
"fieldname": "status",
"fieldtype": "Select",
@@ -733,13 +733,14 @@
"hide_toolbar": 0,
"idx": 72,
"image_field": "image",
+ "image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2016-05-30 18:09:56.158782",
+ "modified": "2016-07-05 12:54:38.585259",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Asset",
diff --git a/erpnext/accounts/doctype/asset/asset.py b/erpnext/accounts/doctype/asset/asset.py
index 23bb08b..4d8a6b4 100644
--- a/erpnext/accounts/doctype/asset/asset.py
+++ b/erpnext/accounts/doctype/asset/asset.py
@@ -18,6 +18,7 @@
self.validate_asset_values()
self.set_depreciation_settings()
self.make_depreciation_schedule()
+ self.validate_expected_value_after_useful_life()
# Validate depreciation related accounts
get_depreciation_accounts(self)
@@ -30,9 +31,16 @@
self.set_status()
def validate_item(self):
- item = frappe.get_doc("Item", self.item_code)
- if item.disabled:
+ item = frappe.db.get_value("Item", self.item_code,
+ ["is_fixed_asset", "is_stock_item", "disabled"], as_dict=1)
+ if not item:
+ frappe.throw(_("Item {0} does not exist").format(self.item_code))
+ elif item.disabled:
frappe.throw(_("Item {0} has been disabled").format(self.item_code))
+ elif not item.is_fixed_asset:
+ frappe.throw(_("Item {0} must be a Fixed Asset Item").format(self.item_code))
+ elif item.is_stock_item:
+ frappe.throw(_("Item {0} must be a non-stock item").format(self.item_code))
def validate_asset_values(self):
self.value_after_depreciation = flt(self.gross_purchase_amount) - flt(self.opening_accumulated_depreciation)
@@ -117,6 +125,18 @@
depreciation_amount = flt(depreciable_value) - flt(self.expected_value_after_useful_life)
return depreciation_amount
+
+ def validate_expected_value_after_useful_life(self):
+ if self.depreciation_method == "Double Declining Balance":
+ accumulated_depreciation_after_full_schedule = \
+ max([d.accumulated_depreciation_amount for d in self.get("schedules")])
+
+ asset_value_after_full_schedule = (flt(self.gross_purchase_amount) -
+ flt(accumulated_depreciation_after_full_schedule))
+
+ if self.expected_value_after_useful_life < asset_value_after_full_schedule:
+ frappe.throw(_("Expected value after useful life must be greater than or equal to {0}")
+ .format(asset_value_after_full_schedule))
def validate_cancellation(self):
if self.status not in ("Submitted", "Partially Depreciated", "Fully Depreciated"):
@@ -203,4 +223,17 @@
frappe.db.commit()
- frappe.msgprint(_("Asset Movement record {0} created").format("<a href='#Form/Asset Movement/{0}'>{0}</a>".format(movement_entry.name)))
\ No newline at end of file
+ frappe.msgprint(_("Asset Movement record {0} created").format("<a href='#Form/Asset Movement/{0}'>{0}</a>".format(movement_entry.name)))
+
+@frappe.whitelist()
+def get_item_details(item_code):
+ asset_category = frappe.db.get_value("Item", item_code, "asset_category")
+
+ ret = frappe.db.get_value("Asset Category", asset_category,
+ ["depreciation_method", "total_number_of_depreciations", "frequency_of_depreciation"], as_dict=1)
+
+ ret.update({
+ "asset_category": asset_category
+ })
+
+ return ret
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/asset/depreciation.py b/erpnext/accounts/doctype/asset/depreciation.py
index d045ced..6cf09d3 100644
--- a/erpnext/accounts/doctype/asset/depreciation.py
+++ b/erpnext/accounts/doctype/asset/depreciation.py
@@ -21,7 +21,10 @@
and a.status in ('Submitted', 'Partially Depreciated')
and ifnull(ds.journal_entry, '')=''""", date)
+@frappe.whitelist()
def make_depreciation_entry(asset_name, date=None):
+ frappe.has_permission('Journal Entry', throw=True)
+
if not date:
date = today()
@@ -62,6 +65,8 @@
asset.db_set("value_after_depreciation", asset.value_after_depreciation)
asset.set_status()
+
+ return asset
def get_depreciation_accounts(asset):
fixed_asset_account = accumulated_depreciation_account = depreciation_expense_account = None
@@ -119,6 +124,8 @@
frappe.db.set_value("Asset", asset_name, "disposal_date", today())
frappe.db.set_value("Asset", asset_name, "journal_entry_for_scrap", je.name)
asset.set_status("Scrapped")
+
+ frappe.msgprint(_("Asset scrapped via Journal Entry {0}").format(je.name))
@frappe.whitelist()
def restore_asset(asset_name):
diff --git a/erpnext/accounts/doctype/asset/test_asset.py b/erpnext/accounts/doctype/asset/test_asset.py
index 2753e15..b409ec3 100644
--- a/erpnext/accounts/doctype/asset/test_asset.py
+++ b/erpnext/accounts/doctype/asset/test_asset.py
@@ -258,9 +258,11 @@
"item_code": "Macbook Pro",
"item_name": "Macbook Pro",
"description": "Macbook Pro Retina Display",
+ "asset_category": "Computers",
"item_group": "All Item Groups",
"stock_uom": "Nos",
- "is_stock_item": 0
+ "is_stock_item": 0,
+ "is_fixed_asset": 1
}).insert()
except frappe.DuplicateEntryError:
pass
diff --git a/erpnext/accounts/doctype/asset_category/asset_category.js b/erpnext/accounts/doctype/asset_category/asset_category.js
index 3130f6b..cbbdd48 100644
--- a/erpnext/accounts/doctype/asset_category/asset_category.js
+++ b/erpnext/accounts/doctype/asset_category/asset_category.js
@@ -2,9 +2,18 @@
// For license information, please see license.txt
frappe.ui.form.on('Asset Category', {
+ setup: function(frm) {
+ frm.get_field('accounts').grid.editable_fields = [
+ {fieldname: 'company_name', columns: 2},
+ {fieldname: 'fixed_asset_account', columns: 3},
+ {fieldname: 'accumulated_depreciation_account', columns: 3},
+ {fieldname: 'depreciation_expense_account', columns: 3}
+ ];
+ },
+
onload: function(frm) {
frm.add_fetch('company_name', 'accumulated_depreciation_account', 'accumulated_depreciation_account');
- frm.add_fetch('company_name', 'depreciation_expense_account', 'depreciation_expense_account');
+ frm.add_fetch('company_name', 'depreciation_expense_account', 'accumulated_depreciation_account');
frm.set_query('fixed_asset_account', 'accounts', function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
@@ -13,7 +22,7 @@
"account_type": "Fixed Asset",
"root_type": "Asset",
"is_group": 0,
- "company": d.company
+ "company": d.company_name
}
};
});
@@ -24,7 +33,7 @@
"filters": {
"root_type": "Asset",
"is_group": 0,
- "company": d.company
+ "company": d.company_name
}
};
});
@@ -35,7 +44,7 @@
"filters": {
"root_type": "Expense",
"is_group": 0,
- "company": d.company
+ "company": d.company_name
}
};
});
diff --git a/erpnext/accounts/doctype/depreciation_schedule/depreciation_schedule.json b/erpnext/accounts/doctype/depreciation_schedule/depreciation_schedule.json
index dc854b2..68ce53f 100644
--- a/erpnext/accounts/doctype/depreciation_schedule/depreciation_schedule.json
+++ b/erpnext/accounts/doctype/depreciation_schedule/depreciation_schedule.json
@@ -3,6 +3,7 @@
"allow_import": 0,
"allow_rename": 1,
"autoname": "",
+ "beta": 0,
"creation": "2016-03-02 15:11:01.278862",
"custom": 0,
"docstatus": 0,
@@ -135,18 +136,45 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
+ },
+ {
+ "allow_on_submit": 1,
+ "bold": 0,
+ "collapsible": 0,
+ "depends_on": "eval:(!doc.journal_entry && doc.schedule_date <= get_today())",
+ "fieldname": "make_depreciation_entry",
+ "fieldtype": "Button",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "label": "Make Depreciation Entry",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
}
],
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
+ "image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2016-04-20 16:43:21.407123",
+ "modified": "2016-07-06 12:38:32.456903",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Depreciation Schedule",
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index 8aae29e..444c3b5 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -165,7 +165,7 @@
var row = locals[cdt][cdn];
if(row.asset) {
frappe.call({
- method: erpnext.accounts.doctype.purchase_invoice.purchase_invoice.get_fixed_asset_account,
+ method: "erpnext.accounts.doctype.purchase_invoice.purchase_invoice.get_fixed_asset_account",
args: {
"asset": row.asset,
"account": row.expense_account
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 3bb402d..20d39a8 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -181,15 +181,16 @@
# expense account is always "Stock Received But Not Billed" for a stock item
# except epening entry, drop-ship entry and fixed asset items
- if auto_accounting_for_stock and item.item_code in stock_items and self.is_opening == 'No' \
- and (not item.po_detail or not item.is_fixed_asset
- or not frappe.db.get_value("Purchase Order Item", item.po_detail, "delivered_by_supplier")):
+ if auto_accounting_for_stock and item.item_code in stock_items \
+ and self.is_opening == 'No' and not item.is_fixed_asset \
+ and (not item.po_detail or
+ not frappe.db.get_value("Purchase Order Item", item.po_detail, "delivered_by_supplier")):
if self.update_stock:
item.expense_account = warehouse_account[item.warehouse]["name"]
else:
item.expense_account = stock_not_billed_account
-
+
elif not item.expense_account:
throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index 457bbd9..3372681 100755
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -3,6 +3,7 @@
"allow_import": 0,
"allow_rename": 0,
"autoname": "hash",
+ "beta": 0,
"creation": "2013-05-22 12:43:10",
"custom": 0,
"docstatus": 0,
@@ -1020,31 +1021,6 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "fieldname": "is_fixed_asset",
- "fieldtype": "Check",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_list_view": 0,
- "label": "Is Fixed Asset",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
- {
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
"fieldname": "expense_account",
"fieldtype": "Link",
"hidden": 0,
@@ -1361,6 +1337,31 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "fieldname": "is_fixed_asset",
+ "fieldtype": "Check",
+ "hidden": 1,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "label": "Is Fixed Asset",
+ "length": 0,
+ "no_copy": 1,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 1,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
"depends_on": "is_fixed_asset",
"fieldname": "asset",
"fieldtype": "Link",
@@ -1566,13 +1567,14 @@
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 1,
+ "image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2016-04-18 08:08:53.056819",
+ "modified": "2016-07-05 13:29:00.829144",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index 2b3232c..512abe3 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -979,31 +979,6 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "fieldname": "is_fixed_asset",
- "fieldtype": "Check",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_list_view": 0,
- "label": "Is Fixed Asset",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
- {
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
"fieldname": "income_account",
"fieldtype": "Link",
"hidden": 0,
@@ -1578,6 +1553,31 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "fieldname": "is_fixed_asset",
+ "fieldtype": "Check",
+ "hidden": 1,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "label": "Is Fixed Asset",
+ "length": 0,
+ "no_copy": 1,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 1,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
"fieldname": "asset",
"fieldtype": "Link",
"hidden": 0,
@@ -1659,7 +1659,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2016-06-24 16:01:59.719026",
+ "modified": "2016-07-05 13:28:51.981000",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index 5bb0061..d3d4bcc 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -40,8 +40,9 @@
// make sensitive fields(has_serial_no, is_stock_item, valuation_method)
// read only if any stock ledger entry exists
-
- erpnext.item.make_dashboard(frm);
+ if(!frm.doc.is_fixed_asset) {
+ erpnext.item.make_dashboard(frm);
+ }
// clear intro
frm.set_intro();
@@ -76,7 +77,8 @@
erpnext.item.toggle_attributes(frm);
-
+ frm.toggle_enable("is_fixed_asset", !frm.doc.is_stock_item &&
+ ((frm.doc.__onload && frm.doc.__onload.asset_exists) ? false : true));
},
validate: function(frm){
@@ -86,6 +88,16 @@
image: function(frm) {
refresh_field("image_view");
},
+
+ is_fixed_asset: function(frm) {
+ if (frm.doc.is_fixed_asset) {
+ frm.set_value("is_stock_item", 0);
+ }
+ },
+
+ is_stock_item: function(frm) {
+ frm.toggle_enable("is_fixed_asset", !frm.doc.is_stock_item);
+ },
page_name: frappe.utils.warn_page_name_change,
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index 680e7cc..2ab40c5 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -2307,7 +2307,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 1,
- "modified": "2016-07-06 16:00:45.561339",
+ "modified": "2016-07-06 17:00:45.561349",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item",
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index eee88bc..355503e 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -28,6 +28,9 @@
def onload(self):
super(Item, self).onload()
self.set_onload('sle_exists', self.check_if_sle_exists())
+ if self.is_fixed_asset:
+ asset = frappe.db.get_all("Asset", filters={"item_code": self.name, "docstatus": 1}, limit=1)
+ self.set_onload("asset_exists", True if asset else False)
def autoname(self):
if frappe.db.get_default("item_naming_by")=="Naming Series":
@@ -86,6 +89,7 @@
self.validate_variant_attributes()
self.validate_website_image()
self.make_thumbnail()
+ self.validate_fixed_asset()
if not self.get("__islocal"):
self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group")
@@ -220,6 +224,14 @@
file_doc.make_thumbnail()
self.thumbnail = file_doc.thumbnail_url
+
+ def validate_fixed_asset(self):
+ if self.is_fixed_asset:
+ if self.is_stock_item:
+ frappe.throw(_("Fixed Asset Item must be a non-stock item."))
+
+ if not self.asset_category:
+ frappe.throw(_("Asset Category is mandatory for Fixed Asset item"))
def get_context(self, context):
context.show_search=True
@@ -441,8 +453,8 @@
def cant_change(self):
if not self.get("__islocal"):
- vals = frappe.db.get_value("Item", self.name,
- ["has_serial_no", "is_stock_item", "valuation_method", "has_batch_no"], as_dict=True)
+ vals = frappe.db.get_value("Item", self.name, ["has_serial_no", "is_stock_item",
+ "valuation_method", "has_batch_no", "is_fixed_asset"], as_dict=True)
if vals and ((self.is_stock_item != vals.is_stock_item) or
vals.has_serial_no != self.has_serial_no or
@@ -451,6 +463,11 @@
if self.check_if_linked_document_exists():
frappe.throw(_("As there are existing transactions for this item, \
you can not change the values of 'Has Serial No', 'Has Batch No', 'Is Stock Item' and 'Valuation Method'"))
+
+ if vals and not self.is_fixed_asset and self.is_fixed_asset != vals.is_fixed_asset:
+ asset = frappe.db.get_all("Asset", filters={"item_code": self.name, "docstatus": 1}, limit=1)
+ if asset:
+ frappe.throw(_('"Is Fixed Asset" cannot be unchecked, as Asset record exists against the item'))
def check_if_linked_document_exists(self):
for doctype in ("Sales Order Item", "Delivery Note Item", "Sales Invoice Item",
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index f67026e..1e3bd8a 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -173,7 +173,8 @@
"net_amount": 0.0,
"discount_percentage": 0.0,
"supplier": item.default_supplier,
- "delivered_by_supplier": item.delivered_by_supplier
+ "delivered_by_supplier": item.delivered_by_supplier,
+ "is_fixed_asset": item.is_fixed_asset
})
# if default specified in item is for another company, fetch from company