From 61a4a498cf9b27db9065ba0b1dcb40ec7b1d2c16 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 22 Dec 2011 18:02:36 +0530 Subject: [PATCH 1/7] Added feature: Income Year To Date in Email Digest --- .../doctype/email_digest/email_digest.js | 2 + .../doctype/email_digest/email_digest.py | 37 ++++++++++++++++++- .../doctype/email_digest/email_digest.txt | 27 ++++++++++++-- 3 files changed, 60 insertions(+), 6 deletions(-) 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 3498a7f55f..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']: @@ -179,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 @@ -203,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({ @@ -233,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 }) @@ -578,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', diff --git a/erpnext/setup/doctype/email_digest/email_digest.txt b/erpnext/setup/doctype/email_digest/email_digest.txt index 3d8de7b8f7..6d8a3dab67 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.txt +++ b/erpnext/setup/doctype/email_digest/email_digest.txt @@ -3,16 +3,16 @@ # These values are common in all dictionaries { - 'creation': '2011-12-12 10:41:40', + 'creation': '2011-12-14 12:15:09', 'docstatus': 0, - 'modified': '2011-12-15 13:53:08', + 'modified': '2011-12-22 17:55:57', 'modified_by': 'Administrator', 'owner': 'Administrator' }, # These values are common for all DocType { - '_last_update': '1323353260', + '_last_update': '1323937389', 'autoname': 'Prompt', 'colour': 'White:FFF', 'doctype': 'DocType', @@ -21,7 +21,7 @@ 'name': '__common__', 'section_style': 'Simple', 'show_in_menu': 0, - 'version': 79 + 'version': 80 }, # These values are common for all DocField @@ -134,6 +134,15 @@ 'search_index': 0 }, + # DocField + { + 'doctype': 'DocField', + 'fieldtype': 'Button', + 'label': 'Add Recipients', + 'permlevel': 0, + 'trigger': 'Client' + }, + # DocField { 'doctype': 'DocField', @@ -290,6 +299,16 @@ 'permlevel': 0 }, + # DocField + { + 'depends_on': 'eval:doc.use_standard', + 'doctype': 'DocField', + 'fieldname': 'income_year_to_date', + 'fieldtype': 'Check', + 'label': 'Income Year to Date', + 'permlevel': 0 + }, + # DocField { 'depends_on': 'eval:doc.use_standard', From 68f3967de0454c841222ade81907ad7ef85439ba Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 22 Dec 2011 18:18:10 +0530 Subject: [PATCH 2/7] Patch to enable income year to date summary in email digest --- erpnext/patches/edigest_enable_income_year_to_date.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 erpnext/patches/edigest_enable_income_year_to_date.py 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..16e8932ed3 --- /dev/null +++ b/erpnext/patches/edigest_enable_income_year_to_date.py @@ -0,0 +1,10 @@ +import webnotes + +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() From 0188df1609b9125a2a26f3a31018ccbe8eb19122 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 22 Dec 2011 18:21:57 +0530 Subject: [PATCH 3/7] Amended the patch to import class Document --- erpnext/patches/edigest_enable_income_year_to_date.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/patches/edigest_enable_income_year_to_date.py b/erpnext/patches/edigest_enable_income_year_to_date.py index 16e8932ed3..380de832b8 100644 --- a/erpnext/patches/edigest_enable_income_year_to_date.py +++ b/erpnext/patches/edigest_enable_income_year_to_date.py @@ -1,4 +1,5 @@ import webnotes +from webnotes.model.doc import Document def execute(): companies_list = webnotes.conn.sql("SELECT company_name FROM `tabCompany`", as_list=1) From f5d5f10ff30e613cf58539a03e53881866487638 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 22 Dec 2011 19:02:15 +0530 Subject: [PATCH 4/7] Remove "Add Recipients" button from Email Digest (again!) --- .../setup/doctype/email_digest/email_digest.txt | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.txt b/erpnext/setup/doctype/email_digest/email_digest.txt index 6d8a3dab67..897adadd2b 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.txt +++ b/erpnext/setup/doctype/email_digest/email_digest.txt @@ -5,14 +5,14 @@ { 'creation': '2011-12-14 12:15:09', 'docstatus': 0, - 'modified': '2011-12-22 17:55:57', + 'modified': '2011-12-22 19:01:33', 'modified_by': 'Administrator', 'owner': 'Administrator' }, # These values are common for all DocType { - '_last_update': '1323937389', + '_last_update': '1324556758', 'autoname': 'Prompt', 'colour': 'White:FFF', 'doctype': 'DocType', @@ -21,7 +21,7 @@ 'name': '__common__', 'section_style': 'Simple', 'show_in_menu': 0, - 'version': 80 + 'version': 81 }, # These values are common for all DocField @@ -134,15 +134,6 @@ 'search_index': 0 }, - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Button', - 'label': 'Add Recipients', - 'permlevel': 0, - 'trigger': 'Client' - }, - # DocField { 'doctype': 'DocField', From d0a892ffe7a8c87c2d4c785a176e955360cc9f1f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 22 Dec 2011 19:04:49 +0530 Subject: [PATCH 5/7] print hide price list flds --- .../receivable_voucher/receivable_voucher.txt | 34 ++++++++++++++-- erpnext/patches/print_hide_price_list.py | 3 ++ .../selling/doctype/quotation/quotation.txt | 39 ++++++++++++++++--- .../doctype/sales_order/sales_order.txt | 39 ++++++++++++++++--- .../doctype/delivery_note/delivery_note.txt | 28 +++++++++++-- 5 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 erpnext/patches/print_hide_price_list.py diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.txt b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.txt index 497c99febe..c194e7cc0c 100644 --- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.txt +++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.txt @@ -5,7 +5,7 @@ { 'creation': '2010-08-08 17:09:18', 'docstatus': 0, - 'modified': '2011-12-20 18:23:36', + 'modified': '2011-12-22 19:04:07', 'modified_by': 'Administrator', 'owner': 'Administrator' }, @@ -34,13 +34,12 @@ 'server_code_error': ' ', 'show_in_menu': 0, 'subject': 'To %(customer_name)s worth %(currency)s %(grand_total_export)s due on %(due_date)s | %(outstanding_amount)s outstanding', - 'version': 391 + 'version': 392 }, # These values are common for all DocFormat { 'doctype': 'DocFormat', - 'format': 'POS Invoice', 'name': '__common__', 'parent': 'Receivable Voucher', 'parentfield': 'formats', @@ -126,7 +125,32 @@ # DocFormat { - 'doctype': 'DocFormat' + 'doctype': 'DocFormat', + 'format': 'POS Invoice' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'POS Invoice' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Sales Invoice Classic' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Sales Invoice Modern' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Sales Invoice Spartan' }, # DocField @@ -477,6 +501,7 @@ 'label': 'Price List Currency', 'options': 'link:Currency', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, @@ -489,6 +514,7 @@ 'fieldtype': 'Currency', 'label': 'Price List Currency Conversion Rate', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, diff --git a/erpnext/patches/print_hide_price_list.py b/erpnext/patches/print_hide_price_list.py new file mode 100644 index 0000000000..833ab98808 --- /dev/null +++ b/erpnext/patches/print_hide_price_list.py @@ -0,0 +1,3 @@ +def execute(): + import webnotes + webnotes.conn.sql("update `tabDocField` set print_hide = 1 where fieldname in ('price_list_currency', 'plc_conversion_rate')") diff --git a/erpnext/selling/doctype/quotation/quotation.txt b/erpnext/selling/doctype/quotation/quotation.txt index 86b7b5f324..ac58dc4db9 100644 --- a/erpnext/selling/doctype/quotation/quotation.txt +++ b/erpnext/selling/doctype/quotation/quotation.txt @@ -5,11 +5,20 @@ { 'creation': '2010-08-08 17:09:17', 'docstatus': 0, - 'modified': '2011-12-20 14:01:09', + 'modified': '2011-12-22 19:03:04', 'modified_by': 'Administrator', 'owner': 'Administrator' }, + # These values are common for all DocField + { + 'doctype': 'DocField', + 'name': '__common__', + 'parent': 'Quotation', + 'parentfield': 'fields', + 'parenttype': 'DocType' + }, + # These values are common for all DocType { '_last_update': '1322549700', @@ -32,15 +41,15 @@ 'show_in_menu': 0, 'subject': 'To %(customer_name)s on %(transaction_date)s worth %(currency)s %(grand_total_export)s', 'tag_fields': 'status', - 'version': 597 + 'version': 598 }, - # These values are common for all DocField + # These values are common for all DocFormat { - 'doctype': 'DocField', + 'doctype': 'DocFormat', 'name': '__common__', 'parent': 'Quotation', - 'parentfield': 'fields', + 'parentfield': 'formats', 'parenttype': 'DocType' }, @@ -169,6 +178,24 @@ 'role': 'Maintenance User' }, + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Quotation Classic' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Quotation Modern' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Quotation Spartan' + }, + # DocField { 'colour': 'White:FFF', @@ -568,6 +595,7 @@ 'label': 'Price List Currency', 'options': 'link:Currency', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, @@ -580,6 +608,7 @@ 'fieldtype': 'Currency', 'label': 'Price List Currency Conversion Rate', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, diff --git a/erpnext/selling/doctype/sales_order/sales_order.txt b/erpnext/selling/doctype/sales_order/sales_order.txt index d59f236e5b..2e6ea99966 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.txt +++ b/erpnext/selling/doctype/sales_order/sales_order.txt @@ -5,11 +5,20 @@ { 'creation': '2010-08-08 17:09:21', 'docstatus': 0, - 'modified': '2011-12-20 12:55:02', + 'modified': '2011-12-22 19:03:25', 'modified_by': 'Administrator', 'owner': 'Administrator' }, + # These values are common for all DocField + { + 'doctype': 'DocField', + 'name': '__common__', + 'parent': 'Sales Order', + 'parentfield': 'fields', + 'parenttype': 'DocType' + }, + # These values are common for all DocType { '_last_update': '1324295218', @@ -29,15 +38,15 @@ 'show_in_menu': 0, 'subject': 'From %(customer_name)s on %(transaction_date)s worth %(currency)s %(grand_total_export)s | %(per_delivered)s% delivered | %(per_billed)s% billed', 'tag_fields': 'delivery_status,billing_status', - 'version': 608 + 'version': 609 }, - # These values are common for all DocField + # These values are common for all DocFormat { - 'doctype': 'DocField', + 'doctype': 'DocFormat', 'name': '__common__', 'parent': 'Sales Order', - 'parentfield': 'fields', + 'parentfield': 'formats', 'parenttype': 'DocType' }, @@ -166,6 +175,24 @@ 'role': 'Maintenance User' }, + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Sales Order Classic' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Sales Order Modern' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Sales Order Spartan' + }, + # DocField { 'colour': 'White:FFF', @@ -581,6 +608,7 @@ 'label': 'Price List Currency', 'options': 'link:Currency', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, @@ -593,6 +621,7 @@ 'fieldtype': 'Currency', 'label': 'Price List Currency Conversion Rate', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.txt b/erpnext/stock/doctype/delivery_note/delivery_note.txt index dc905f569d..5340955e67 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.txt +++ b/erpnext/stock/doctype/delivery_note/delivery_note.txt @@ -5,7 +5,7 @@ { 'creation': '2011-04-18 15:58:20', 'docstatus': 0, - 'modified': '2011-12-20 13:23:33', + 'modified': '2011-12-22 19:03:44', 'modified_by': 'Administrator', 'owner': 'Administrator' }, @@ -37,13 +37,12 @@ 'show_in_menu': 0, 'subject': 'To %(customer_name)s on %(transaction_date)s | %(per_billed)s% billed', 'tag_fields': 'billing_status', - 'version': 459 + 'version': 460 }, # These values are common for all DocFormat { 'doctype': 'DocFormat', - 'format': 'Delivery Note Packing List Wise', 'name': '__common__', 'parent': 'Delivery Note', 'parentfield': 'formats', @@ -143,7 +142,26 @@ # DocFormat { - 'doctype': 'DocFormat' + 'doctype': 'DocFormat', + 'format': 'Delivery Note Packing List Wise' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Delivery Note Classic' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Delivery Note Modern' + }, + + # DocFormat + { + 'doctype': 'DocFormat', + 'format': 'Delivery Note Spartan' }, # DocField @@ -567,6 +585,7 @@ 'label': 'Price List Currency', 'options': 'link:Currency', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, @@ -579,6 +598,7 @@ 'fieldtype': 'Currency', 'label': 'Price List Currency Conversion Rate', 'permlevel': 0, + 'print_hide': 1, 'reqd': 1 }, From e80496cef431f25c2455a3d721f6d070cdfd5bc5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 23 Dec 2011 11:25:37 +0530 Subject: [PATCH 6/7] Consider description also to check item duplication in purchase cycle --- .../buying/doctype/purchase_common/purchase_common.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py index 7612c190b7..84bfffb7ed 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.py +++ b/erpnext/buying/doctype/purchase_common/purchase_common.py @@ -248,7 +248,7 @@ class DocType(TransactionBase): raise Exception # list criteria that should not repeat if item is stock item - e = [d.schedule_date, d.item_code, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or ''] + e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or ''] # if is not stock item f = [d.schedule_date, d.item_code, d.description] @@ -258,16 +258,16 @@ class DocType(TransactionBase): if ch and ch[0][0] == 'Yes': # check for same items if e in check_list: - msgprint("Item %s has been entered more than once with same schedule date, warehouse and uom." % d.item_code) - raise Exception + msgprint("""Item %s has been entered more than once with same description, schedule date, warehouse and uom.\n + Please change any of the field value to enter the item twice""" % d.item_code, raise_exception = 1) else: check_list.append(e) elif ch and ch[0][0] == 'No': # check for same items if f in chk_dupl_itm: - msgprint("Item %s has been entered more than once." % d.item_code) - raise Exception + msgprint("""Item %s has been entered more than once with same description, schedule date.\n + Please change any of the field value to enter the item twice.""" % d.item_code, raise_exception = 1) else: chk_dupl_itm.append(f) From bd269cdbe760d92334bf99ddcb15907e2554f487 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 23 Dec 2011 11:55:00 +0530 Subject: [PATCH 7/7] Fix: Email digest gets deleted if even one is disabled. --- erpnext/setup/doctype/email_digest/email_digest.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index cd84d1098a..e599e7b058 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -417,7 +417,6 @@ class DocType: sch = Scheduler() sch.connect() - if self.doc.enabled == 1: # Create scheduler entry res = sch.conn.sql(""" @@ -429,15 +428,21 @@ class DocType: if not (res and res[0]): args['next_execution'] = self.get_next_execution() - + sch.conn.begin() sch.conn.sql(""" INSERT INTO Event (db_name, event, `interval`, next_execution, recurring) VALUES (%(db_name)s, %(event)s, 86400, %(next_execution)s, 1) """, args) + sch.conn.commit() else: - # delete scheduler entry - sch.clear(args['db_name'], args['event']) + # delete scheduler entry if no other email digest is enabled + res = webnotes.conn.sql(""" + SELECT * FROM `tabEmail Digest` + WHERE enabled=1 + """) + if not (res and res[0]): + sch.clear(args['db_name'], args['event']) #print "after on update"