Fixed asset item property and validations

This commit is contained in:
Nabin Hait 2016-07-05 13:13:53 +05:30
parent 2dec0db3bd
commit abd6c5debb
2 changed files with 25 additions and 5 deletions

View File

@ -40,8 +40,9 @@ frappe.ui.form.on("Item", {
// 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 @@ frappe.ui.form.on("Item", {
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 @@ frappe.ui.form.on("Item", {
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,

View File

@ -28,6 +28,9 @@ class Item(WebsiteGenerator):
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":
@ -450,8 +453,8 @@ class Item(WebsiteGenerator):
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
@ -460,6 +463,11 @@ class Item(WebsiteGenerator):
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",