From d56d57d20551537910e482e518ba38e063570dfd Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 2 Jan 2012 16:25:05 +0530 Subject: [PATCH] Patch system changes, Inclusive Price feature and session cache clear on disabling user or on new login --- .../doctype/rv_tax_detail/rv_tax_detail.txt | 37 +-- erpnext/home/page/my_company/my_company.py | 5 + erpnext/patches/patch_list.py | 11 + .../doctype/sales_common/sales_common.js | 241 +++++++++++++++--- .../doctype/other_charges/other_charges.js | 2 +- erpnext/startup/event_handlers.py | 10 +- 6 files changed, 248 insertions(+), 58 deletions(-) create mode 100644 erpnext/patches/patch_list.py diff --git a/erpnext/accounts/doctype/rv_tax_detail/rv_tax_detail.txt b/erpnext/accounts/doctype/rv_tax_detail/rv_tax_detail.txt index a9326a0286..784c3b7591 100644 --- a/erpnext/accounts/doctype/rv_tax_detail/rv_tax_detail.txt +++ b/erpnext/accounts/doctype/rv_tax_detail/rv_tax_detail.txt @@ -5,8 +5,8 @@ { 'creation': '2010-08-08 17:09:20', 'docstatus': 0, - 'modified': '2010-09-20 14:06:57', - 'modified_by': 'nabin@webnotestech.com', + 'modified': '2011-12-28 17:33:30', + 'modified_by': 'Administrator', 'owner': 'Administrator' }, @@ -14,6 +14,7 @@ { 'autoname': 'INVTD.######', 'colour': 'White:FFF', + 'default_print_format': 'Standard', 'doctype': 'DocType', 'hide_heading': 1, 'istable': 1, @@ -22,7 +23,7 @@ 'section_style': 'Tray', 'server_code_error': ' ', 'show_in_menu': 0, - 'version': 15 + 'version': 18 }, # These values are common for all DocField @@ -45,7 +46,6 @@ 'doctype': 'DocField', 'fieldname': 'charge_type', 'fieldtype': 'Select', - 'idx': 1, 'label': 'Type', 'oldfieldname': 'charge_type', 'oldfieldtype': 'Select', @@ -60,7 +60,6 @@ 'doctype': 'DocField', 'fieldname': 'account_head', 'fieldtype': 'Link', - 'idx': 2, 'label': 'Account Head', 'oldfieldname': 'account_head', 'oldfieldtype': 'Link', @@ -75,13 +74,11 @@ 'doctype': 'DocField', 'fieldname': 'cost_center_other_charges', 'fieldtype': 'Link', - 'idx': 3, 'label': 'Cost Center', 'oldfieldname': 'cost_center_other_charges', 'oldfieldtype': 'Link', 'options': 'Cost Center', - 'permlevel': 0, - 'search_index': 0 + 'permlevel': 0 }, # DocField @@ -89,7 +86,6 @@ 'doctype': 'DocField', 'fieldname': 'description', 'fieldtype': 'Small Text', - 'idx': 4, 'label': 'Description', 'oldfieldname': 'description', 'oldfieldtype': 'Small Text', @@ -103,7 +99,6 @@ 'doctype': 'DocField', 'fieldname': 'rate', 'fieldtype': 'Currency', - 'idx': 5, 'label': 'Rate', 'oldfieldname': 'rate', 'oldfieldtype': 'Currency', @@ -117,7 +112,6 @@ 'doctype': 'DocField', 'fieldname': 'tax_amount', 'fieldtype': 'Currency', - 'idx': 6, 'label': 'Amount*', 'oldfieldname': 'tax_amount', 'oldfieldtype': 'Currency', @@ -131,7 +125,6 @@ 'doctype': 'DocField', 'fieldname': 'total', 'fieldtype': 'Currency', - 'idx': 7, 'label': 'Total*', 'oldfieldname': 'total', 'oldfieldtype': 'Currency', @@ -144,7 +137,6 @@ 'fieldname': 'row_id', 'fieldtype': 'Data', 'hidden': 0, - 'idx': 8, 'label': 'Enter Row', 'oldfieldname': 'row_id', 'oldfieldtype': 'Data', @@ -157,7 +149,6 @@ 'doctype': 'DocField', 'fieldname': 'item_wise_tax_detail', 'fieldtype': 'Small Text', - 'idx': 9, 'label': 'Item Wise Tax Detail ', 'oldfieldname': 'item_wise_tax_detail', 'oldfieldtype': 'Small Text', @@ -170,7 +161,6 @@ 'fieldname': 'parenttype', 'fieldtype': 'Data', 'hidden': 1, - 'idx': 10, 'in_filter': 1, 'label': 'Parenttype', 'oldfieldname': 'parenttype', @@ -188,7 +178,6 @@ 'fieldname': 'total_tax_amount', 'fieldtype': 'Currency', 'hidden': 1, - 'idx': 11, 'label': 'Total Tax Amount', 'no_copy': 1, 'oldfieldname': 'total_tax_amount', @@ -205,7 +194,6 @@ 'fieldname': 'total_amount', 'fieldtype': 'Currency', 'hidden': 1, - 'idx': 12, 'label': 'Total Amount', 'no_copy': 1, 'oldfieldname': 'total_amount', @@ -213,5 +201,20 @@ 'permlevel': 0, 'print_hide': 1, 'report_hide': 1 + }, + + # DocField + { + 'allow_on_submit': 0, + 'description': 'If checked, the tax amount will be considered as already included in the Print Rate / Print Amount', + 'doctype': 'DocField', + 'fieldname': 'included_in_print_rate', + 'fieldtype': 'Check', + 'label': 'Included in Print Rate', + 'no_column': 0, + 'no_copy': 1, + 'permlevel': 0, + 'print_hide': 1, + 'report_hide': 1 } ] \ No newline at end of file diff --git a/erpnext/home/page/my_company/my_company.py b/erpnext/home/page/my_company/my_company.py index ad0089dc14..4931ea9a6f 100644 --- a/erpnext/home/page/my_company/my_company.py +++ b/erpnext/home/page/my_company/my_company.py @@ -34,6 +34,11 @@ def disable_profile(arg=''): return 'Cannot disable Administrator' webnotes.conn.sql("update tabProfile set enabled=0 where name=%s", arg) + sid_list = webnotes.conn.sql("SELECT sid FROM `tabSessions` WHERE user=%s", arg) + from webnotes.auth import LoginManager + login_manager = LoginManager() + for sid in sid_list: + login_manager.logout(sid=sid) return 0 # diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py new file mode 100644 index 0000000000..80f1cc1df0 --- /dev/null +++ b/erpnext/patches/patch_list.py @@ -0,0 +1,11 @@ +patch_list = [ + { + 'patch_file': 'reload_print_format', + 'description': 'Reload doctype print format' + }, + { + 'patch_module': 'patches', + 'patch_file': 'reload_project_task', + 'description': 'Reload doctype task of project module' + } +] diff --git a/erpnext/selling/doctype/sales_common/sales_common.js b/erpnext/selling/doctype/sales_common/sales_common.js index 23e04202f2..0cc886872b 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.js +++ b/erpnext/selling/doctype/sales_common/sales_common.js @@ -130,26 +130,47 @@ cur_frm.cscript.adj_rate = function(doc, cdt, cdn) { cur_frm.cscript.recalc(doc, // ************************ REF RATE **************************** cur_frm.cscript.ref_rate = function(doc, cdt, cdn){ - var d = locals[cdt][cdn]; - set_multiple(cur_frm.cscript.tname, d.name, {'export_rate': flt(d.ref_rate) * (100 - flt(d.adj_rate)) / 100}, cur_frm.cscript.fname); - cur_frm.cscript.recalc(doc, 3); + var d = locals[cdt][cdn]; + var consider_incl_rate = cur_frm.cscript.consider_incl_rate(doc, cur_frm.cscript.other_fname); + if(!consider_incl_rate) { + set_multiple(cur_frm.cscript.tname, d.name, {'export_rate': flt(d.ref_rate) * (100 - flt(d.adj_rate)) / 100}, cur_frm.cscript.fname); + } + cur_frm.cscript.recalc(doc, 1); } // *********************** BASIC RATE ************************** cur_frm.cscript.basic_rate = function(doc, cdt, cdn) { - var fname = cur_frm.cscript.fname; - var d = locals[cdt][cdn];; - if(!d.qty) - { - d.qty = 1; - refresh_field('qty', d.name, fname); - - } - cur_frm.cscript.recalc(doc, 2); + var fname = cur_frm.cscript.fname; + var d = locals[cdt][cdn]; + if(!d.qty) { + d.qty = 1; + refresh_field('qty', d.name, fname); + } + var consider_incl_rate = cur_frm.cscript.consider_incl_rate(doc, cur_frm.cscript.other_fname); + if(!consider_incl_rate) { + cur_frm.cscript.recalc(doc, 2); + } else { + var basic_rate = cur_frm.cscript.back_calc_basic_rate( + doc, cur_frm.cscript.tname, fname, d, cur_frm.cscript.other_fname + ); + if (d.basic_rate != basic_rate.toFixed(2)) { + d.basic_rate = basic_rate; + refresh_field('basic_rate', d.name, fname); + msgprint("You cannot change Basic Rate* (Base Currency) when \ + considering rates inclusive of taxes.
\ + Please either
\ + * Specify Basic Rate (i.e. Rate which will be displayed in print)
\ + -- or --
\ + * Uncheck 'Included in Print Rate' in the tax entries of Taxes section."); + } + } } // ************************ EXPORT RATE ************************* -cur_frm.cscript.export_rate = function(doc,cdt,cdn) { cur_frm.cscript.recalc(doc, 3);} +cur_frm.cscript.export_rate = function(doc,cdt,cdn) { + doc = locals[doc.doctype][doc.name]; + cur_frm.cscript.recalc(doc, 1); +} @@ -177,7 +198,7 @@ cur_frm.cscript.recalc = function(doc, n) { if(!flt(doc.conversion_rate)) { doc.conversion_rate = 1; refresh_field('conversion_rate'); } if(!flt(doc.plc_conversion_rate)) { doc.plc_conversion_rate = 1; refresh_field('plc_conversion_rate'); } - if(n > 0) cur_frm.cscript.update_fname_table(doc , tname , fname , n); // updates all values in table (i.e. amount, export amount, net total etc.) + if(n > 0) cur_frm.cscript.update_fname_table(doc , tname , fname , n, other_fname); // updates all values in table (i.e. amount, export amount, net total etc.) if(flt(doc.net_total) > 0) { var cl = getchildren('RV Tax Detail', doc.name, other_fname,doc.doctype); @@ -218,11 +239,18 @@ cur_frm.cscript.calc_doc_values = function(doc, cdt, cdn, tname, fname, other_fn for(var i = 0; i net_total ? flt(net_total_incl) : flt(net_total); doc.other_charges_total = flt(other_charges_total); doc.grand_total = flt(flt(net_total) + flt(other_charges_total)); doc.rounded_total = Math.round(doc.grand_total); @@ -278,9 +306,12 @@ cur_frm.cscript.calc_other_charges = function(doc , tname , fname , other_fname) // this is calculation part for all types if(tax[t].charge_type != "Actual") tax[t].item_wise_tax_detail += item_wise_tax_detail; - tax[t].total_amount = flt(tax_amount.toFixed(2)); //stores actual tax amount in virtual field - tax[t].total_tax_amount = flt(prev_total.toFixed(2)); //stores total amount in virtual field - tax[t].tax_amount += flt(tax_amount.toFixed(2)); + //tax[t].total_amount = flt(tax_amount.toFixed(2)); //stores actual tax amount in virtual field + //tax[t].total_tax_amount = flt(prev_total.toFixed(2)); //stores total amount in virtual field + //tax[t].tax_amount += flt(tax_amount.toFixed(2)); + tax[t].total_amount = flt(tax_amount); //stores actual tax amount in virtual field + tax[t].total_tax_amount = flt(prev_total); //stores total amount in virtual field + tax[t].tax_amount += flt(tax_amount); var total_amount = flt(tax[t].tax_amount); total_tax_amount = flt(tax[t].total_tax_amount) + flt(total_amount); set_multiple('RV Tax Detail', tax[t].name, { 'item_wise_tax_detail':tax[t].item_wise_tax_detail, 'amount':total_amount, 'total':flt(total)+flt(tax[t].tax_amount)/*_tax_amount)*/}, other_fname); @@ -311,7 +342,8 @@ cur_frm.cscript.check_charge_type_and_get_tax_amount = function( doc, tax, t, cl refresh_field('total_excise_rate'); return } - return tax_amount = (flt(rate) * flt(cl.amount) / 100); + + return tax_amount = (flt(rate) * flt(cl.amount) / 100); } else if(tax[t].charge_type == 'On Previous Row Amount'){ if(flt(print_amt) == 1) { @@ -347,28 +379,150 @@ cur_frm.cscript.check_charge_type_and_get_tax_amount = function( doc, tax, t, cl } } +// ********************** Functions for inclusive value calc ****************************** +cur_frm.cscript.consider_incl_rate = function(doc, other_fname) { + var tax_list = getchildren('RV Tax Detail', doc.name, other_fname, doc.doctype); + for(var i=0; i \ + * On Net Total
\ + * On Previous Row Amount
\ + * On Previous Row Total"); + tax.included_in_print_rate = 0; + refresh_field('included_in_print_rate', tax.name, cur_frm.cscript.other_fname); + } else if(inList(['On Previous Row Total', 'On Previous Row Amount'], tax.charge_type)){ + if(tax.row_id) { + var tax_list = getchildren('RV Tax Detail', doc.name, cur_frm.cscript.other_fname, doc.doctype); + if(tax_list[tax.row_id-1].charge_type=='Actual') { + msgprint("Row of type 'Actual' cannot be depended on for type '" + tax.charge_type + "'\ + when using tax inclusive prices.
\ + This will lead to incorrect values.

\ + Please specify correct value in 'Enter Row' column of Row: " + + tax.idx + " in Taxes table"); + validated = false; + tax.included_in_print_rate = 0; + refresh_field('included_in_print_rate', tax.name, cur_frm.cscript.other_fname); + } + } + } + } +} + // ********************** Update values in table ****************************** -cur_frm.cscript.update_fname_table = function(doc , tname , fname , n) { +cur_frm.cscript.update_fname_table = function(doc , tname , fname , n, other_fname) { doc = locals[doc.doctype][doc.name] var net_total = 0 var cl = getchildren(tname, doc.name, fname); + var consider_incl_rate = cur_frm.cscript.consider_incl_rate(doc, other_fname); for(var i=0;i 0) - set_multiple(tname, cl[i].name, {'export_rate': flt(flt(cl[i].ref_rate) * (100 - flt(cl[i].adj_rate)) / 100)}, fname); - set_multiple(tname, cl[i].name, {'export_amount': flt(flt(cl[i].qty) * flt(cl[i].export_rate)), 'basic_rate': flt(flt(cl[i].export_rate) * flt(doc.conversion_rate)), 'amount': flt((flt(cl[i].export_rate) * flt(doc.conversion_rate)) * flt(cl[i].qty)) }, fname); + if(!consider_incl_rate && (flt(cl[i].ref_rate) > 0)) { + set_multiple(tname, cl[i].name, { + 'export_rate': flt(flt(cl[i].ref_rate) * (100 - flt(cl[i].adj_rate)) / 100) + }, fname); + + set_multiple(tname, cl[i].name, { + 'export_amount': flt(flt(cl[i].qty) * flt(cl[i].export_rate)), + 'basic_rate': flt(flt(cl[i].export_rate) * flt(doc.conversion_rate)), + 'amount': flt((flt(cl[i].export_rate) * flt(doc.conversion_rate)) * flt(cl[i].qty)) + }, fname); + + var base_ref_rate = flt(cl[i].basic_rate) + flt(flt(cl[i].basic_rate) * flt(cl[i].adj_rate) / 100); + set_multiple(tname, cl[i].name, { + 'base_ref_rate': flt(base_ref_rate) + }, fname); + + } else if(consider_incl_rate) { + if(flt(cl[i].export_rate) > 0) { + // calculate basic rate based on taxes + // then calculate and set basic_rate, base_ref_rate, ref_rate, amount, export_amount + var ref_rate = flt(cl[i].adj_rate)!=flt(100) ? + flt((100 * flt(cl[i].export_rate))/flt(100 - flt(cl[i].adj_rate))) : + flt(0) + set_multiple(tname, cl[i].name, { 'ref_rate': ref_rate }, fname); + } else if((flt(cl[i].ref_rate) > 0) && (flt(cl[i].adj_rate) > 0)) { + var export_rate = flt(cl[i].ref_rate) * flt(1 - flt(cl[i].adj_rate / 100)); + set_multiple(tname, cl[i].name, { 'export_rate': flt(export_rate) }, fname); + } + console.log("export_rate: " + cl[i].export_rate); + + var basic_rate = cur_frm.cscript.back_calc_basic_rate(doc, tname, fname, cl[i], other_fname); + var base_ref_rate = basic_rate + flt(basic_rate * flt(cl[i].adj_rate) / 100); + set_multiple(tname, cl[i].name, { + 'basic_rate': flt(basic_rate), + 'amount': flt(basic_rate * flt(cl[i].qty)), + 'export_amount': flt(flt(cl[i].qty) * flt(cl[i].export_rate)), + 'base_ref_rate': flt(base_ref_rate) + }, fname); + } } else if(n == 2){ if(flt(cl[i].ref_rate) > 0) set_multiple(tname, cl[i].name, {'adj_rate': 100 - flt(flt(cl[i].basic_rate) * 100 / (flt(cl[i].ref_rate) * flt(doc.conversion_rate)))}, fname); set_multiple(tname, cl[i].name, {'amount': flt(flt(cl[i].qty) * flt(cl[i].basic_rate)), 'export_rate': flt(flt(cl[i].basic_rate) / flt(doc.conversion_rate)), 'export_amount': flt((flt(cl[i].basic_rate) / flt(doc.conversion_rate)) * flt(cl[i].qty)) }, fname); } - else if(n == 3){ + /*else if(n == 3){ set_multiple(tname, cl[i].name, {'basic_rate': flt(flt(cl[i].export_rate) * flt(doc.conversion_rate))}, fname); set_multiple(tname, cl[i].name, {'amount' : flt(flt(cl[i].basic_rate) * flt(cl[i].qty)), 'export_amount': flt(flt(cl[i].export_rate) * flt(cl[i].qty))}, fname); if(cl[i].ref_rate > 0) set_multiple(tname, cl[i].name, {'adj_rate': 100 - flt(flt(cl[i].export_rate) * 100 / flt(cl[i].ref_rate)), 'base_ref_rate': flt(flt(cl[i].ref_rate) * flt(doc.conversion_rate)) }, fname); - } + }*/ net_total += flt(flt(cl[i].qty) * flt(cl[i].basic_rate)); } doc.net_total = net_total; @@ -389,20 +543,31 @@ cur_frm.cscript['Re-Calculate Values'] = function(doc, cdt, cdn) { } cur_frm.cscript['Calculate Charges'] = function(doc, cdt, cdn) { - var other_fname = cur_frm.cscript.other_fname; + var other_fname = cur_frm.cscript.other_fname; - var cl = getchildren('RV Tax Detail', doc.name, other_fname, doc.doctype); - for(var i = 0; i\ + This will lead to incorrect values.

\ + Please specify correct value in 'Enter Row' column of Row: " + + cl[i].idx + " in Taxes table"); + validated = false; + cl[i].included_in_print_rate = 0; + refresh_field('included_in_print_rate', cl[i].name, other_fname); + } + } + } + cur_frm.cscript.recalc(doc, 1); } // Get Sales Partner Commission diff --git a/erpnext/setup/doctype/other_charges/other_charges.js b/erpnext/setup/doctype/other_charges/other_charges.js index 4c154f529e..ddc9755254 100644 --- a/erpnext/setup/doctype/other_charges/other_charges.js +++ b/erpnext/setup/doctype/other_charges/other_charges.js @@ -36,7 +36,7 @@ cur_frm.pformat.other_charges= function(doc){ // add rows if(cl.length){ for(var i=0;i