mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 08:54:45 +00:00
Queries to get new records in a particular doctype
This commit is contained in:
@@ -34,7 +34,7 @@ cur_frm.cscript['Add Recipients'] = function(doc, dt, dn) {
|
|||||||
add_or_update = 'Update';
|
add_or_update = 'Update';
|
||||||
}
|
}
|
||||||
var profile = $a($td(tab, i+1, 1), 'span', '', '', v.name);
|
var profile = $a($td(tab, i+1, 1), 'span', '', '', v.name);
|
||||||
profile.onclick = function() { check.checked = !check.checked; }
|
//profile.onclick = function() { check.checked = !check.checked; }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Display add recipients button
|
// Display add recipients button
|
||||||
|
|||||||
@@ -69,31 +69,52 @@ class DocType:
|
|||||||
'type': 'bank_balance'
|
'type': 'bank_balance'
|
||||||
}),
|
}),
|
||||||
|
|
||||||
'new_leads': """""",
|
'new_leads': self.generate_new_type_query({
|
||||||
|
'type': 'new_leads',
|
||||||
|
'doctype': 'Lead'
|
||||||
|
}),
|
||||||
|
|
||||||
'new_inquiries': """""",
|
'new_enquiries': self.generate_new_type_query({
|
||||||
|
'type': 'new_enquiries',
|
||||||
|
'doctype': 'Enquiry'
|
||||||
|
}),
|
||||||
|
|
||||||
'new_quotations': "",
|
'new_quotations': self.generate_new_type_query({
|
||||||
|
'type': 'new_quotations',
|
||||||
|
'doctype': 'Quotation',
|
||||||
|
'sum_col': 'grand_total'
|
||||||
|
}),
|
||||||
|
|
||||||
'new_orders': "",
|
'new_sales_orders': self.generate_new_type_query({
|
||||||
|
'type': 'new_sales_orders',
|
||||||
|
'doctype': 'Receivable Voucher',
|
||||||
|
'sum_col': 'grand_total'
|
||||||
|
}),
|
||||||
|
|
||||||
'stock_below_rl': """""",
|
'new_purchase_orders': self.generate_new_type_query({
|
||||||
|
'type': 'new_purchase_orders',
|
||||||
|
'doctype': 'Purchase Order',
|
||||||
|
'sum_col': 'grand_total'
|
||||||
|
}),
|
||||||
|
|
||||||
'new_transactions': """"""
|
'new_transactions': self.generate_new_type_query({
|
||||||
|
'type': 'new_transactions',
|
||||||
|
'doctype': 'Feed'
|
||||||
|
}),
|
||||||
|
|
||||||
|
'stock_below_rl': ""
|
||||||
}
|
}
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
for query in query_dict.keys():
|
for query in query_dict.keys():
|
||||||
if query_dict[query]:
|
if self.doc.fields[query]:
|
||||||
webnotes.msgprint(query)
|
webnotes.msgprint(query)
|
||||||
res = webnotes.conn.sql(query_dict[query], as_dict=1, debug=1)
|
res = webnotes.conn.sql(query_dict[query], as_dict=1, debug=1)
|
||||||
if query == 'income':
|
if query == 'income':
|
||||||
res[0]['value'] = float(res[0]['credit'] - res[0]['debit'])
|
for r in res:
|
||||||
elif query == 'expenses_booked':
|
r['value'] = float(r['credit'] - r['debit'])
|
||||||
res[0]['value'] = float(res[0]['debit'] - res[0]['credit'])
|
elif query in ['expenses_booked', 'bank_balance']:
|
||||||
elif query == 'bank_balance':
|
|
||||||
for r in res:
|
for r in res:
|
||||||
r['value'] = float(r['debit'] - r['credit'])
|
r['value'] = float(r['debit'] - r['credit'])
|
||||||
webnotes.msgprint(query)
|
webnotes.msgprint(query)
|
||||||
@@ -105,7 +126,7 @@ class DocType:
|
|||||||
|
|
||||||
def generate_gle_query(self, args):
|
def generate_gle_query(self, args):
|
||||||
"""
|
"""
|
||||||
Returns generated query string
|
Returns generated query string based 'tabGL Entry' and 'tabAccount'
|
||||||
"""
|
"""
|
||||||
self.process_args(args)
|
self.process_args(args)
|
||||||
|
|
||||||
@@ -114,7 +135,7 @@ class DocType:
|
|||||||
if args['type'] in ['invoiced_amount', 'payables']:
|
if args['type'] in ['invoiced_amount', 'payables']:
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
SUM(IFNULL(gle.%(field)s, 0)) AS '%(field)s',
|
IFNULL(SUM(IFNULL(gle.%(field)s, 0)), 0) AS '%(field)s',
|
||||||
%(common_select)s
|
%(common_select)s
|
||||||
FROM
|
FROM
|
||||||
%(common_from)s
|
%(common_from)s
|
||||||
@@ -128,7 +149,7 @@ class DocType:
|
|||||||
args['bc_accounts_regex'] = self.get_bc_accounts_regex()
|
args['bc_accounts_regex'] = self.get_bc_accounts_regex()
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
SUM(IFNULL(gle.%(field)s, 0)) AS '%(field)s',
|
IFNULL(SUM(IFNULL(gle.%(field)s, 0)), 0) AS '%(field)s',
|
||||||
%(common_select)s
|
%(common_select)s
|
||||||
FROM
|
FROM
|
||||||
%(common_from)s
|
%(common_from)s
|
||||||
@@ -142,8 +163,8 @@ class DocType:
|
|||||||
elif args['type'] in ['income', 'expenses_booked']:
|
elif args['type'] in ['income', 'expenses_booked']:
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
SUM(IFNULL(gle.debit, 0)) AS 'debit',
|
IFNULL(SUM(IFNULL(gle.debit, 0)), 0) AS 'debit',
|
||||||
SUM(IFNULL(gle.credit, 0)) AS 'credit',
|
IFNULL(SUM(IFNULL(gle.credit, 0)), 0) AS 'credit',
|
||||||
%(common_select)s
|
%(common_select)s
|
||||||
FROM
|
FROM
|
||||||
%(common_from)s
|
%(common_from)s
|
||||||
@@ -158,8 +179,8 @@ class DocType:
|
|||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
ac.name AS 'name',
|
ac.name AS 'name',
|
||||||
SUM(IFNULL(gle.debit, 0)) AS 'debit',
|
IFNULL(SUM(IFNULL(gle.debit, 0)), 0) AS 'debit',
|
||||||
SUM(IFNULL(gle.credit, 0)) AS 'credit',
|
IFNULL(SUM(IFNULL(gle.credit, 0)), 0) AS 'credit',
|
||||||
%(common_select)s
|
%(common_select)s
|
||||||
FROM
|
FROM
|
||||||
%(common_from)s
|
%(common_from)s
|
||||||
@@ -177,24 +198,69 @@ class DocType:
|
|||||||
"""
|
"""
|
||||||
Adds common conditions in dictionary "args"
|
Adds common conditions in dictionary "args"
|
||||||
"""
|
"""
|
||||||
|
start_date, end_date = self.get_start_end_dates()
|
||||||
|
|
||||||
|
if 'new' in args['type']:
|
||||||
|
args.update({
|
||||||
|
'company': self.doc.company,
|
||||||
|
'start_date': start_date,
|
||||||
|
'end_date': end_date,
|
||||||
|
'sum_if_reqd': ''
|
||||||
|
})
|
||||||
|
if args['type'] in ['new_quotations', 'new_sales_orders', 'new_purchase_orders']:
|
||||||
|
args['sum_if_reqd'] = "IFNULL(SUM(IFNULL(%(sum_col)s, 0)), 0) AS '%(sum_col)s'," % args
|
||||||
|
|
||||||
|
if args['type'] == 'new_transactions':
|
||||||
|
args['company_condition'] = ''
|
||||||
|
else:
|
||||||
|
args['company_condition'] = "company = '%(company)s' AND" % args
|
||||||
|
|
||||||
|
else:
|
||||||
|
args.update({
|
||||||
|
'common_select': "COUNT(*) AS 'count'",
|
||||||
|
|
||||||
|
'common_from': "`tabGL Entry` gle, `tabAccount` ac",
|
||||||
|
|
||||||
|
'common_where': """
|
||||||
|
gle.company = '%s' AND
|
||||||
|
gle.account = ac.name AND
|
||||||
|
ac.docstatus < 2 AND
|
||||||
|
IFNULL(gle.is_cancelled, 'No') = 'No'""" % self.doc.company,
|
||||||
|
|
||||||
|
'start_date_condition': "gle.posting_date >= '%s'" % start_date,
|
||||||
|
|
||||||
|
'end_date_condition': "gle.posting_date <= '%s'" % end_date
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def get_start_end_dates(self):
|
||||||
|
"""
|
||||||
|
Returns start and end date depending on the frequency of email digest
|
||||||
|
"""
|
||||||
start_date = '2011-11-01'
|
start_date = '2011-11-01'
|
||||||
end_date = '2011-11-30'
|
end_date = '2011-11-31'
|
||||||
|
return start_date, end_date
|
||||||
|
|
||||||
args.update({
|
|
||||||
'common_select': "COUNT(*) AS 'count'",
|
|
||||||
|
|
||||||
'common_from': "`tabGL Entry` gle, `tabAccount` ac",
|
def generate_new_type_query(self, args):
|
||||||
|
"""
|
||||||
|
Returns generated query string for calculating new transactions created
|
||||||
|
"""
|
||||||
|
self.process_args(args)
|
||||||
|
|
||||||
'common_where': """
|
query = """
|
||||||
gle.company = '%s' AND
|
SELECT
|
||||||
gle.account = ac.name AND
|
%(sum_if_reqd)s
|
||||||
ac.docstatus < 2 AND
|
COUNT(*) AS 'count'
|
||||||
IFNULL(gle.is_cancelled, 'No') = 'No'""" % self.doc.company,
|
FROM
|
||||||
|
`tab%(doctype)s`
|
||||||
|
WHERE
|
||||||
|
docstatus < 2 AND
|
||||||
|
%(company_condition)s
|
||||||
|
creation >= '%(start_date)s' AND
|
||||||
|
creation <= '%(end_date)s'""" % args
|
||||||
|
|
||||||
'start_date_condition': "gle.posting_date >= '%s'" % start_date,
|
return query
|
||||||
|
|
||||||
'end_date_condition': "gle.posting_date <= '%s'" % end_date
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
def get_bc_accounts_regex(self):
|
def get_bc_accounts_regex(self):
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
{
|
{
|
||||||
'creation': '2011-11-28 13:11:56',
|
'creation': '2011-11-28 13:11:56',
|
||||||
'docstatus': 0,
|
'docstatus': 0,
|
||||||
'modified': '2011-12-02 10:58:22',
|
'modified': '2011-12-02 18:55:47',
|
||||||
'modified_by': 'Administrator',
|
'modified_by': 'Administrator',
|
||||||
'owner': 'Administrator'
|
'owner': 'Administrator'
|
||||||
},
|
},
|
||||||
|
|
||||||
# These values are common for all DocType
|
# These values are common for all DocType
|
||||||
{
|
{
|
||||||
'_last_update': '1322803627',
|
'_last_update': '1322829965',
|
||||||
'autoname': 'Prompt',
|
'autoname': 'Prompt',
|
||||||
'colour': 'White:FFF',
|
'colour': 'White:FFF',
|
||||||
'doctype': 'DocType',
|
'doctype': 'DocType',
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
'name': '__common__',
|
'name': '__common__',
|
||||||
'section_style': 'Simple',
|
'section_style': 'Simple',
|
||||||
'show_in_menu': 0,
|
'show_in_menu': 0,
|
||||||
'version': 45
|
'version': 47
|
||||||
},
|
},
|
||||||
|
|
||||||
# These values are common for all DocField
|
# These values are common for all DocField
|
||||||
@@ -261,9 +261,9 @@
|
|||||||
{
|
{
|
||||||
'depends_on': 'eval:doc.use_standard',
|
'depends_on': 'eval:doc.use_standard',
|
||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'new_inquiries',
|
'fieldname': 'new_enquiries',
|
||||||
'fieldtype': 'Check',
|
'fieldtype': 'Check',
|
||||||
'label': 'New Inquiries',
|
'label': 'New Enquiries',
|
||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -277,13 +277,22 @@
|
|||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# DocField
|
||||||
|
{
|
||||||
|
'doctype': 'DocField',
|
||||||
|
'fieldname': 'new_sales_orders',
|
||||||
|
'fieldtype': 'Check',
|
||||||
|
'label': 'New Sales Orders',
|
||||||
|
'permlevel': 0
|
||||||
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
'depends_on': 'eval:doc.use_standard',
|
'depends_on': 'eval:doc.use_standard',
|
||||||
'doctype': 'DocField',
|
'doctype': 'DocField',
|
||||||
'fieldname': 'new_orders',
|
'fieldname': 'new_purchase_orders',
|
||||||
'fieldtype': 'Check',
|
'fieldtype': 'Check',
|
||||||
'label': 'New Orders',
|
'label': 'New Purchase Orders',
|
||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user