commified item_code query

This commit is contained in:
Rushabh Mehta 2013-01-07 17:03:11 +05:30
parent 523aec499a
commit 143ea718c3
10 changed files with 78 additions and 52 deletions

View File

@ -193,7 +193,9 @@ cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
}
cur_frm.fields_dict['entries'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
return 'SELECT tabItem.name, tabItem.description FROM tabItem WHERE tabItem.is_purchase_item="Yes" AND (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` ="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50'
return return erpnext.queries.item({
'ifnull(tabItem.is_purchase_item, "No")': 'Yes'
})
}
cur_frm.fields_dict['credit_to'].get_query = function(doc) {

View File

@ -167,9 +167,13 @@ cur_frm.cscript.conversion_rate = function(doc,cdt,cdn) {
// Only Is Purchase Item = 'Yes' and Items not moved to trash are allowed.
cur_frm.fields_dict[fname].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
if (doc.is_subcontracted =="Yes") {
return 'SELECT tabItem.name, tabItem.description FROM tabItem WHERE ifnull(tabItem.is_sub_contracted_item, "No")="Yes" AND (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` ="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50'
return erpnext.queries.item({
'ifnull(tabItem.is_sub_contracted_item, "No")': 'Yes'
})
} else {
return 'SELECT tabItem.name, tabItem.description FROM tabItem WHERE ifnull(tabItem.is_purchase_item, "No")="Yes" AND (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` ="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50'
return erpnext.queries.item({
'ifnull(tabItem.is_purchase_item, "No")': 'Yes'
})
}
}

View File

@ -174,10 +174,9 @@ var calculate_total = function(doc) {
cur_frm.fields_dict['item'].get_query = function(doc) {
return 'SELECT DISTINCT `tabItem`.`name`, `tabItem`.description FROM `tabItem` \
WHERE is_manufactured_item = "Yes" and (IFNULL(`tabItem`.`end_of_life`,"") = "" OR \
`tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND \
`tabItem`.`%(key)s` like "%s" ORDER BY `tabItem`.`name` LIMIT 50';
return return erpnext.queries.item({
'ifnull(tabItem.is_manufactured_item, "No")': 'Yes'
})
}
cur_frm.fields_dict['project_name'].get_query = function(doc, dt, dn) {

View File

@ -45,12 +45,9 @@ cur_frm.cscript.download_materials_required = function(doc, cdt, cdn) {
}
cur_frm.fields_dict['pp_details'].grid.get_field('item_code').get_query = function(doc) {
return 'SELECT DISTINCT `tabItem`.`name`,`tabItem`.`item_name` \
FROM `tabItem` WHERE `tabItem`.is_pro_applicable = "Yes" \
AND (IFNULL(`tabItem`.`end_of_life`,"") = "" \
OR `tabItem`.`end_of_life`="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) \
AND tabItem.%(key)s like "%s" \
ORDER BY `tabItem`.`name` LIMIT 50';
return erpnext.queries.item({
'ifnull(tabItem.is_pro_applicable, "No")': 'Yes'
});
}
cur_frm.fields_dict['pp_details'].grid.get_field('bom_no').get_query = function(doc) {

View File

@ -114,16 +114,33 @@ erpnext.utils.supplier_query = function() {
wn.provide("erpnext.queries");
erpnext.queries.get_conditions = function(doctype, opts) {
conditions = [];
if (opts) {
$.each(opts, function(key, val) {
var lhs = "`tab" + doctype + "`.`" + key + "`";
if(key.indexOf(doctype)!=-1) {
// with function
lhs = key;
}
if (esc_quotes(val).charAt(0) != "!")
conditions.push(lhs + "='"+esc_quotes(val)+"'");
else
conditions.push(lhs + "!='"+esc_quotes(val).substr(1)+"'");
});
}
return conditions;
}
erpnext.queries.account = function(opts) {
if(!opts)
opts = {};
if(!opts.group_or_ledger)
opts.group_or_ledger = "Ledger";
conditions = [];
$.each(opts, function(key, val) {
conditions.push("tabAccount.`" + key + "`='"+esc_quotes(val)+"'");
});
var conditions = erpnext.queries.get_conditions("Account", opts);
return 'SELECT tabAccount.name, tabAccount.parent_account, tabAccount.debit_or_credit \
FROM tabAccount \
@ -131,18 +148,29 @@ erpnext.queries.account = function(opts) {
AND tabAccount.%(key)s LIKE "%s" ' + (conditions
? (" AND " + conditions.join(" AND "))
: "")
+ " LIMIT 50"
}
erpnext.queries.item = function(opts) {
var conditions = erpnext.queries.get_conditions("Item", opts);
return 'SELECT tabItem.name, \
if(length(tabItem.item_name) > 40, \
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name, \
if(length(tabItem.description) > 40, \
concat(substr(tabItem.description, 1, 40), "..."), description) as decription \
FROM tabItem \
WHERE tabItem.docstatus!=2 \
AND (ifnull(`tabItem`.`end_of_life`,"") in ("", "0000-00-00") \
OR `tabItem`.`end_of_life` > NOW()) \
AND tabItem.%(key)s LIKE "%s" ' + (conditions
? (" AND " + conditions.join(" AND "))
: "")
+ " LIMIT 50"
}
erpnext.queries.bom = function(opts) {
conditions = [];
if (opts) {
$.each(opts, function(key, val) {
if (esc_quotes(val).charAt(0) != "!")
conditions.push("tabBOM.`" + key + "`='"+esc_quotes(val)+"'");
else
conditions.push("tabBOM.`" + key + "`!='"+esc_quotes(val).substr(1)+"'");
});
}
var conditions = erpnext.queries.get_conditions("BOM", opts);
return 'SELECT tabBOM.name, tabBOM.item \
FROM tabBOM \
@ -151,4 +179,6 @@ erpnext.queries.bom = function(opts) {
AND tabBOM.%(key)s LIKE "%s" ' + (conditions.length
? (" AND " + conditions.join(" AND "))
: "")
+ " LIMIT 50"
}

View File

@ -149,9 +149,13 @@ cur_frm.cscript.lead = function(doc, cdt, cdn) {
//=======================================
cur_frm.fields_dict['enquiry_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
if (doc.enquiry_type == 'Maintenance')
return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem WHERE tabItem.is_service_item="Yes" AND (ifnull(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` > NOW() OR `tabItem`.`end_of_life`="0000-00-00") AND tabItem.%(key)s LIKE "%s" LIMIT 50';
return erpnext.queries.item({
'ifnull(tabItem.is_service_item, "No")': 'Yes'
});
else
return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem WHERE tabItem.is_sales_item="Yes" AND (ifnull(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` > NOW() OR `tabItem`.`end_of_life`="0000-00-00") AND tabItem.%(key)s LIKE "%s" LIMIT 50';
return erpnext.queries.item({
'ifnull(tabItem.is_sales_item, "No")': 'Yes'
});
}
// Create New Quotation

View File

@ -249,21 +249,15 @@ cur_frm.cscript.price_list_name = function(doc, cdt, cdn) {
// ******************** ITEM CODE ********************************
cur_frm.fields_dict[cur_frm.cscript.fname].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
if (inList(['Maintenance', 'Service'], doc.order_type))
return 'SELECT tabItem.name,tabItem.item_name,tabItem.description \
FROM tabItem WHERE tabItem.is_service_item="Yes" \
AND tabItem.docstatus != 2 \
AND (ifnull(`tabItem`.`end_of_life`,"") = "" \
OR `tabItem`.`end_of_life` > NOW() \
OR `tabItem`.`end_of_life`="0000-00-00") \
AND tabItem.%(key)s LIKE "%s" LIMIT 50';
else
return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem \
WHERE tabItem.is_sales_item="Yes" AND tabItem.docstatus != 2 \
AND (ifnull(`tabItem`.`end_of_life`,"") = "" \
OR `tabItem`.`end_of_life` > NOW() \
OR `tabItem`.`end_of_life`="0000-00-00") \
AND tabItem.%(key)s LIKE "%s" LIMIT 50';
if (inList(['Maintenance', 'Service'], doc.order_type)) {
return erpnext.queries.item({
'ifnull(tabItem.is_service_item, "No")': 'Yes'
});
} else {
return erpnext.queries.item({
'ifnull(tabItem.is_sales_item, "No")': 'Yes'
});
}
}

View File

@ -20,7 +20,7 @@ cur_frm.fields_dict['delivery_note'].get_query = function(doc, cdt, cdn) {
cur_frm.fields_dict['item_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
var query = 'SELECT name, description FROM `tabItem` WHERE name IN ( \
var query = 'SELECT name, item_name, description FROM `tabItem` WHERE name IN ( \
SELECT item_code FROM `tabDelivery Note Item` dnd \
WHERE parent="' + doc.delivery_note + '" AND IFNULL(qty, 0) > IFNULL(packed_qty, 0)) AND %(key)s LIKE "%s" LIMIT 50';
return query;

View File

@ -14,14 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// ************************************** onload ****************************************************
cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(!doc.status) set_multiple(cdt, cdn, {status:'In Store'});
if(doc.__islocal) hide_field(['supplier_name','address_display'])
}
// ************************************** refresh ***************************************************
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
if(!doc.__islocal) {
flds = ['item_code', 'warehouse', 'purchase_document_type', 'purchase_document_no', 'purchase_date', 'purchase_time', 'purchase_rate', 'supplier']
@ -31,7 +29,6 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}
// ************************************** triggers **************************************************
// item details
// -------------
@ -63,10 +60,9 @@ cur_frm.cscript.supplier = function(doc,dt,dn) {
//item code
//----------
cur_frm.fields_dict['item_code'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabItem`.`name`,`tabItem`.`description` FROM `tabItem` \
WHERE `tabItem`.`docstatus`!= 2 AND ifnull(`tabItem`.`has_serial_no`, "No") = "Yes" \
AND (ifnull(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` > NOW() OR `tabItem`.`end_of_life`="0000-00-00") \
AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` ASC LIMIT 50';
return erpnext.queries.item({
'ifnull(tabItem.has_serial_no, "No")': 'Yes'
});
}
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;

View File

@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.fields_dict['item_code'].get_query = function(doc) {
return 'SELECT DISTINCT `tabItem`.`name`, `tabItem`.description FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` ="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.`%(key)s` like "%s" ORDER BY `tabItem`.`name` LIMIT 50';
return erpnext.queries.item();
}
//==================== Get Items Stock UOM =====================================================