From e5982c0399e3dc90e08153682425aef1dfeb5148 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 3 May 2012 12:37:26 +0530 Subject: [PATCH 1/5] email digest fixes --- .../doctype/email_digest/email_digest.py | 151 ++++++++++-------- 1 file changed, 83 insertions(+), 68 deletions(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index b3ea118cc6..ae3d800e3f 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -502,126 +502,141 @@ class DocType: body_dict = { 'invoiced_amount': { - 'table': 'invoiced_amount' in result and table({ - 'head': 'Invoiced Amount', - 'body': currency_amount_str \ - % (currency, fmt_money(result['invoiced_amount']['debit'])) - }), + 'table': result.get('invoiced_amount') and \ + table({ + 'head': 'Invoiced Amount', + 'body': currency_amount_str \ + % (currency, fmt_money(result['invoiced_amount'].get('debit'))) + }), 'idx': 300 }, 'payables': { - 'table': 'payables' in result and table({ - 'head': 'Payables', - 'body': currency_amount_str \ - % (currency, fmt_money(result['payables']['credit'])) - }), + 'table': result.get('payables') and \ + table({ + 'head': 'Payables', + 'body': currency_amount_str \ + % (currency, fmt_money(result['payables'].get('credit'))) + }), 'idx': 200 }, 'collections': { - 'table': 'collections' in result and table({ - 'head': 'Collections', - 'body': currency_amount_str \ - % (currency, fmt_money(result['collections']['credit'])) - }), + 'table': result.get('collections') and \ + table({ + 'head': 'Collections', + 'body': currency_amount_str \ + % (currency, fmt_money(result['collections'].get('credit'))) + }), 'idx': 301 }, 'payments': { - 'table': 'payments' in result and table({ - 'head': 'Payments', - 'body': currency_amount_str \ - % (currency, fmt_money(result['payments']['debit'])) - }), + 'table': result.get('payments') and \ + table({ + 'head': 'Payments', + 'body': currency_amount_str \ + % (currency, fmt_money(result['payments'].get('debit'))) + }), 'idx': 201 }, 'income': { - 'table': 'income' in result and table({ - 'head': 'Income', - 'body': currency_amount_str \ - % (currency, fmt_money(result['income']['value'])) - }), + 'table': result.get('income') and \ + table({ + 'head': 'Income', + 'body': currency_amount_str \ + % (currency, fmt_money(result['income'].get('value'))) + }), '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'])) - }), + 'table': result.get('income_year_to_date') and \ + table({ + 'head': 'Income Year To Date', + 'body': currency_amount_str \ + % (currency, fmt_money(result['income_year_to_date'].get('value'))) + }), 'idx': 303 }, 'expenses_booked': { - 'table': 'expenses_booked' in result and table({ - 'head': 'Expenses Booked', - 'body': currency_amount_str \ - % (currency, fmt_money(result['expenses_booked']['value'])) - }), + 'table': result.get('expenses_booked') and \ + table({ + 'head': 'Expenses Booked', + 'body': currency_amount_str \ + % (currency, fmt_money(result['expenses_booked'].get('value'))) + }), 'idx': 202 }, 'bank_balance': { - 'table': 'bank_balance' in result and result['bank_balance'] and table({ - 'head': 'Bank Balance', - 'body': [ - [ - "%s" % bank['name'], - currency_amount_str % (currency, fmt_money(bank['value'])) - ] for bank in result.get('bank_balance', []) - ] - }), + 'table': result.get('bank_balance') and \ + table({ + 'head': 'Bank Balance', + 'body': [ + [ + "%s" \ + % bank['name'], + currency_amount_str % (currency, fmt_money(bank.get('value'))) + ] for bank in result['bank_balance'] + ] + }), 'idx': 400 }, 'new_leads': { - 'table': 'new_leads' in result and table({ - 'head': 'New Leads', - 'body': '%s' % result['new_leads']['count'] - }), + 'table': result.get('new_leads') and \ + table({ + 'head': 'New Leads', + 'body': '%s' % result['new_leads'].get('count') + }), 'idx': 100 }, 'new_enquiries': { - 'table': 'new_enquiries' in result and table({ - 'head': 'New Enquiries', - 'body': '%s' % result['new_enquiries']['count'] - }), + 'table': result.get('new_enquiries') and \ + table({ + 'head': 'New Enquiries', + 'body': '%s' % result['new_enquiries'].get('count') + }), 'idx': 101 }, 'new_quotations': { - 'table': 'new_quotations' in result and table({ - 'head': 'New Quotations', - 'body': '%s' % result['new_quotations']['count'] - }), + 'table': result.get('new_quotations') and \ + table({ + 'head': 'New Quotations', + 'body': '%s' % result['new_quotations'].get('count') + }), 'idx': 102 }, 'new_sales_orders': { - 'table': 'new_sales_orders' in result and table({ - 'head': 'New Sales Orders', - 'body': '%s' % result['new_sales_orders']['count'] - }), + 'table': result.get('new_sales_orders') and \ + table({ + 'head': 'New Sales Orders', + 'body': '%s' % result['new_sales_orders'].get('count') + }), 'idx': 103 }, 'new_purchase_orders': { - 'table': 'new_purchase_orders' in result and table({ - 'head': 'New Purchase Orders', - 'body': '%s' % result['new_purchase_orders']['count'] - }), + 'table': result.get('new_purchase_orders') and \ + table({ + 'head': 'New Purchase Orders', + 'body': '%s' % result['new_purchase_orders'].get('count') + }), 'idx': 104 }, 'new_transactions': { - 'table': 'new_transactions' in result and table({ - 'head': 'New Transactions', - 'body': '%s' % result['new_transactions']['count'] - }), + 'table': result.get('new_transactions') and \ + table({ + 'head': 'New Transactions', + 'body': '%s' % result['new_transactions'].get('count') + }), 'idx': 105 } From 996abdd155dd71de16af376be8ba24cfd82e42cb Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 3 May 2012 12:48:44 +0530 Subject: [PATCH 2/5] fix in email digest --- erpnext/setup/doctype/email_digest/email_digest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index ae3d800e3f..40472a27cb 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -142,7 +142,7 @@ class DocType: r['value'] = float(r['debit'] - r['credit']) #webnotes.msgprint(query) #webnotes.msgprint(res) - result[query] = (res and len(res)==1) and res[0] or (res and res or None) + result[query] = res and (len(res)==1 and res[0]) or (res or None) if result[query] is None: del result[query] From 57bc3f424fdc8d462187a74265044293405e29d2 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 3 May 2012 12:57:56 +0530 Subject: [PATCH 3/5] fix in email digest --- erpnext/setup/doctype/email_digest/email_digest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index 40472a27cb..351d6722b9 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -580,7 +580,9 @@ class DocType: "%s" \ % bank['name'], currency_amount_str % (currency, fmt_money(bank.get('value'))) - ] for bank in result['bank_balance'] + ] for bank in (isinstance(result['bank_balance'], list) and \ + result['bank_balance'] or \ + [result['bank_balance']]) ] }), 'idx': 400 From 32826a8cf1fafc8cabd025e9f4e3b974e0307379 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 3 May 2012 13:10:34 +0530 Subject: [PATCH 4/5] fixes in customerwise price list --- .../accounts/doctype/sales_invoice/sales_invoice.js | 3 ++- erpnext/selling/doctype/quotation/quotation.js | 3 ++- erpnext/selling/doctype/sales_common/sales_common.js | 10 +++++----- erpnext/selling/doctype/sales_order/sales_order.js | 6 ++++-- erpnext/stock/doctype/delivery_note/delivery_note.js | 3 ++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 15270defc9..8272fb2513 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -173,6 +173,7 @@ cur_frm.cscript.warehouse = function(doc, cdt , cdn) { //Customer cur_frm.cscript.customer = function(doc,dt,dn,onload) { + var pl = doc.price_list_name; var callback = function(r,rt) { var callback2 = function(doc, dt, dn) { doc = locals[dt][dn]; @@ -180,7 +181,7 @@ cur_frm.cscript.customer = function(doc,dt,dn,onload) { get_server_fields('get_cust_and_due_date','','',doc,dt,dn,1, function(doc, dt, dn) { cur_frm.refresh(); - if (!onload) cur_frm.cscript.price_list_name(doc, dt, dn); + if (!onload && (pl != doc.price_list_name)) cur_frm.cscript.price_list_name(doc, dt, dn); }); } diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 28008f5468..eb1cfe455d 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -100,10 +100,11 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { //customer cur_frm.cscript.customer = function(doc,dt,dn) { + var pl = doc.price_list_name; var callback = function(r,rt) { var doc = locals[cur_frm.doctype][cur_frm.docname]; cur_frm.refresh(); - cur_frm.cscript.price_list_name(doc, dt, dn); + if (pl != doc.price_list_name) cur_frm.cscript.price_list_name(doc, dt, dn); } if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), diff --git a/erpnext/selling/doctype/sales_common/sales_common.js b/erpnext/selling/doctype/sales_common/sales_common.js index bd32fa37b7..32c5d9e6a8 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.js +++ b/erpnext/selling/doctype/sales_common/sales_common.js @@ -143,23 +143,23 @@ cur_frm.cscript.hide_price_list_currency = function(doc, cdt, cdn, callback1) { unhide_field(['price_list_currency', 'plc_conversion_rate']); if (pl_currency.length==1) { - set_multiple(cdt, cdn, {price_list_currency:pl_currency[0]}); + if (doc.price_list_currency != pl_currency[0]) set_multiple(cdt, cdn, {price_list_currency:pl_currency[0]}); if (pl_currency[0] == doc.currency) { - set_multiple(cdt, cdn, {plc_conversion_rate:doc.conversion_rate}); + if(doc.plc_conversion_rate != doc.conversion_rate) set_multiple(cdt, cdn, {plc_conversion_rate:doc.conversion_rate}); hide_field(['price_list_currency', 'plc_conversion_rate']); } else if (pl_currency[0] == r.message[1]) { - set_multiple(cdt, cdn, {plc_conversion_rate:1}) + if (doc.plc_conversion_rate != 1) set_multiple(cdt, cdn, {plc_conversion_rate:1}) hide_field(['price_list_currency', 'plc_conversion_rate']); } } if (r.message[1] == doc.currency) { - set_multiple(cdt, cdn, {conversion_rate:1}); + if (doc.conversion_rate != 1) set_multiple(cdt, cdn, {conversion_rate:1}); hide_field(['conversion_rate', 'grand_total_export', 'in_words_export', 'rounded_total_export']); } else unhide_field(['conversion_rate', 'grand_total_export', 'in_words_export', 'rounded_total_export']); if (r.message[1] == doc.price_list_currency) { - set_multiple(cdt, cdn, {plc_conversion_rate:1}); + if (doc.plc_conversion_rate != 1) set_multiple(cdt, cdn, {plc_conversion_rate:1}); hide_field('plc_conversion_rate'); } else unhide_field('plc_conversion_rate'); diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 7f89748276..4faa6a38b1 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -98,18 +98,20 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { //customer cur_frm.cscript.customer = function(doc,dt,dn) { + var pl = doc.price_list_name; var callback = function(r,rt) { var callback2 = function(r, rt) { + if(doc.customer) unhide_field(['customer_address', 'contact_person', 'territory','customer_group','shipping_address']); cur_frm.refresh(); - if(!onload) cur_frm.cscript.price_list_name(doc, dt, dn); + + if(!onload && (pl != doc.price_list_name)) cur_frm.cscript.price_list_name(doc, dt, dn); } var doc = locals[cur_frm.doctype][cur_frm.docname]; get_server_fields('get_shipping_address',doc.customer,'',doc, dt, dn, 0, callback2); } - if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', '', callback); } diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index 982275174d..4be65ae1b9 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -79,11 +79,12 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { //customer cur_frm.cscript.customer = function(doc,dt,dn,onload) { + var pl = doc.price_list_name; var callback = function(r,rt) { var doc = locals[cur_frm.doctype][cur_frm.docname]; if(doc.customer) unhide_field(['customer_address','contact_person','territory','customer_group']); cur_frm.refresh(); - if(!onload) cur_frm.cscript.price_list_name(doc, dt, dn); + if(!onload && (pl != doc.price_list_name)) cur_frm.cscript.price_list_name(doc, dt, dn); } var args = onload ? 'onload':'' if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_shipping_address', args, callback); From 359852e3d9368bef452442be78028dd2cf0d661f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 3 May 2012 13:23:06 +0530 Subject: [PATCH 5/5] fix in email digest --- .../doctype/email_digest/email_digest.py | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index 351d6722b9..1a5e18f5b6 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -508,7 +508,8 @@ class DocType: 'body': currency_amount_str \ % (currency, fmt_money(result['invoiced_amount'].get('debit'))) }), - 'idx': 300 + 'idx': 300, + 'value': result.get('invoiced_amount') and result['invoiced_amount'].get('debit') }, 'payables': { @@ -518,7 +519,8 @@ class DocType: 'body': currency_amount_str \ % (currency, fmt_money(result['payables'].get('credit'))) }), - 'idx': 200 + 'idx': 200, + 'value': result.get('payables') and result['payables'].get('credit') }, 'collections': { @@ -528,7 +530,8 @@ class DocType: 'body': currency_amount_str \ % (currency, fmt_money(result['collections'].get('credit'))) }), - 'idx': 301 + 'idx': 301, + 'value': result.get('collections') and result['collections'].get('credit') }, 'payments': { @@ -538,7 +541,8 @@ class DocType: 'body': currency_amount_str \ % (currency, fmt_money(result['payments'].get('debit'))) }), - 'idx': 201 + 'idx': 201, + 'value': result.get('payments') and result['payments'].get('debit') }, 'income': { @@ -548,7 +552,8 @@ class DocType: 'body': currency_amount_str \ % (currency, fmt_money(result['income'].get('value'))) }), - 'idx': 302 + 'idx': 302, + 'value': result.get('income') and result['income'].get('value') }, 'income_year_to_date': { @@ -558,7 +563,9 @@ class DocType: 'body': currency_amount_str \ % (currency, fmt_money(result['income_year_to_date'].get('value'))) }), - 'idx': 303 + 'idx': 303, + 'value': result.get('income_year_to_date') and \ + result['income_year_to_date'].get('value') }, 'expenses_booked': { @@ -568,7 +575,8 @@ class DocType: 'body': currency_amount_str \ % (currency, fmt_money(result['expenses_booked'].get('value'))) }), - 'idx': 202 + 'idx': 202, + 'value': result.get('expenses_booked') and result['expenses_booked'].get('value') }, 'bank_balance': { @@ -585,7 +593,8 @@ class DocType: [result['bank_balance']]) ] }), - 'idx': 400 + 'idx': 0, + 'value': 0.1 }, 'new_leads': { @@ -594,7 +603,8 @@ class DocType: 'head': 'New Leads', 'body': '%s' % result['new_leads'].get('count') }), - 'idx': 100 + 'idx': 100, + 'value': result.get('new_leads') and result['new_leads'].get('count') }, 'new_enquiries': { @@ -603,7 +613,8 @@ class DocType: 'head': 'New Enquiries', 'body': '%s' % result['new_enquiries'].get('count') }), - 'idx': 101 + 'idx': 101, + 'value': result.get('new_enquiries') and result['new_enquiries'].get('count') }, 'new_quotations': { @@ -612,7 +623,8 @@ class DocType: 'head': 'New Quotations', 'body': '%s' % result['new_quotations'].get('count') }), - 'idx': 102 + 'idx': 102, + 'value': result.get('new_quotations') and result['new_quotations'].get('count') }, 'new_sales_orders': { @@ -621,7 +633,8 @@ class DocType: 'head': 'New Sales Orders', 'body': '%s' % result['new_sales_orders'].get('count') }), - 'idx': 103 + 'idx': 103, + 'value': result.get('new_sales_orders') and result['new_sales_orders'].get('count') }, 'new_purchase_orders': { @@ -630,7 +643,9 @@ class DocType: 'head': 'New Purchase Orders', 'body': '%s' % result['new_purchase_orders'].get('count') }), - 'idx': 104 + 'idx': 104, + 'value': result.get('new_purchase_orders') and \ + result['new_purchase_orders'].get('count') }, 'new_transactions': { @@ -639,7 +654,8 @@ class DocType: 'head': 'New Transactions', 'body': '%s' % result['new_transactions'].get('count') }), - 'idx': 105 + 'idx': 105, + 'value': result.get('new_transactions') and result['new_transactions'].get('count') } #'stock_below_rl': @@ -648,11 +664,20 @@ class DocType: table_list = [] # Sort these keys depending on idx value - bd_keys = sorted(body_dict, key=lambda x: body_dict[x]['idx']) + bd_keys = sorted(body_dict, key=lambda x: \ + (-webnotes.utils.flt(body_dict[x]['value']), body_dict[x]['idx'])) + + new_section = False for k in bd_keys: if self.doc.fields[k]: if k in result: + if not body_dict[k].get('value') and not new_section: + if len(table_list) % 2 != 0: + table_list.append("") + table_list.append("
") + table_list.append("
") + new_section = True table_list.append(body_dict[k]['table']) elif k in ['collections', 'payments']: table_list.append(\