From 0788570ce7aaf5bf4f13a8839bd5add3bc11451f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 20 Apr 2012 13:31:05 +0530 Subject: [PATCH] automatically write off feature in sales invoice --- .../doctype/sales_invoice/sales_invoice.js | 22 +- .../doctype/sales_invoice/sales_invoice.txt | 206 +++++++++--------- 2 files changed, 127 insertions(+), 101 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 4e7a51a261..cddb92e90b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -86,13 +86,19 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) { if(cint(doc.is_pos) == 1) { hide_field(par_flds); + $(cur_frm.fields_dict.payments_section.row.wrapper).toggle(true); + $(cur_frm.fields_dict.advances.row.wrapper).toggle(false); for(f in item_flds_normal) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_normal[f], false); for(f in item_flds_pos) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_pos[f], (doc.update_stock==1?true:false)); } else { unhide_field(par_flds); + $(cur_frm.fields_dict.payments_section.row.wrapper).toggle(false); + $(cur_frm.fields_dict.advances.row.wrapper).toggle(true); for(f in item_flds_normal) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_normal[f], true); for(f in item_flds_pos) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_pos[f], false); } + if (doc.docstatus==1) $(cur_frm.fields_dict.recurring_invoice.row.wrapper).toggle(true); + else $(cur_frm.fields_dict.recurring_invoice.row.wrapper).toggle(false); // India related fields var cp = wn.control_panel; @@ -236,9 +242,21 @@ cur_frm.cscript.debit_to = function(doc,dt,dn) { //refresh advance amount //------------------------------------------------- -cur_frm.cscript.paid_amount = function(doc,dt,dn){ + +cur_frm.cscript.write_off_outstanding_amount_automatically = function(doc) { + if (doc.write_off_outstanding_amount_automatically == 1) + doc.write_off_amount = flt(doc.grand_total) - flt(doc.paid_amount); + doc.outstanding_amount = flt(doc.grand_total) - flt(doc.paid_amount) - flt(doc.write_off_amount); - refresh_field('outstanding_amount'); + refresh_field(['write_off_amount', 'outstanding_amount']); +} + +cur_frm.cscript.paid_amount = function(doc) { + cur_frm.cscript.write_off_outstanding_amount_automatically(doc); +} + +cur_frm.cscript.write_off_amount = function(doc) { + cur_frm.cscript.write_off_outstanding_amount_automatically(doc); } diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt index c851e75952..6e76145291 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt @@ -3,9 +3,9 @@ # These values are common in all dictionaries { - 'creation': '2012-04-11 13:17:25', + 'creation': '2012-04-13 11:56:18', 'docstatus': 0, - 'modified': '2012-04-13 11:26:44', + 'modified': '2012-04-20 11:52:36', 'modified_by': u'Administrator', 'owner': u'Administrator' }, @@ -27,7 +27,7 @@ 'server_code_error': u' ', 'show_in_menu': 0, 'subject': u'To %(customer_name)s worth %(currency)s %(grand_total_export)s due on %(due_date)s | %(outstanding_amount)s outstanding', - 'version': 418 + 'version': 1 }, # These values are common for all DocField @@ -580,23 +580,6 @@ 'trigger': u'Client' }, - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'section_break1', - 'fieldtype': u'Section Break', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'column_break3', - 'fieldtype': u'Column Break', - 'permlevel': 0, - 'width': u'50%' - }, - # DocField { 'description': u'Will be calculated automatically when you enter the details', @@ -611,83 +594,6 @@ 'reqd': 1 }, - # DocField - { - 'colour': u'White:FFF', - 'depends_on': u'eval:doc.is_pos==1', - 'doctype': u'DocField', - 'fieldname': u'cash_bank_account', - 'fieldtype': u'Link', - 'label': u'Cash/Bank Account', - 'oldfieldname': u'cash_bank_account', - 'oldfieldtype': u'Link', - 'options': u'Account', - 'permlevel': 0, - 'print_hide': 1 - }, - - # DocField - { - 'colour': u'White:FFF', - 'depends_on': u'eval:doc.is_pos==1', - 'doctype': u'DocField', - 'fieldname': u'paid_amount', - 'fieldtype': u'Currency', - 'label': u'Paid Amount', - 'oldfieldname': u'paid_amount', - 'oldfieldtype': u'Currency', - 'permlevel': 0, - 'print_hide': 1, - 'trigger': u'Client' - }, - - # DocField - { - 'doctype': u'DocField', - 'fieldname': u'column_break4', - 'fieldtype': u'Column Break', - 'permlevel': 0, - 'width': u'50%' - }, - - # DocField - { - 'colour': u'White:FFF', - 'depends_on': u'eval:doc.is_pos==1', - 'doctype': u'DocField', - 'fieldname': u'write_off_account', - 'fieldtype': u'Link', - 'label': u'Write Off Account', - 'options': u'Account', - 'permlevel': 0, - 'print_hide': 1 - }, - - # DocField - { - 'colour': u'White:FFF', - 'depends_on': u'eval:doc.is_pos==1', - 'doctype': u'DocField', - 'fieldname': u'write_off_cost_center', - 'fieldtype': u'Link', - 'label': u'Write Off Cost Center', - 'options': u'Cost Center', - 'permlevel': 0, - 'print_hide': 1 - }, - - # DocField - { - 'colour': u'White:FFF', - 'depends_on': u'eval:doc.is_pos==1', - 'doctype': u'DocField', - 'fieldname': u'write_off_amount', - 'fieldtype': u'Currency', - 'label': u'Write Off Amount', - 'permlevel': 0, - 'print_hide': 1 - }, - # DocField { 'doctype': u'DocField', @@ -938,6 +844,109 @@ 'print_hide': 1 }, + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'payments_section', + 'fieldtype': u'Section Break', + 'label': u'Payments', + 'permlevel': 0 + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'column_break3', + 'fieldtype': u'Column Break', + 'permlevel': 0, + 'width': u'50%' + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'paid_amount', + 'fieldtype': u'Currency', + 'label': u'Paid Amount', + 'oldfieldname': u'paid_amount', + 'oldfieldtype': u'Currency', + 'permlevel': 0, + 'print_hide': 1, + 'trigger': u'Client' + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'cash_bank_account', + 'fieldtype': u'Link', + 'label': u'Cash/Bank Account', + 'oldfieldname': u'cash_bank_account', + 'oldfieldtype': u'Link', + 'options': u'Account', + 'permlevel': 0, + 'print_hide': 1 + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'column_break4', + 'fieldtype': u'Column Break', + 'permlevel': 0, + 'width': u'50%' + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'write_off_outstanding_amount_automatically', + 'fieldtype': u'Check', + 'label': u'Write Off Outstanding Amount Automatically', + 'permlevel': 0 + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'write_off_amount', + 'fieldtype': u'Currency', + 'label': u'Write Off Amount', + 'permlevel': 0, + 'print_hide': 1 + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'write_off_account', + 'fieldtype': u'Link', + 'label': u'Write Off Account', + 'options': u'Account', + 'permlevel': 0, + 'print_hide': 1 + }, + + # DocField + { + 'colour': u'White:FFF', + 'doctype': u'DocField', + 'fieldname': u'write_off_cost_center', + 'fieldtype': u'Link', + 'label': u'Write Off Cost Center', + 'options': u'Cost Center', + 'permlevel': 0, + 'print_hide': 1 + }, + # DocField { 'colour': u'White:FFF', @@ -1232,7 +1241,6 @@ # DocField { 'colour': u'White:FFF', - 'depends_on': u'eval:!doc.is_pos', 'doctype': u'DocField', 'fieldname': u'advances', 'fieldtype': u'Section Break', @@ -1369,7 +1377,7 @@ # DocField { - 'depends_on': u'eval:doc.docstatus==1', + 'colour': u'White:FFF', 'doctype': u'DocField', 'fieldname': u'recurring_invoice', 'fieldtype': u'Section Break',