[get_query]to server side

This commit is contained in:
Saurabh
2013-07-09 16:18:52 +05:30
parent ebe50397d9
commit ab462d2000
52 changed files with 692 additions and 314 deletions

View File

@@ -15,7 +15,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.fields_dict['item'].get_query = function(doc, cdt, cdn) {
return erpnext.queries.item({
'ifnull(tabItem.is_stock_item, "No")': 'Yes'
})
return {
query:"controllers.queries.item_query",
filters:{
'is_stock_item': 'Yes'
}
}
}

View File

@@ -104,12 +104,12 @@ cur_frm.cscript.new_contact = function(){
// ***************** Get project name *****************
cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) {
var cond = '';
if(doc.customer) cond = '(`tabProject`.customer = "'+doc.customer+'" OR IFNULL(`tabProject`.customer,"")="") AND';
return repl('SELECT `tabProject`.name FROM `tabProject` \
WHERE `tabProject`.status not in ("Completed", "Cancelled") \
AND %(cond)s `tabProject`.name LIKE "%s" \
ORDER BY `tabProject`.name ASC LIMIT 50', {cond:cond});
return {
query: "controllers.queries.get_project_name",
filters: {
'customer': doc.customer
}
}
}
cur_frm.cscript.serial_no = function(doc, cdt, cdn) {
@@ -120,7 +120,9 @@ cur_frm.cscript.serial_no = function(doc, cdt, cdn) {
}
cur_frm.fields_dict['transporter_name'].get_query = function(doc) {
return 'SELECT DISTINCT `tabSupplier`.`name` FROM `tabSupplier` WHERE `tabSupplier`.supplier_type = "transporter" AND `tabSupplier`.docstatus != 2 AND `tabSupplier`.%(key)s LIKE "%s" ORDER BY `tabSupplier`.`name` LIMIT 50';
return{
filters: { 'supplier_type': "transporter" }
}
}
cur_frm.cscript['Make Packing Slip'] = function() {
@@ -133,7 +135,9 @@ cur_frm.cscript['Make Packing Slip'] = function() {
//get query select Territory
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
return{
filters: { 'is_group': "No" }
}
}
var set_print_hide= function(doc, cdt, cdn){
@@ -221,11 +225,11 @@ if (sys_defaults.auto_inventory_accounting) {
// expense account
cur_frm.fields_dict['delivery_note_details'].grid.get_field('expense_account').get_query = function(doc) {
return {
"query": "accounts.utils.get_account_list",
"filters": {
filters: {
"is_pl_account": "Yes",
"debit_or_credit": "Debit",
"company": doc.company
"company": doc.company,
"group_or_ledger": "Ledger"
}
}
}
@@ -244,8 +248,10 @@ if (sys_defaults.auto_inventory_accounting) {
cur_frm.fields_dict.delivery_note_details.grid.get_field("cost_center").get_query = function(doc) {
return {
query: "accounts.utils.get_cost_center_list",
filters: { company_name: doc.company}
filters: {
'company_name': doc.company,
'group_or_ledger': "Ledger"
}
}
}
}

View File

@@ -51,39 +51,65 @@ cur_frm.cscript.item_code = function(doc) {
cur_frm.fields_dict['default_bom'].get_query = function(doc) {
//var d = locals[this.doctype][this.docname];
return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '" AND ifnull(`tabBOM`.`is_active`, 0) = 0 and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50'
return{
filters:{
'item': doc.item_code,
'is_active': 0
}
}
// return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '" AND ifnull(`tabBOM`.`is_active`, 0) = 0 and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50'
}
// Expense Account
// ---------------------------------
cur_frm.fields_dict['purchase_account'].get_query = function(doc){
return 'SELECT DISTINCT `tabAccount`.`name` FROM `tabAccount` WHERE `tabAccount`.`debit_or_credit`="Debit" AND `tabAccount`.`group_or_ledger`="Ledger" AND `tabAccount`.`docstatus`!=2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50'
return{
filters:{
'debit_or_credit': "Debit",
'group_or_ledger': "Ledger"
}
}
}
// Income Account
// --------------------------------
cur_frm.fields_dict['default_income_account'].get_query = function(doc) {
return 'SELECT DISTINCT `tabAccount`.`name` FROM `tabAccount` WHERE `tabAccount`.`debit_or_credit`="Credit" AND `tabAccount`.`group_or_ledger`="Ledger" AND `tabAccount`.`docstatus`!=2 AND `tabAccount`.`account_type` ="Income Account" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.`name` LIMIT 50'
return{
filters:{
'debit_or_credit': "Credit",
'group_or_ledger': "Ledger",
'account_type': "Income Account"
}
}
}
// Purchase Cost Center
// -----------------------------
cur_frm.fields_dict['cost_center'].get_query = function(doc) {
return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.`docstatus`!= 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50'
return{
filters:{ 'group_or_ledger': "Ledger" }
}
}
// Sales Cost Center
// -----------------------------
cur_frm.fields_dict['default_sales_cost_center'].get_query = function(doc) {
return 'SELECT `tabCost Center`.`name` FROM `tabCost Center` WHERE `tabCost Center`.%(key)s LIKE "%s" AND `tabCost Center`.`group_or_ledger` = "Ledger" AND `tabCost Center`.`docstatus`!= 2 ORDER BY `tabCost Center`.`name` ASC LIMIT 50'
return{
filters:{ 'group_or_ledger': "Ledger" }
}
}
cur_frm.fields_dict['item_tax'].grid.get_field("tax_type").get_query = function(doc, cdt, cdn) {
return 'SELECT `tabAccount`.`name` FROM `tabAccount` WHERE `tabAccount`.`account_type` in ("Tax", "Chargeable") and `tabAccount`.`docstatus` != 2 and `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.`name` DESC LIMIT 50'
return{
filters:[
['Account', 'account_type', 'in', 'Tax, Chargeable'],
['Account', 'docstatus', '!=', 2]
]
}
}
cur_frm.cscript.tax_type = function(doc, cdt, cdn){
@@ -94,10 +120,11 @@ cur_frm.cscript.tax_type = function(doc, cdt, cdn){
//get query select item group
cur_frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` \
FROM `tabItem Group` WHERE `tabItem Group`.`docstatus`!= 2 AND \
`tabItem Group`.%(key)s LIKE "%s" ORDER BY `tabItem Group`.`name` \
ASC LIMIT 50'
return {
filters: [
['Item Group', 'docstatus', '!=', 2]
]
}
}
// for description from attachment
@@ -137,10 +164,12 @@ cur_frm.fields_dict['ref_rate_details'].grid.onrowadd = function(doc, cdt, cdn){
}
cur_frm.fields_dict.item_customer_details.grid.get_field("customer_name").get_query =
erpnext.utils.customer_query;
function(doc,cdt,cdn) {
return{ query:"controllers.queries.customer_query" } }
cur_frm.fields_dict.item_supplier_details.grid.get_field("supplier").get_query =
erpnext.utils.supplier_query;
function(doc,cdt,cdn) {
return{ query:"controllers.queries.supplier_query" } }
cur_frm.cscript.on_remove_attachment = function(doc) {
if(!inList(cur_frm.fields_dict.image.df.options.split("\n"), doc.image)) {

View File

@@ -20,5 +20,13 @@ if(!doc.currency){doc.currency = sys_defaults.currency;}
cur_frm.fields_dict['landed_cost_details'].grid.get_field("account_head").get_query = function(doc,cdt,cdn) {
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND (tabAccount.account_type = "Tax" OR tabAccount.account_type = "Chargeable" or (tabAccount.is_pl_account = "Yes" and tabAccount.debit_or_credit = "Debit")) AND tabAccount.name LIKE "%s"';
return{
filters:[
['Account', 'group_or_ledger', '=', 'Ledger'],
['Account', 'account_type', 'in', 'Tax, Chargeable'],
['Account', 'is_pl_account', '=', 'Yes'],
['Account', 'debit_or_credit', '=', 'Debit']
]
}
// return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND (tabAccount.account_type = "Tax" OR tabAccount.account_type = "Chargeable" or (tabAccount.is_pl_account = "Yes" and tabAccount.debit_or_credit = "Debit")) AND tabAccount.name LIKE "%s"';
}

View File

@@ -15,17 +15,19 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.fields_dict['delivery_note'].get_query = function(doc, cdt, cdn) {
return 'SELECT name FROM `tabDelivery Note` WHERE docstatus=0 AND %(key)s LIKE "%s"';
return{
filters:{ 'docstatus': 0}
}
// return 'SELECT name FROM `tabDelivery Note` WHERE docstatus=0 AND %(key)s LIKE "%s"';
}
cur_frm.fields_dict['item_details'].grid.get_field('item_code').get_query =
function(doc, cdt, cdn) {
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;
return {
query: "stock.doctype.packing_slip.packing_slip.item_details",
filters:{ 'delivery_note': doc.delivery_note}
}
}
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {

View File

@@ -171,4 +171,13 @@ class DocType:
ch.item_name = item.item_name
ch.stock_uom = item.stock_uom
ch.qty = flt(item.qty) - flt(item.packed_qty)
self.update_item_details()
self.update_item_details()
def item_details(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql("""select name, item_name, description from `tabItem`
where name in ( select item_code FROM `tabDelivery Note Item`
where parent= %s and ifnull(qty, 0) > ifnull(packed_qty, 0))
and %s like "%s" %s limit %s, %s """ % ("%s", searchfield, "%s",
get_match_cond(doctype, searchfield), "%s", "%s"),
(filters["delivery_note"], "%%%s%%" % txt, start, page_len))

View File

@@ -116,11 +116,15 @@ cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc
}
cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,address_line1,city FROM tabAddress WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
return{
filters:{ 'supplier': doc.supplier}
}
}
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
return{
filters:{ 'supplier': doc.supplier}
}
}
cur_frm.cscript.new_contact = function(){
@@ -131,15 +135,19 @@ cur_frm.cscript.new_contact = function(){
}
cur_frm.fields_dict['purchase_receipt_details'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) {
return 'SELECT `tabProject`.name FROM `tabProject` \
WHERE `tabProject`.status not in ("Completed", "Cancelled") \
AND `tabProject`.name LIKE "%s" ORDER BY `tabProject`.name ASC LIMIT 50';
return{
filters:[
['project', 'status', 'not in', 'Completed, Cancelled']
]
}
}
cur_frm.fields_dict['purchase_receipt_details'].grid.get_field('batch_no').get_query= function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.item_code){
return "SELECT tabBatch.name, tabBatch.description FROM tabBatch WHERE tabBatch.docstatus != 2 AND tabBatch.item = '"+ d.item_code +"' AND `tabBatch`.`name` like '%s' ORDER BY `tabBatch`.`name` DESC LIMIT 50"
return{
filters:{'item': d.item_code}
}
}
else{
alert("Please enter Item Code.");
@@ -156,11 +164,19 @@ cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
}
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
return{
filters:[
['Print Heading', 'docstatus', '!=', '2']
]
}
}
cur_frm.fields_dict.purchase_receipt_details.grid.get_field("qa_no").get_query = function(doc) {
return 'SELECT `tabQuality Inspection`.name FROM `tabQuality Inspection` WHERE `tabQuality Inspection`.docstatus = 1 AND `tabQuality Inspection`.%(key)s LIKE "%s"';
return {
filters: {
'docstatus': 1
}
}
}
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {

View File

@@ -46,7 +46,10 @@ cur_frm.add_fetch('customer', 'territory', 'territory')
// territory
// ----------
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
return{
filters:{'is_group': "No"}
}
// return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
}
// Supplier
@@ -59,11 +62,22 @@ cur_frm.cscript.supplier = function(doc,dt,dn) {
//item code
//----------
cur_frm.fields_dict['item_code'].get_query = function(doc,cdt,cdn) {
return erpnext.queries.item({
'ifnull(tabItem.has_serial_no, "No")': 'Yes'
});
return{
query:"controllers.queries.item_query",
filters:{
'has_serial_no': 'Yes'
}
}
}
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return{
query:"controllers.queries.customer_query"
}
}
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
cur_frm.fields_dict.supplier.get_query = function(doc,cdt,cdn) {
return{
query:"controllers.queries.supplier_query"
}
}

View File

@@ -56,7 +56,9 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
this.frm.fields_dict.delivery_note_no.get_query;
this.frm.fields_dict.purchase_receipt_no.get_query = function() {
return { query: "stock.doctype.stock_entry.stock_entry.query_purchase_return_doc" };
return {
filters:{ 'docstatus': 1 }
};
};
this.frm.fields_dict.mtn_details.grid.get_field('item_code').get_query = function() {
@@ -81,8 +83,10 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
this.frm.fields_dict["expense_adjustment_account"].get_query = function() {
return {
"query": "accounts.utils.get_account_list",
"filters": { "company": me.frm.doc.company }
filters: {
"company": me.frm.doc.company,
"group_or_ledger": "Ledger"
}
}
}
}
@@ -278,9 +282,12 @@ cur_frm.cscript.supplier = function(doc,cdt,cdn){
}
cur_frm.fields_dict['production_order'].get_query = function(doc) {
return 'select name from `tabProduction Order` \
where docstatus = 1 and qty > ifnull(produced_qty,0) AND %(key)s like "%s%%" \
order by name desc limit 50';
return{
filters:[
['Production Order', 'docstatus', '=', 1],
['Production Order', 'qty', '>','`tabProduction Order`.produced_qty']
]
}
}
cur_frm.cscript.purpose = function(doc, cdt, cdn) {
@@ -305,17 +312,21 @@ cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query = functi
var d = locals[cdt][cdn];
if(d.item_code) {
if (d.s_warehouse) {
return "select batch_no from `tabStock Ledger Entry` sle \
where item_code = '" + d.item_code + "' and warehouse = '" + d.s_warehouse +
"' and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%s' \
and exists(select * from `tabBatch` where \
name = sle.batch_no and expiry_date >= '" + doc.posting_date +
"' and docstatus != 2) group by batch_no having sum(actual_qty) > 0 \
order by batch_no desc limit 50";
return{
query: "stock.doctype.stock_entry.stock_entry.get_batch_no",
filters:{
'item_code': d.item_code,
's_warehouse': d.s_warehouse,
'posting_date': doc.posting_date
}
}
} else {
return "SELECT name FROM tabBatch WHERE docstatus != 2 AND item = '" +
d.item_code + "' and expiry_date >= '" + doc.posting_date +
"' AND name like '%s' ORDER BY name DESC LIMIT 50";
return{
filters:[
['Batch', 'item', '=', d.item_code],
['Batch', 'expiry_date', '>=', doc.posting_date]
]
}
}
} else {
msgprint("Please enter Item Code to get batch no");
@@ -372,6 +383,8 @@ cur_frm.cscript.validate_items = function(doc) {
}
}
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return{ query:"controllers.queries.customer_query" } }
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
cur_frm.fields_dict.supplier.get_query = function(doc,cdt,cdn) {
return{ query:"controllers.queries.supplier_query" } }

View File

@@ -25,6 +25,7 @@ from webnotes.model.code import get_obj
from webnotes import msgprint, _
from stock.utils import get_incoming_rate
from stock.stock_ledger import get_previous_sle
from controllers.queries import get_match_cond
import json
sql = webnotes.conn.sql
@@ -709,24 +710,29 @@ def get_production_order_details(production_order):
return result and result[0] or {}
def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
conditions = ""
if doctype == "Sales Invoice":
conditions = "and update_stock=1"
return webnotes.conn.sql("""select name, customer, customer_name
from `tab%s` where docstatus = 1
and (`%s` like %%(txt)s or `customer` like %%(txt)s) %s
and (`%s` like %%(txt)s or `customer` like %%(txt)s) %s %s
order by name, customer, customer_name
limit %s""" % (doctype, searchfield, conditions, "%(start)s, %(page_len)s"),
{"txt": "%%%s%%" % txt, "start": start, "page_len": page_len}, as_list=True)
limit %s""" % (doctype, searchfield, conditions,
get_match_cond(doctype, searchfield), "%(start)s, %(page_len)s"),
{"txt": "%%%s%%" % txt, "start": start, "page_len": page_len},
as_list=True)
def query_purchase_return_doc(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql("""select name, supplier, supplier_name
from `tab%s` where docstatus = 1
and (`%s` like %%(txt)s or `supplier` like %%(txt)s)
and (`%s` like %%(txt)s or `supplier` like %%(txt)s) %s
order by name, supplier, supplier_name
limit %s""" % (doctype, searchfield, "%(start)s, %(page_len)s"),
{"txt": "%%%s%%" % txt, "start": start, "page_len": page_len}, as_list=True)
limit %s""" % (doctype, searchfield, get_match_cond(doctype, searchfield),
"%(start)s, %(page_len)s"), {"txt": "%%%s%%" % txt, "start":
start, "page_len": page_len}, as_list=True)
def query_return_item(doctype, txt, searchfield, start, page_len, filters):
txt = txt.replace("%", "")
@@ -752,6 +758,20 @@ def query_return_item(doctype, txt, searchfield, start, page_len, filters):
return result[start:start+page_len]
def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle
where item_code = '%(item_code)s' and warehouse = '%(s_warehouse)s'
and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%(txt)s'
and exists(select * from `tabBatch` where name = sle.batch_no
and expiry_date >= %(posting_date)s and docstatus != 2) %(mcond)s
group by batch_no having sum(actual_qty) > 0
order by batch_no desc limit %(start)s, %(page_len)s """
% {'item_code': filters['item_code'], 's_warehouse': filters['s_warehouse'],
'posting_date': filters['posting_date'], 'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield),"start": start, "page_len": page_len})
def get_stock_items_for_return(ref_doclist, parentfields):
"""return item codes filtered from doclist, which are stock items"""
if isinstance(parentfields, basestring):

View File

@@ -46,9 +46,9 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
this.frm.fields_dict["expense_account"].get_query = function() {
return {
"query": "accounts.utils.get_account_list",
"filters": {
"company": me.frm.doc.company
'company': me.frm.doc.company,
'group_or_ledger': 'Ledger'
}
}
}

View File

@@ -15,7 +15,9 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.fields_dict['item_code'].get_query = function(doc) {
return erpnext.queries.item_std();
return {
query: "controllers.queries.item_std"
}
}
//==================== Get Items Stock UOM =====================================================