Fetch deatils from Item and Asset Category
diff --git a/erpnext/accounts/doctype/asset/asset.js b/erpnext/accounts/doctype/asset/asset.js
index e6d8b3b..2cd800a 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
}
};
});
@@ -113,6 +115,24 @@
});
},
+ 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);
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..366a02c 100644
--- a/erpnext/accounts/doctype/asset/asset.py
+++ b/erpnext/accounts/doctype/asset/asset.py
@@ -30,9 +30,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)
@@ -203,4 +210,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