2015-03-03 09:25:30 +00:00
|
|
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
2013-01-11 05:45:27 +00:00
|
|
|
|
2014-03-11 10:45:05 +00:00
|
|
|
// searches for enabled users
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.provide("erpnext.queries");
|
2013-07-18 07:56:27 +00:00
|
|
|
$.extend(erpnext.queries, {
|
2014-03-11 10:45:05 +00:00
|
|
|
user: function() {
|
|
|
|
return { query: "frappe.core.doctype.user.user.user_query" };
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
lead: function() {
|
2013-12-13 08:40:14 +00:00
|
|
|
return { query: "erpnext.controllers.queries.lead_query" };
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
customer: function() {
|
2013-12-13 08:40:14 +00:00
|
|
|
return { query: "erpnext.controllers.queries.customer_query" };
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
supplier: function() {
|
2013-12-13 08:40:14 +00:00
|
|
|
return { query: "erpnext.controllers.queries.supplier_query" };
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2014-04-16 09:51:46 +00:00
|
|
|
item: function(filters) {
|
|
|
|
var args = { query: "erpnext.controllers.queries.item_query" };
|
|
|
|
if(filters) args["filters"] = filters;
|
|
|
|
return args;
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
bom: function() {
|
2013-12-13 08:40:14 +00:00
|
|
|
return { query: "erpnext.controllers.queries.bom" };
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
task: function() {
|
2014-01-30 08:26:57 +00:00
|
|
|
return { query: "erpnext.projects.utils.query_task" };
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
customer_filter: function(doc) {
|
|
|
|
if(!doc.customer) {
|
2017-01-30 07:05:34 +00:00
|
|
|
frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "customer", doc.name))]));
|
2013-07-18 07:56:27 +00:00
|
|
|
}
|
2014-04-16 09:51:46 +00:00
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
return { filters: { customer: doc.customer } };
|
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
2017-01-13 13:23:11 +00:00
|
|
|
contact_query: function(doc) {
|
2017-01-16 07:36:07 +00:00
|
|
|
if(frappe.dynamic_link) {
|
|
|
|
if(!doc[frappe.dynamic_link.fieldname]) {
|
2017-01-30 07:05:34 +00:00
|
|
|
frappe.throw(__("Please set {0}",
|
|
|
|
[__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))]));
|
2017-01-13 13:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
query: 'frappe.email.doctype.contact.contact.contact_query',
|
2017-01-16 07:36:07 +00:00
|
|
|
filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } };
|
2017-01-13 13:23:11 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
address_query: function(doc) {
|
2017-01-16 07:36:07 +00:00
|
|
|
if(frappe.dynamic_link) {
|
|
|
|
if(!doc[frappe.dynamic_link.fieldname]) {
|
2017-01-30 07:05:34 +00:00
|
|
|
frappe.throw(__("Please set {0}",
|
|
|
|
[__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))]));
|
2017-01-13 13:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2017-01-16 07:36:07 +00:00
|
|
|
query: 'frappe.geo.doctype.address.address.address_query',
|
|
|
|
filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } };
|
2017-01-13 13:23:11 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-01-20 09:17:15 +00:00
|
|
|
company_address_query: function(doc) {
|
|
|
|
return {
|
|
|
|
query: 'frappe.geo.doctype.address.address.address_query',
|
|
|
|
filters: { is_your_company_address: 1, link_doctype: 'Company', link_name: doc.company || '' }
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2013-07-29 07:58:37 +00:00
|
|
|
supplier_filter: function(doc) {
|
|
|
|
if(!doc.supplier) {
|
2017-01-30 07:05:34 +00:00
|
|
|
frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "supplier", doc.name))]));
|
2013-07-29 07:58:37 +00:00
|
|
|
}
|
2014-04-16 09:51:46 +00:00
|
|
|
|
2013-07-29 07:58:37 +00:00
|
|
|
return { filters: { supplier: doc.supplier } };
|
|
|
|
},
|
2014-01-29 14:43:43 +00:00
|
|
|
|
|
|
|
lead_filter: function(doc) {
|
|
|
|
if(!doc.lead) {
|
2017-01-30 07:05:34 +00:00
|
|
|
frappe.throw(__("Please specify a {0}",
|
|
|
|
[__(frappe.meta.get_label(doc.doctype, "lead", doc.name))]));
|
2014-01-29 14:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return { filters: { lead: doc.lead } };
|
|
|
|
},
|
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
not_a_group_filter: function() {
|
2016-07-14 08:33:19 +00:00
|
|
|
return { filters: { is_group: 0 } };
|
2013-07-18 07:56:27 +00:00
|
|
|
},
|
2014-05-02 10:50:45 +00:00
|
|
|
|
|
|
|
employee: function() {
|
|
|
|
return { query: "erpnext.controllers.queries.employee_query" }
|
2014-06-24 13:23:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
warehouse: function(doc) {
|
|
|
|
return {
|
2016-06-20 11:55:45 +00:00
|
|
|
filters: [
|
|
|
|
["Warehouse", "company", "in", ["", cstr(doc.company)]],
|
2016-06-26 17:20:11 +00:00
|
|
|
["Warehouse", "is_group", "=",0]
|
2017-01-13 13:23:11 +00:00
|
|
|
|
2016-06-20 11:55:45 +00:00
|
|
|
]
|
2014-06-24 13:23:04 +00:00
|
|
|
}
|
2014-05-02 10:50:45 +00:00
|
|
|
}
|
2014-04-16 09:51:46 +00:00
|
|
|
});
|
2015-08-10 11:34:07 +00:00
|
|
|
|
|
|
|
erpnext.queries.setup_queries = function(frm, options, query_fn) {
|
|
|
|
var me = this;
|
|
|
|
var set_query = function(doctype, parentfield) {
|
|
|
|
var link_fields = frappe.meta.get_docfields(doctype, frm.doc.name,
|
|
|
|
{"fieldtype": "Link", "options": options});
|
|
|
|
$.each(link_fields, function(i, df) {
|
|
|
|
if(parentfield) {
|
|
|
|
frm.set_query(df.fieldname, parentfield, query_fn);
|
|
|
|
} else {
|
|
|
|
frm.set_query(df.fieldname, query_fn);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
set_query(frm.doc.doctype);
|
|
|
|
|
|
|
|
// warehouse field in tables
|
|
|
|
$.each(frappe.meta.get_docfields(frm.doc.doctype, frm.doc.name, {"fieldtype": "Table"}),
|
|
|
|
function(i, df) {
|
|
|
|
set_query(df.options, df.fieldname);
|
|
|
|
});
|
|
|
|
}
|
2017-01-12 12:19:37 +00:00
|
|
|
|
|
|
|
/* if item code is selected in child table
|
|
|
|
then list down warehouses with its quantity
|
|
|
|
else apply default filters.
|
|
|
|
*/
|
|
|
|
erpnext.queries.setup_warehouse_query = function(frm){
|
|
|
|
frm.set_query('warehouse', 'items', function(doc, cdt, cdn) {
|
|
|
|
var row = locals[cdt][cdn];
|
|
|
|
var filters = erpnext.queries.warehouse(frm.doc);
|
|
|
|
if(row.item_code){
|
|
|
|
$.extend(filters, {"query":"erpnext.controllers.queries.warehouse_query"});
|
|
|
|
filters["filters"].push(["Bin", "item_code", "=", row.item_code]);
|
|
|
|
}
|
|
|
|
return filters
|
|
|
|
});
|
|
|
|
}
|