diff --git a/erpnext/patches/edigest_enable_income_year_to_date.py b/erpnext/patches/edigest_enable_income_year_to_date.py new file mode 100644 index 0000000000..380de832b8 --- /dev/null +++ b/erpnext/patches/edigest_enable_income_year_to_date.py @@ -0,0 +1,11 @@ +import webnotes +from webnotes.model.doc import Document + +def execute(): + companies_list = webnotes.conn.sql("SELECT company_name FROM `tabCompany`", as_list=1) + for company in companies_list: + if company and company[0]: + edigest = Document('Email Digest', "Default Weekly Digest - " + company[0]) + if edigest: + edigest.income_year_to_date = 1 + edigest.save() diff --git a/erpnext/patches/remove_previous_field_property_setter.py b/erpnext/patches/remove_previous_field_property_setter.py new file mode 100644 index 0000000000..677188e624 --- /dev/null +++ b/erpnext/patches/remove_previous_field_property_setter.py @@ -0,0 +1,6 @@ +import webnotes +def execute(): + webnotes.conn.sql("""\ + DELETE FROM `tabProperty Setter` + WHERE property='previous_field' + """) diff --git a/erpnext/patches/update_0_idx.py b/erpnext/patches/update_0_idx.py new file mode 100644 index 0000000000..9c31f1d664 --- /dev/null +++ b/erpnext/patches/update_0_idx.py @@ -0,0 +1,9 @@ +import webnotes +def execute(): + doc_type_list = webnotes.conn.sql("""SELECT DISTINCT parent FROM `tabDocField` where idx=0""") + for doc_type in doc_type_list: + if doc_type and doc_type[0]: + webnotes.conn.sql("""\ + UPDATE `tabDocField` SET idx=idx+1 + WHERE parent=%s + """, doc_type[0]) diff --git a/erpnext/setup/doctype/email_digest/email_digest.js b/erpnext/setup/doctype/email_digest/email_digest.js index 728c8b4b7d..81b37e43da 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.js +++ b/erpnext/setup/doctype/email_digest/email_digest.js @@ -4,6 +4,7 @@ cur_frm.cscript.refresh = function(doc, dt, dn) { var err_msg = "There was an error. One probable reason could be that you haven't saved the form. Please contact support@erpnext.com if the problem persists." cur_frm.add_custom_button('View Now', function() { + doc = locals[dt][dn]; if(doc.__unsaved != 1) { $c_obj(make_doclist(dt, dn), 'get', '', function(r, rt) { if(r.exc) { @@ -26,6 +27,7 @@ cur_frm.cscript.refresh = function(doc, dt, dn) { } }, 1); cur_frm.add_custom_button('Send Now', function() { + doc = locals[dt][dn]; if(doc.__unsaved != 1) { $c_obj(make_doclist(dt, dn), 'send', '', function(r, rt) { if(r.exc) { diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index 5b760245e2..cd84d1098a 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -1,4 +1,5 @@ import webnotes +import webnotes.utils class DocType: def __init__(self, doc, doclist=[]): @@ -61,6 +62,11 @@ class DocType: 'debit_or_credit': 'Credit' }), + 'income_year_to_date': self.generate_gle_query({ + 'type': 'income_year_to_date', + 'debit_or_credit': 'Credit' + }), + 'expenses_booked': self.generate_gle_query({ 'type': 'expenses_booked', 'debit_or_credit': 'Debit' @@ -112,7 +118,7 @@ class DocType: if self.doc.fields[query] and query_dict[query]: #webnotes.msgprint(query) res = webnotes.conn.sql(query_dict[query], as_dict=1) - if query == 'income': + if query in ['income', 'income_year_to_date']: for r in res: r['value'] = float(r['credit'] - r['debit']) elif query in ['expenses_booked', 'bank_balance']: @@ -121,6 +127,8 @@ class DocType: #webnotes.msgprint(query) #webnotes.msgprint(res) result[query] = (res and len(res)==1) and res[0] or (res and res or None) + if result[query] is None: + del result[query] return result @@ -177,6 +185,21 @@ class DocType: %(start_date_condition)s AND %(end_date_condition)s""" % args + elif args['type'] == 'income_year_to_date': + query = """ + SELECT + IFNULL(SUM(IFNULL(gle.debit, 0)), 0) AS 'debit', + IFNULL(SUM(IFNULL(gle.credit, 0)), 0) AS 'credit', + %(common_select)s + FROM + %(common_from)s + WHERE + %(common_where)s AND + ac.is_pl_account = 'Yes' AND + ac.debit_or_credit = '%(debit_or_credit)s' AND + %(fiscal_start_date_condition)s AND + %(end_date_condition)s""" % args + elif args['type'] == 'bank_balance': query = """ SELECT @@ -201,6 +224,7 @@ class DocType: Adds common conditions in dictionary "args" """ start_date, end_date = self.get_start_end_dates() + fiscal_start_date = webnotes.utils.get_defaults()['year_start_date'] if 'new' in args['type']: args.update({ @@ -231,7 +255,9 @@ class DocType: 'start_date_condition': "gle.posting_date >= '%s'" % start_date, - 'end_date_condition': "gle.posting_date <= '%s'" % end_date + 'end_date_condition': "gle.posting_date <= '%s'" % end_date, + + 'fiscal_start_date_condition': "gle.posting_date >= '%s'" % fiscal_start_date }) @@ -576,6 +602,15 @@ class DocType: 'idx': 302 }, + 'income_year_to_date': { + 'table': 'income_year_to_date' in result and table({ + 'head': 'Income Year To Date', + 'body': currency_amount_str \ + % (currency, fmt_money(result['income_year_to_date']['value'])) + }), + 'idx': 303 + }, + 'expenses_booked': { 'table': 'expenses_booked' in result and table({ 'head': 'Expenses Booked', @@ -586,7 +621,7 @@ class DocType: }, 'bank_balance': { - 'table': 'bank_balance' in result and table({ + 'table': 'bank_balance' in result and result['bank_balance'] and table({ 'head': 'Bank Balance', 'body': [ [ @@ -662,8 +697,15 @@ class DocType: table_list.append(\ "