2015-03-03 14:55:30 +05:30
|
|
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 14:59:54 +05:30
|
|
|
// License: GNU General Public License v3. See license.txt
|
2013-01-11 11:15:27 +05:30
|
|
|
|
2014-03-11 16:15:05 +05:30
|
|
|
// searches for enabled users
|
2014-02-14 15:47:51 +05:30
|
|
|
frappe.provide("erpnext.queries");
|
2013-07-18 13:26:27 +05:30
|
|
|
$.extend(erpnext.queries, {
|
2014-03-11 16:15:05 +05:30
|
|
|
user: function() {
|
|
|
|
return { query: "frappe.core.doctype.user.user.user_query" };
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
lead: function() {
|
2013-12-13 14:10:14 +05:30
|
|
|
return { query: "erpnext.controllers.queries.lead_query" };
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
customer: function() {
|
2013-12-13 14:10:14 +05:30
|
|
|
return { query: "erpnext.controllers.queries.customer_query" };
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
supplier: function() {
|
2013-12-13 14:10:14 +05:30
|
|
|
return { query: "erpnext.controllers.queries.supplier_query" };
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2014-04-16 15:21:46 +05:30
|
|
|
item: function(filters) {
|
|
|
|
var args = { query: "erpnext.controllers.queries.item_query" };
|
|
|
|
if(filters) args["filters"] = filters;
|
|
|
|
return args;
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
bom: function() {
|
2013-12-13 14:10:14 +05:30
|
|
|
return { query: "erpnext.controllers.queries.bom" };
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
task: function() {
|
2014-01-30 13:56:57 +05:30
|
|
|
return { query: "erpnext.projects.utils.query_task" };
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
customer_filter: function(doc) {
|
|
|
|
if(!doc.customer) {
|
2017-01-30 12:35:34 +05:30
|
|
|
frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "customer", doc.name))]));
|
2013-07-18 13:26:27 +05:30
|
|
|
}
|
2014-04-16 15:21:46 +05:30
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
return { filters: { customer: doc.customer } };
|
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
2017-01-13 18:53:11 +05:30
|
|
|
contact_query: function(doc) {
|
2017-01-16 13:06:07 +05:30
|
|
|
if(frappe.dynamic_link) {
|
|
|
|
if(!doc[frappe.dynamic_link.fieldname]) {
|
2017-01-30 12:35:34 +05:30
|
|
|
frappe.throw(__("Please set {0}",
|
|
|
|
[__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))]));
|
2017-01-13 18:53:11 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2017-06-13 15:26:35 +05:30
|
|
|
query: 'frappe.contacts.doctype.contact.contact.contact_query',
|
2017-06-22 16:37:04 +05:30
|
|
|
filters: {
|
|
|
|
link_doctype: frappe.dynamic_link.doctype,
|
|
|
|
link_name: doc[frappe.dynamic_link.fieldname]
|
|
|
|
}
|
|
|
|
};
|
2017-01-13 18:53:11 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
address_query: function(doc) {
|
2017-01-16 13:06:07 +05:30
|
|
|
if(frappe.dynamic_link) {
|
|
|
|
if(!doc[frappe.dynamic_link.fieldname]) {
|
2017-06-22 16:37:04 +05:30
|
|
|
frappe.throw(__("Please set {0}",
|
2017-01-30 12:35:34 +05:30
|
|
|
[__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))]));
|
2017-01-13 18:53:11 +05:30
|
|
|
}
|
2019-12-10 15:55:05 +05:30
|
|
|
|
2017-01-13 18:53:11 +05:30
|
|
|
return {
|
2017-06-13 15:26:35 +05:30
|
|
|
query: 'frappe.contacts.doctype.address.address.address_query',
|
2017-06-22 16:37:04 +05:30
|
|
|
filters: {
|
|
|
|
link_doctype: frappe.dynamic_link.doctype,
|
|
|
|
link_name: doc[frappe.dynamic_link.fieldname]
|
|
|
|
}
|
|
|
|
};
|
2017-01-13 18:53:11 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-01-20 14:47:15 +05:30
|
|
|
company_address_query: function(doc) {
|
|
|
|
return {
|
2017-06-13 15:26:35 +05:30
|
|
|
query: 'frappe.contacts.doctype.address.address.address_query',
|
2017-01-20 14:47:15 +05:30
|
|
|
filters: { is_your_company_address: 1, link_doctype: 'Company', link_name: doc.company || '' }
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2013-07-29 13:28:37 +05:30
|
|
|
supplier_filter: function(doc) {
|
|
|
|
if(!doc.supplier) {
|
2017-01-30 12:35:34 +05:30
|
|
|
frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "supplier", doc.name))]));
|
2013-07-29 13:28:37 +05:30
|
|
|
}
|
2014-04-16 15:21:46 +05:30
|
|
|
|
2013-07-29 13:28:37 +05:30
|
|
|
return { filters: { supplier: doc.supplier } };
|
|
|
|
},
|
2014-01-29 20:13:43 +05:30
|
|
|
|
|
|
|
lead_filter: function(doc) {
|
|
|
|
if(!doc.lead) {
|
2017-06-22 16:37:04 +05:30
|
|
|
frappe.throw(__("Please specify a {0}",
|
2017-01-30 12:35:34 +05:30
|
|
|
[__(frappe.meta.get_label(doc.doctype, "lead", doc.name))]));
|
2014-01-29 20:13:43 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return { filters: { lead: doc.lead } };
|
|
|
|
},
|
|
|
|
|
2013-07-18 13:26:27 +05:30
|
|
|
not_a_group_filter: function() {
|
2016-07-14 14:03:19 +05:30
|
|
|
return { filters: { is_group: 0 } };
|
2013-07-18 13:26:27 +05:30
|
|
|
},
|
2014-05-02 16:20:45 +05:30
|
|
|
|
|
|
|
employee: function() {
|
|
|
|
return { query: "erpnext.controllers.queries.employee_query" }
|
2014-06-24 18:53:04 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
warehouse: function(doc) {
|
|
|
|
return {
|
2016-06-20 17:25:45 +05:30
|
|
|
filters: [
|
|
|
|
["Warehouse", "company", "in", ["", cstr(doc.company)]],
|
2016-06-26 22:50:11 +05:30
|
|
|
["Warehouse", "is_group", "=",0]
|
2017-01-13 18:53:11 +05:30
|
|
|
|
2016-06-20 17:25:45 +05:30
|
|
|
]
|
2020-12-31 11:29:06 +05:30
|
|
|
};
|
2020-11-15 22:43:48 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
get_filtered_dimensions: function(doc, child_fields, dimension, company) {
|
|
|
|
let account = '';
|
|
|
|
|
|
|
|
child_fields.forEach((field) => {
|
|
|
|
if (!account) {
|
|
|
|
account = doc[field];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
query: "erpnext.controllers.queries.get_filtered_dimensions",
|
|
|
|
filters: {
|
|
|
|
'dimension': dimension,
|
|
|
|
'account': account,
|
|
|
|
'company': company
|
|
|
|
}
|
2020-11-16 12:03:47 +05:30
|
|
|
};
|
2014-05-02 16:20:45 +05:30
|
|
|
}
|
2014-04-16 15:21:46 +05:30
|
|
|
});
|
2015-08-10 17:04:07 +05:30
|
|
|
|
|
|
|
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 17:49:37 +05:30
|
|
|
|
|
|
|
/* 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
|
|
|
|
});
|
|
|
|
}
|