blob: 91601a4312707d0060f760d19080e554f9b52470 [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302// License: GNU General Public License v3. See license.txt
Anand Doshi3543f302013-05-24 19:25:01 +05303
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05304frappe.provide("erpnext");
Nabin Haitb4a3dfa2015-01-22 17:13:13 +05305frappe.require("assets/erpnext/js/controllers/taxes_and_totals.js");
Neil Trini Lasrado78fa6952014-10-03 17:43:02 +05306frappe.require("assets/erpnext/js/utils.js");
7
Nabin Haitb4a3dfa2015-01-22 17:13:13 +05308erpnext.TransactionController = erpnext.taxes_and_totals.extend({
Anand Doshi3543f302013-05-24 19:25:01 +05309 onload: function() {
Anand Doshi1e4fb682013-08-23 12:56:33 +053010 var me = this;
Anand Doshi3543f302013-05-24 19:25:01 +053011 if(this.frm.doc.__islocal) {
Anand Doshi1e4fb682013-08-23 12:56:33 +053012 var today = get_today(),
Nabin Hait73083dc2014-03-14 15:10:42 +053013 currency = frappe.defaults.get_user_default("currency");
Rushabh Mehtaff938022014-04-15 18:40:00 +053014
Anand Doshi3543f302013-05-24 19:25:01 +053015 $.each({
Anand Doshifc777182013-05-27 19:29:07 +053016 posting_date: today,
17 due_date: today,
18 transaction_date: today,
19 currency: currency,
20 price_list_currency: currency,
21 status: "Draft",
Anand Doshifc777182013-05-27 19:29:07 +053022 is_subcontracted: "No",
Anand Doshi3543f302013-05-24 19:25:01 +053023 }, function(fieldname, value) {
24 if(me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname])
25 me.frm.set_value(fieldname, value);
Rushabh Mehtaff938022014-04-15 18:40:00 +053026 });
nabinhaitbc408d82014-07-07 16:51:52 +053027
nabinhaitb7392642014-07-28 14:55:08 +053028 if(this.frm.doc.company && !this.frm.doc.amended_from) {
nabinhaitbc408d82014-07-07 16:51:52 +053029 cur_frm.script_manager.trigger("company");
30 }
Anand Doshi3543f302013-05-24 19:25:01 +053031 }
Akhilesh Darjee564c6212013-10-17 11:31:11 +053032
Nabin Haitdd38a262014-12-26 13:15:21 +053033 if(this.frm.fields_dict["taxes"]) {
34 this["taxes_remove"] = this.calculate_taxes_and_totals;
Anand Doshia91c95f2013-08-23 13:00:47 +053035 }
Rushabh Mehtaff938022014-04-15 18:40:00 +053036
Nabin Haitdd38a262014-12-26 13:15:21 +053037 if(this.frm.fields_dict["items"]) {
38 this["items_remove"] = this.calculate_taxes_and_totals;
Anand Doshi1e4fb682013-08-23 12:56:33 +053039 }
Neil Trini Lasradoe2d8dd02015-06-22 19:06:15 +053040
41 if(this.frm.fields_dict["recurring_print_format"]) {
42 this.frm.set_query("recurring_print_format", function(doc) {
43 return{
44 filters: [
45 ['Print Format', 'doc_type', '=', cur_frm.doctype],
46 ]
47 }
48 });
49 }
Anand Doshi3543f302013-05-24 19:25:01 +053050 },
Rushabh Mehtaff938022014-04-15 18:40:00 +053051
Anand Doshi5e4e5d72013-08-06 17:23:44 +053052 onload_post_render: function() {
Akhilesh Darjee61b5c592013-10-15 20:24:34 +053053 var me = this;
Nabin Haitffc7f3f2015-05-12 15:07:02 +053054 if(this.frm.doc.__islocal && !(this.frm.doc.taxes || []).length
55 && !(this.frm.doc.__onload ? this.frm.doc.__onload.load_after_mapping : false)) {
56 this.apply_default_taxes();
57 }
Rushabh Mehta4a3c8052015-05-19 11:10:12 +053058
Nabin Haitdd38a262014-12-26 13:15:21 +053059 if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] && !this.frm.doc.is_pos) {
Anand Doshib054eb72014-04-22 20:35:22 +053060 this.calculate_taxes_and_totals();
Anand Doshi5e4e5d72013-08-06 17:23:44 +053061 }
Nabin Haitdd38a262014-12-26 13:15:21 +053062 if(frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "item_code")) {
63 cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
Rushabh Mehtab6843f22014-06-04 13:10:41 +053064 }
Anand Doshi5e4e5d72013-08-06 17:23:44 +053065 },
Rushabh Mehtaff938022014-04-15 18:40:00 +053066
Anand Doshi3543f302013-05-24 19:25:01 +053067 refresh: function() {
Anand Doshi8bde7f92014-04-24 18:11:49 +053068 erpnext.toggle_naming_series();
Anand Doshibdee6e02013-07-09 13:03:39 +053069 erpnext.hide_company();
Nabin Hait239c2c32015-01-15 14:21:41 +053070 this.hide_currency_and_price_list()
Anand Doshi3543f302013-05-24 19:25:01 +053071 this.show_item_wise_taxes();
Nabin Hait1f996c32013-07-29 19:00:53 +053072 this.set_dynamic_labels();
Anand Doshi50d7e8c2015-01-06 17:14:13 +053073 erpnext.pos.make_pos_btn(this.frm);
Rushabh Mehta614e7ab2015-02-18 19:51:48 +053074 this.setup_sms();
75 },
Rushabh Mehta4a3c8052015-05-19 11:10:12 +053076
Nabin Haitffc7f3f2015-05-12 15:07:02 +053077 apply_default_taxes: function() {
78 var me = this;
Rushabh Mehta4984bcc2015-05-21 12:51:07 +053079 var taxes_and_charges_field = frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges",
80 me.frm.doc.name);
81
82 if(taxes_and_charges_field) {
83 frappe.call({
84 method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
85 args: {
86 "master_doctype": taxes_and_charges_field.options
87 },
88 callback: function(r) {
89 if(!r.exc) {
90 me.frm.set_value("taxes", r.message);
91 }
Nabin Haitffc7f3f2015-05-12 15:07:02 +053092 }
Rushabh Mehta4984bcc2015-05-21 12:51:07 +053093 });
94 }
Nabin Haitffc7f3f2015-05-12 15:07:02 +053095 },
Rushabh Mehta614e7ab2015-02-18 19:51:48 +053096
97 setup_sms: function() {
98 var me = this;
Rushabh Mehta4a3c8052015-05-19 11:10:12 +053099 if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped"], this.frm.doc.status)
100 && this.frm.doctype != "Purchase Invoice") {
Rushabh Mehta614e7ab2015-02-18 19:51:48 +0530101 this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); });
102 }
103 },
104
105 send_sms: function() {
106 frappe.require("assets/erpnext/js/sms_manager.js");
Rushabh Mehta4a3c8052015-05-19 11:10:12 +0530107 var sms_man = new SMSManager(this.frm.doc);
Nabin Hait239c2c32015-01-15 14:21:41 +0530108 },
Anand Doshi50d7e8c2015-01-06 17:14:13 +0530109
Nabin Hait239c2c32015-01-15 14:21:41 +0530110 hide_currency_and_price_list: function() {
Nabin Hait093beec2015-05-26 10:47:52 +0530111 if(this.frm.doc.conversion_rate == 1 && this.frm.doc.docstatus > 0) {
Nabin Hait239c2c32015-01-15 14:21:41 +0530112 hide_field("currency_and_price_list");
113 } else {
114 unhide_field("currency_and_price_list");
115 }
Akhilesh Darjee6773bc22013-09-17 11:56:17 +0530116 },
117
Neil Trini Lasradod0151952015-06-09 15:21:50 +0530118 barcode: function(doc, cdt, cdn) {
119 var d = locals[cdt][cdn];
120 if(d.barcode=="" || d.barcode==null) {
121 // barcode cleared, remove item
122 d.item_code = "";
123 }
124 this.item_code(doc, cdt, cdn);
125 },
126
Nabin Hait139dc7b2014-02-12 14:53:18 +0530127 item_code: function(doc, cdt, cdn) {
128 var me = this;
Rushabh Mehta66d52b52014-03-27 14:17:33 +0530129 var item = frappe.get_doc(cdt, cdn);
Nabin Hait139dc7b2014-02-12 14:53:18 +0530130 if(item.item_code || item.barcode || item.serial_no) {
131 if(!this.validate_company_and_party()) {
Nabin Haitdd38a262014-12-26 13:15:21 +0530132 cur_frm.fields_dict["items"].grid.grid_rows[item.idx - 1].remove();
Nabin Hait139dc7b2014-02-12 14:53:18 +0530133 } else {
134 return this.frm.call({
135 method: "erpnext.stock.get_item_details.get_item_details",
136 child: item,
137 args: {
138 args: {
139 item_code: item.item_code,
140 barcode: item.barcode,
141 serial_no: item.serial_no,
142 warehouse: item.warehouse,
Nabin Hait444f9562014-06-20 15:59:49 +0530143 parenttype: me.frm.doc.doctype,
144 parent: me.frm.doc.name,
Nabin Hait139dc7b2014-02-12 14:53:18 +0530145 customer: me.frm.doc.customer,
146 supplier: me.frm.doc.supplier,
147 currency: me.frm.doc.currency,
148 conversion_rate: me.frm.doc.conversion_rate,
149 price_list: me.frm.doc.selling_price_list ||
150 me.frm.doc.buying_price_list,
151 price_list_currency: me.frm.doc.price_list_currency,
152 plc_conversion_rate: me.frm.doc.plc_conversion_rate,
153 company: me.frm.doc.company,
154 order_type: me.frm.doc.order_type,
155 is_pos: cint(me.frm.doc.is_pos),
156 is_subcontracted: me.frm.doc.is_subcontracted,
Nabin Haita1bf43b2015-03-17 10:50:47 +0530157 transaction_date: me.frm.doc.transaction_date || me.frm.doc.posting_date,
Nabin Hait444f9562014-06-20 15:59:49 +0530158 ignore_pricing_rule: me.frm.doc.ignore_pricing_rule,
159 doctype: item.doctype,
Anand Doshi43f087c2014-08-26 14:25:53 +0530160 name: item.name,
Anand Doshi9b955fe2015-01-05 16:19:12 +0530161 project_name: item.project_name || me.frm.doc.project_name,
162 qty: item.qty
Nabin Hait139dc7b2014-02-12 14:53:18 +0530163 }
164 },
Anand Doshi13945092014-09-21 19:45:49 +0530165
Nabin Hait139dc7b2014-02-12 14:53:18 +0530166 callback: function(r) {
167 if(!r.exc) {
168 me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
169 }
170 }
171 });
172 }
173 }
Rushabh Mehtaff938022014-04-15 18:40:00 +0530174 },
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530175
176 serial_no: function(doc, cdt, cdn) {
177 var me = this;
Rushabh Mehta66d52b52014-03-27 14:17:33 +0530178 var item = frappe.get_doc(cdt, cdn);
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530179
180 if (item.serial_no) {
181 if (!item.item_code) {
182 this.frm.script_manager.trigger("item_code", cdt, cdn);
183 }
184 else {
185 var sr_no = [];
186
187 // Replacing all occurences of comma with carriage return
188 var serial_nos = item.serial_no.trim().replace(/,/g, '\n');
189
190 serial_nos = serial_nos.trim().split('\n');
Rushabh Mehtaff938022014-04-15 18:40:00 +0530191
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530192 // Trim each string and push unique string to new list
193 for (var x=0; x<=serial_nos.length - 1; x++) {
194 if (serial_nos[x].trim() != "" && sr_no.indexOf(serial_nos[x].trim()) == -1) {
195 sr_no.push(serial_nos[x].trim());
196 }
197 }
198
199 // Add the new list to the serial no. field in grid with each in new line
200 item.serial_no = "";
201 for (var x=0; x<=sr_no.length - 1; x++)
202 item.serial_no += sr_no[x] + '\n';
203
204 refresh_field("serial_no", item.name, item.parentfield);
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530205 frappe.model.set_value(item.doctype, item.name, "qty", sr_no.length);
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530206 }
207 }
208 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530209
Anand Doshi923d41d2013-05-28 17:23:36 +0530210 validate: function() {
Anand Doshi652bc072014-04-16 15:21:46 +0530211 this.calculate_taxes_and_totals(false);
Anand Doshi923d41d2013-05-28 17:23:36 +0530212 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530213
Anand Doshi3543f302013-05-24 19:25:01 +0530214 company: function() {
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530215 var me = this;
216 var fn = function() {
217 if(me.frm.doc.company && me.frm.fields_dict.currency) {
218 var company_currency = me.get_company_currency();
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530219 var company_doc = frappe.get_doc(":Company", me.frm.doc.company);
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530220 if (!me.frm.doc.currency) {
221 me.frm.set_value("currency", company_currency);
222 }
Rushabh Mehtaff938022014-04-15 18:40:00 +0530223
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530224 if (me.frm.doc.currency == company_currency) {
225 me.frm.set_value("conversion_rate", 1.0);
226 }
227 if (me.frm.doc.price_list_currency == company_currency) {
228 me.frm.set_value('plc_conversion_rate', 1.0);
229 }
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530230 if (company_doc.default_letter_head) {
Rushabh Mehtac1857342015-05-27 12:29:57 +0530231 if(me.frm.fields_dict.letter_head) {
232 me.frm.set_value("letter_head", company_doc.default_letter_head);
233 }
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530234 }
Rushabh Mehtac1857342015-05-27 12:29:57 +0530235 if (company_doc.default_terms && me.frm.doc.doctype != "Purchase Invoice") {
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530236 me.frm.set_value("tc_name", company_doc.default_terms);
237 }
Akhilesh Darjee1797cfe2013-10-11 13:34:10 +0530238
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530239 me.frm.script_manager.trigger("currency");
240 me.apply_pricing_rule();
Nabin Haitdd38a262014-12-26 13:15:21 +0530241 }
Anand Doshi3543f302013-05-24 19:25:01 +0530242 }
Nabin Haitdd38a262014-12-26 13:15:21 +0530243
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530244 if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date;
245 else var date = this.frm.doc.transaction_date;
246 erpnext.get_fiscal_year(this.frm.doc.company, date, fn);
Rushabh Mehta45ca8a42015-04-28 16:02:09 +0530247
248 if(this.frm.doc.company) {
249 erpnext.last_selected_company = this.frm.doc.company;
250 }
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530251 },
252
253 transaction_date: function() {
254 erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.transaction_date);
Neil Trini Lasrado78fa6952014-10-03 17:43:02 +0530255 },
256
257 posting_date: function() {
Neil Trini Lasrado565d9862014-10-07 18:26:39 +0530258 erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.posting_date);
Anand Doshi3543f302013-05-24 19:25:01 +0530259 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530260
Anand Doshi3543f302013-05-24 19:25:01 +0530261 get_company_currency: function() {
262 return erpnext.get_currency(this.frm.doc.company);
263 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530264
Anand Doshi3543f302013-05-24 19:25:01 +0530265 currency: function() {
Anand Doshi61a2f682013-06-21 17:55:31 +0530266 var me = this;
267 this.set_dynamic_labels();
Akhilesh Darjee78378272013-10-11 19:06:30 +0530268
Anand Doshi61a2f682013-06-21 17:55:31 +0530269 var company_currency = this.get_company_currency();
Nabin Hait69cdf592015-05-02 18:46:10 +0530270 // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
Pratik Vyas1a84d8e2015-05-19 12:23:52 +0530271 if(this.frm.doc.currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
Rushabh Mehtaff938022014-04-15 18:40:00 +0530272 this.get_exchange_rate(this.frm.doc.currency, company_currency,
Anand Doshi61a2f682013-06-21 17:55:31 +0530273 function(exchange_rate) {
Akhilesh Darjee78378272013-10-11 19:06:30 +0530274 me.frm.set_value("conversion_rate", exchange_rate);
Anand Doshi61a2f682013-06-21 17:55:31 +0530275 });
276 } else {
Rushabh Mehtaff938022014-04-15 18:40:00 +0530277 this.conversion_rate();
Anand Doshi61a2f682013-06-21 17:55:31 +0530278 }
279 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530280
Anand Doshi61a2f682013-06-21 17:55:31 +0530281 conversion_rate: function() {
Anand Doshi535d8332013-07-19 13:51:07 +0530282 if(this.frm.doc.currency === this.get_company_currency()) {
283 this.frm.set_value("conversion_rate", 1.0);
Akhilesh Darjeeacf65a72013-10-17 13:04:26 +0530284 }
285 if(this.frm.doc.currency === this.frm.doc.price_list_currency &&
Anand Doshi61a2f682013-06-21 17:55:31 +0530286 this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) {
287 this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate);
288 }
Rushabh Mehta4a3c8052015-05-19 11:10:12 +0530289
Nabin Haita3dd72a2014-05-28 12:49:20 +0530290 if(flt(this.frm.doc.conversion_rate)>0.0) {
Nabin Hait444f9562014-06-20 15:59:49 +0530291 if(this.frm.doc.ignore_pricing_rule) {
292 this.calculate_taxes_and_totals();
Anand Doshi51f722d2014-07-04 15:44:26 +0530293 } else if (!this.in_apply_price_list){
294 this.apply_price_list();
Nabin Hait444f9562014-06-20 15:59:49 +0530295 }
296
Nabin Haita3dd72a2014-05-28 12:49:20 +0530297 }
Anand Doshi3543f302013-05-24 19:25:01 +0530298 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530299
Anand Doshi61a2f682013-06-21 17:55:31 +0530300 get_exchange_rate: function(from_currency, to_currency, callback) {
Rushabh Mehta66fa1ff2015-05-07 12:25:33 +0530301 frappe.call({
302 method: "erpnext.setup.utils.get_exchange_rate",
303 args: {
304 from_currency: from_currency,
305 to_currency: to_currency
306 },
307 callback: function(r) {
308 callback(flt(r.message));
309 }
Anand Doshi61a2f682013-06-21 17:55:31 +0530310 });
311 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530312
Anand Doshi3543f302013-05-24 19:25:01 +0530313 price_list_currency: function() {
Akhilesh Darjeedb59ffb2013-09-11 13:05:24 +0530314 var me=this;
Anand Doshi3543f302013-05-24 19:25:01 +0530315 this.set_dynamic_labels();
Nabin Haitec361ea2015-05-11 18:14:45 +0530316
317 var company_currency = this.get_company_currency();
318 // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
319 if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
320 this.get_exchange_rate(this.frm.doc.price_list_currency, company_currency,
321 function(exchange_rate) {
322 me.frm.set_value("plc_conversion_rate", exchange_rate);
323 });
324 } else {
325 this.plc_conversion_rate();
326 }
Anand Doshi3543f302013-05-24 19:25:01 +0530327 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530328
Anand Doshi3543f302013-05-24 19:25:01 +0530329 plc_conversion_rate: function() {
Anand Doshi61a2f682013-06-21 17:55:31 +0530330 if(this.frm.doc.price_list_currency === this.get_company_currency()) {
331 this.frm.set_value("plc_conversion_rate", 1.0);
Nabin Haitec361ea2015-05-11 18:14:45 +0530332 } else if(this.frm.doc.price_list_currency === this.frm.doc.currency && this.frm.doc.plc_conversion_rate && cint(this.frm.doc.plc_conversion_rate) != 1 &&
333 cint(this.frm.doc.plc_conversion_rate) != cint(this.frm.doc.conversion_rate)) {
334 this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate);
Akhilesh Darjee564c6212013-10-17 11:31:11 +0530335 }
Rushabh Mehta4a3c8052015-05-19 11:10:12 +0530336
Nabin Haitec361ea2015-05-11 18:14:45 +0530337 if(!this.in_apply_price_list) {
338 this.apply_price_list();
Anand Doshi61a2f682013-06-21 17:55:31 +0530339 }
Anand Doshi3543f302013-05-24 19:25:01 +0530340 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530341
Anand Doshi3543f302013-05-24 19:25:01 +0530342 qty: function(doc, cdt, cdn) {
Nabin Hait444f9562014-06-20 15:59:49 +0530343 this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
Anand Doshi3543f302013-05-24 19:25:01 +0530344 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530345
Anand Doshi61a2f682013-06-21 17:55:31 +0530346 set_dynamic_labels: function() {
347 // What TODO? should we make price list system non-mandatory?
348 this.frm.toggle_reqd("plc_conversion_rate",
349 !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency));
Rushabh Mehtaff938022014-04-15 18:40:00 +0530350
Anand Doshi61a2f682013-06-21 17:55:31 +0530351 var company_currency = this.get_company_currency();
352 this.change_form_labels(company_currency);
353 this.change_grid_labels(company_currency);
Anand Doshi5013dcb2013-08-05 12:16:04 +0530354 this.frm.refresh_fields();
Anand Doshi61a2f682013-06-21 17:55:31 +0530355 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530356
Nabin Hait613d0812015-02-23 11:58:15 +0530357 change_form_labels: function(company_currency) {
358 var me = this;
359 var field_label_map = {};
360
361 var setup_field_label_map = function(fields_list, currency) {
362 $.each(fields_list, function(i, fname) {
363 var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
364 if(docfield) {
365 var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
366 field_label_map[fname] = label.trim() + " (" + currency + ")";
367 }
368 });
369 };
370 setup_field_label_map(["base_total", "base_net_total", "base_total_taxes_and_charges",
371 "base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words",
372 "base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay",
Nabin Hait37b047d2015-02-23 16:01:33 +0530373 "outstanding_amount", "total_advance", "paid_amount", "write_off_amount"], company_currency);
Nabin Hait613d0812015-02-23 11:58:15 +0530374
375 setup_field_label_map(["total", "net_total", "total_taxes_and_charges", "discount_amount",
376 "grand_total", "taxes_and_charges_added", "taxes_and_charges_deducted",
377 "rounded_total", "in_words"], this.frm.doc.currency);
378
379 cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
380 + " = [?] " + company_currency)
381
382 if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
383 cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
384 + " = [?] " + company_currency)
385 }
386
387 // toggle fields
388 this.frm.toggle_display(["conversion_rate", "base_total", "base_net_total", "base_total_taxes_and_charges",
389 "base_taxes_and_charges_added", "base_taxes_and_charges_deducted",
390 "base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount"],
391 this.frm.doc.currency != company_currency);
392
393 this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
394 this.frm.doc.price_list_currency != company_currency);
395
396 // set labels
397 $.each(field_label_map, function(fname, label) {
398 me.frm.fields_dict[fname].set_label(label);
399 });
Nabin Hait37b047d2015-02-23 16:01:33 +0530400
Nabin Hait903c42a2015-02-24 15:24:49 +0530401 var show =cint(cur_frm.doc.discount_amount) ||
402 ((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
403
404 if(frappe.meta.get_docfield(cur_frm.doctype, "net_total"))
405 cur_frm.toggle_display("net_total", show);
406
407 if(frappe.meta.get_docfield(cur_frm.doctype, "base_net_total"))
408 cur_frm.toggle_display("base_net_total", (show && (me.frm.doc.currency != company_currency)));
409
Nabin Hait613d0812015-02-23 11:58:15 +0530410 },
411
412 change_grid_labels: function(company_currency) {
413 var me = this;
414 var field_label_map = {};
415
416 var setup_field_label_map = function(fields_list, currency, parentfield) {
417 var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
418 $.each(fields_list, function(i, fname) {
419 var docfield = frappe.meta.docfield_map[grid_doctype][fname];
420 if(docfield) {
421 var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
422 field_label_map[grid_doctype + "-" + fname] =
423 label.trim() + " (" + currency + ")";
424 }
425 });
426 }
427
428 setup_field_label_map(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"],
429 company_currency, "items");
430
431 setup_field_label_map(["rate", "net_rate", "price_list_rate", "amount", "net_amount"],
432 this.frm.doc.currency, "items");
433
434 if(this.frm.fields_dict["taxes"]) {
435 setup_field_label_map(["tax_amount", "total", "tax_amount_after_discount"], this.frm.doc.currency, "taxes");
436
437 setup_field_label_map(["base_tax_amount", "base_total", "base_tax_amount_after_discount"], company_currency, "taxes");
438 }
439
440 if(this.frm.fields_dict["advances"]) {
441 setup_field_label_map(["advance_amount", "allocated_amount"], company_currency, "advances");
442 }
443
444 // toggle columns
445 var item_grid = this.frm.fields_dict["items"].grid;
446 $.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) {
447 if(frappe.meta.get_docfield(item_grid.doctype, fname))
448 item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency);
449 });
450
451 var show = (cint(cur_frm.doc.discount_amount)) ||
452 ((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
453
454 $.each(["net_rate", "net_amount"], function(i, fname) {
455 if(frappe.meta.get_docfield(item_grid.doctype, fname))
456 item_grid.set_column_disp(fname, show);
457 });
458
459 $.each(["base_net_rate", "base_net_amount"], function(i, fname) {
460 if(frappe.meta.get_docfield(item_grid.doctype, fname))
461 item_grid.set_column_disp(fname, (show && (me.frm.doc.currency != company_currency)));
462 });
463
464 // set labels
465 var $wrapper = $(this.frm.wrapper);
466 $.each(field_label_map, function(fname, label) {
467 fname = fname.split("-");
468 var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
469 if(df) df.label = label;
470 });
471 },
472
Anand Doshi923d41d2013-05-28 17:23:36 +0530473 recalculate: function() {
474 this.calculate_taxes_and_totals();
475 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530476
Anand Doshi923d41d2013-05-28 17:23:36 +0530477 recalculate_values: function() {
478 this.calculate_taxes_and_totals();
479 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530480
Anand Doshid0b00722013-05-28 18:54:48 +0530481 calculate_charges: function() {
482 this.calculate_taxes_and_totals();
483 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530484
Nabin Hait444f9562014-06-20 15:59:49 +0530485 ignore_pricing_rule: function() {
486 this.apply_pricing_rule();
487 },
488
489 apply_pricing_rule: function(item, calculate_taxes_and_totals) {
Nabin Haita3dd72a2014-05-28 12:49:20 +0530490 var me = this;
Anand Doshidffec8f2014-07-01 17:45:15 +0530491 return this.frm.call({
492 method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule",
493 args: { args: this._get_args(item) },
494 callback: function(r) {
Anand Doshif214bfc2014-07-16 17:52:08 +0530495 if (!r.exc && r.message) {
Anand Doshidffec8f2014-07-01 17:45:15 +0530496 me._set_values_for_item_list(r.message);
497 if(calculate_taxes_and_totals) me.calculate_taxes_and_totals();
498 }
499 }
500 });
501 },
502
503 _get_args: function(item) {
504 var me = this;
505 return {
506 "item_list": this._get_item_list(item),
Nabin Hait444f9562014-06-20 15:59:49 +0530507 "customer": me.frm.doc.customer,
508 "customer_group": me.frm.doc.customer_group,
509 "territory": me.frm.doc.territory,
510 "supplier": me.frm.doc.supplier,
511 "supplier_type": me.frm.doc.supplier_type,
512 "currency": me.frm.doc.currency,
513 "conversion_rate": me.frm.doc.conversion_rate,
514 "price_list": me.frm.doc.selling_price_list || me.frm.doc.buying_price_list,
Nabin Haitdd82bf22015-05-11 16:49:17 +0530515 "price_list_currency": me.frm.doc.price_list_currency,
Nabin Hait444f9562014-06-20 15:59:49 +0530516 "plc_conversion_rate": me.frm.doc.plc_conversion_rate,
517 "company": me.frm.doc.company,
518 "transaction_date": me.frm.doc.transaction_date || me.frm.doc.posting_date,
519 "campaign": me.frm.doc.campaign,
520 "sales_partner": me.frm.doc.sales_partner,
521 "ignore_pricing_rule": me.frm.doc.ignore_pricing_rule,
522 "parenttype": me.frm.doc.doctype,
523 "parent": me.frm.doc.name
524 };
Nabin Hait444f9562014-06-20 15:59:49 +0530525 },
526
527 _get_item_list: function(item) {
528 var item_list = [];
529 var append_item = function(d) {
Anand Doshi39edcbc2014-07-28 16:00:19 +0530530 if (d.item_code) {
531 item_list.push({
532 "doctype": d.doctype,
533 "name": d.name,
534 "item_code": d.item_code,
535 "item_group": d.item_group,
536 "brand": d.brand,
537 "qty": d.qty
538 });
539 }
Nabin Hait444f9562014-06-20 15:59:49 +0530540 };
Nabin Haita3dd72a2014-05-28 12:49:20 +0530541
Nabin Hait444f9562014-06-20 15:59:49 +0530542 if (item) {
543 append_item(item);
Nabin Haitc1367d92014-05-30 11:43:00 +0530544 } else {
Nabin Hait96339342015-01-21 17:22:11 +0530545 $.each(this.frm.doc["items"] || [], function(i, d) {
Nabin Hait444f9562014-06-20 15:59:49 +0530546 append_item(d);
Nabin Haita3dd72a2014-05-28 12:49:20 +0530547 });
548 }
Nabin Hait444f9562014-06-20 15:59:49 +0530549 return item_list;
Nabin Haita3dd72a2014-05-28 12:49:20 +0530550 },
551
Anand Doshidffec8f2014-07-01 17:45:15 +0530552 _set_values_for_item_list: function(children) {
Nabin Hait49a27292014-12-17 11:21:32 +0530553 var me = this;
Nabin Hait7d8fa802014-12-30 15:35:45 +0530554 var price_list_rate_changed = false;
Anand Doshidea3fb02015-02-05 15:05:58 +0530555 for(var i=0, l=children.length; i<l; i++) {
556 var d = children[i];
Nabin Hait49a27292014-12-17 11:21:32 +0530557 var existing_pricing_rule = frappe.model.get_value(d.doctype, d.name, "pricing_rule");
Anand Doshidea3fb02015-02-05 15:05:58 +0530558
559 for(var k in d) {
560 var v = d[k];
Anand Doshidffec8f2014-07-01 17:45:15 +0530561 if (["doctype", "name"].indexOf(k)===-1) {
Nabin Hait7d8fa802014-12-30 15:35:45 +0530562 if(k=="price_list_rate") {
563 if(flt(v) != flt(d.price_list_rate)) price_list_rate_changed = true;
564 }
Anand Doshidffec8f2014-07-01 17:45:15 +0530565 frappe.model.set_value(d.doctype, d.name, k, v);
566 }
Anand Doshidea3fb02015-02-05 15:05:58 +0530567 }
568
Nabin Hait49a27292014-12-17 11:21:32 +0530569 // if pricing rule set as blank from an existing value, apply price_list
Nabin Haitcfe3c542014-12-22 10:42:48 +0530570 if(!me.frm.doc.ignore_pricing_rule && existing_pricing_rule && !d.pricing_rule) {
Nabin Hait49a27292014-12-17 11:21:32 +0530571 me.apply_price_list(frappe.get_doc(d.doctype, d.name));
572 }
Anand Doshidea3fb02015-02-05 15:05:58 +0530573 }
Nabin Hait7d8fa802014-12-30 15:35:45 +0530574
Anand Doshidea3fb02015-02-05 15:05:58 +0530575 if(!price_list_rate_changed) me.calculate_taxes_and_totals();
Anand Doshidffec8f2014-07-01 17:45:15 +0530576 },
577
Nabin Hait49a27292014-12-17 11:21:32 +0530578 apply_price_list: function(item) {
Anand Doshidffec8f2014-07-01 17:45:15 +0530579 var me = this;
Rushabh Mehta052bd622015-01-30 16:57:24 +0530580 var args = this._get_args(item);
Nabin Hait37b047d2015-02-23 16:01:33 +0530581
Anand Doshidffec8f2014-07-01 17:45:15 +0530582 return this.frm.call({
583 method: "erpnext.stock.get_item_details.apply_price_list",
Rushabh Mehta052bd622015-01-30 16:57:24 +0530584 args: { args: args },
Anand Doshidffec8f2014-07-01 17:45:15 +0530585 callback: function(r) {
586 if (!r.exc) {
Anand Doshi51f722d2014-07-04 15:44:26 +0530587 me.in_apply_price_list = true;
Anand Doshidffec8f2014-07-01 17:45:15 +0530588 me.frm.set_value("price_list_currency", r.message.parent.price_list_currency);
589 me.frm.set_value("plc_conversion_rate", r.message.parent.plc_conversion_rate);
Anand Doshi51f722d2014-07-04 15:44:26 +0530590 me.in_apply_price_list = false;
Nabin Hait37b047d2015-02-23 16:01:33 +0530591
592 if(args.item_list.length) {
593 me._set_values_for_item_list(r.message.children);
594 }
Anand Doshidffec8f2014-07-01 17:45:15 +0530595 }
596 }
597 });
598 },
599
Anand Doshi3543f302013-05-24 19:25:01 +0530600 get_item_wise_taxes_html: function() {
601 var item_tax = {};
602 var tax_accounts = [];
603 var company_currency = this.get_company_currency();
Rushabh Mehtaff938022014-04-15 18:40:00 +0530604
Nabin Hait96339342015-01-21 17:22:11 +0530605 $.each(this.frm.doc["taxes"] || [], function(i, tax) {
Anand Doshi3543f302013-05-24 19:25:01 +0530606 var tax_amount_precision = precision("tax_amount", tax);
Anand Doshi53b73422013-05-31 11:50:01 +0530607 var tax_rate_precision = precision("rate", tax);
Rushabh Mehtaff938022014-04-15 18:40:00 +0530608 $.each(JSON.parse(tax.item_wise_tax_detail || '{}'),
Anand Doshi53b73422013-05-31 11:50:01 +0530609 function(item_code, tax_data) {
Anand Doshi3543f302013-05-24 19:25:01 +0530610 if(!item_tax[item_code]) item_tax[item_code] = {};
Anand Doshi53b73422013-05-31 11:50:01 +0530611 if($.isArray(tax_data)) {
Anand Doshi1e4fb682013-08-23 12:56:33 +0530612 var tax_rate = "";
613 if(tax_data[0] != null) {
614 tax_rate = (tax.charge_type === "Actual") ?
615 format_currency(flt(tax_data[0], tax_amount_precision), company_currency, tax_amount_precision) :
616 (flt(tax_data[0], tax_rate_precision) + "%");
617 }
618 var tax_amount = format_currency(flt(tax_data[1], tax_amount_precision), company_currency,
619 tax_amount_precision);
Rushabh Mehtaff938022014-04-15 18:40:00 +0530620
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530621 item_tax[item_code][tax.name] = [tax_rate, tax_amount];
Anand Doshi53b73422013-05-31 11:50:01 +0530622 } else {
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530623 item_tax[item_code][tax.name] = [flt(tax_data, tax_rate_precision) + "%", ""];
Anand Doshi53b73422013-05-31 11:50:01 +0530624 }
Anand Doshi3543f302013-05-24 19:25:01 +0530625 });
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530626 tax_accounts.push([tax.name, tax.account_head]);
Anand Doshi3543f302013-05-24 19:25:01 +0530627 });
Rushabh Mehtaff938022014-04-15 18:40:00 +0530628
629 var headings = $.map([__("Item Name")].concat($.map(tax_accounts, function(head) { return head[1]; })),
Anand Doshi3543f302013-05-24 19:25:01 +0530630 function(head) { return '<th style="min-width: 100px;">' + (head || "") + "</th>" }).join("\n");
Rushabh Mehtaff938022014-04-15 18:40:00 +0530631
Anand Doshi179e3772013-09-05 16:53:57 +0530632 var distinct_item_names = [];
633 var distinct_items = [];
Nabin Hait96339342015-01-21 17:22:11 +0530634 $.each(this.frm.doc["items"] || [], function(i, item) {
Anand Doshi179e3772013-09-05 16:53:57 +0530635 if(distinct_item_names.indexOf(item.item_code || item.item_name)===-1) {
636 distinct_item_names.push(item.item_code || item.item_name);
637 distinct_items.push(item);
638 }
639 });
Rushabh Mehtaff938022014-04-15 18:40:00 +0530640
Anand Doshi179e3772013-09-05 16:53:57 +0530641 var rows = $.map(distinct_items, function(item) {
Anand Doshi3543f302013-05-24 19:25:01 +0530642 var item_tax_record = item_tax[item.item_code || item.item_name];
Anand Doshi53b73422013-05-31 11:50:01 +0530643 if(!item_tax_record) { return null; }
Anand Doshi3543f302013-05-24 19:25:01 +0530644 return repl("<tr><td>%(item_name)s</td>%(taxes)s</tr>", {
645 item_name: item.item_name,
646 taxes: $.map(tax_accounts, function(head) {
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530647 return item_tax_record[head[0]] ?
648 "<td>(" + item_tax_record[head[0]][0] + ") " + item_tax_record[head[0]][1] + "</td>" :
Anand Doshi64f316b2013-07-17 15:12:22 +0530649 "<td></td>";
Anand Doshi3543f302013-05-24 19:25:01 +0530650 }).join("\n")
651 });
652 }).join("\n");
Rushabh Mehtaff938022014-04-15 18:40:00 +0530653
Anand Doshi53b73422013-05-31 11:50:01 +0530654 if(!rows) return "";
Rushabh Mehta7d8b1892013-11-08 16:27:18 +0530655 return '<p><a href="#" onclick="$(\'.tax-break-up\').toggleClass(\'hide\'); return false;">Show / Hide tax break-up</a><br><br></p>\
656 <div class="tax-break-up hide" style="overflow-x: auto;"><table class="table table-bordered table-hover">\
Anand Doshi3543f302013-05-24 19:25:01 +0530657 <thead><tr>' + headings + '</tr></thead> \
658 <tbody>' + rows + '</tbody> \
659 </table></div>';
660 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530661
Nabin Hait139dc7b2014-02-12 14:53:18 +0530662 validate_company_and_party: function() {
Anand Doshi923d41d2013-05-28 17:23:36 +0530663 var me = this;
Anand Doshi3543f302013-05-24 19:25:01 +0530664 var valid = true;
Rushabh Mehtaff938022014-04-15 18:40:00 +0530665
Nabin Hait0f231062014-02-20 11:27:47 +0530666 $.each(["company", "customer"], function(i, fieldname) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530667 if(frappe.meta.has_field(me.frm.doc.doctype, fieldname)) {
Nabin Hait139dc7b2014-02-12 14:53:18 +0530668 if (!me.frm.doc[fieldname]) {
Rushabh Mehtaff938022014-04-15 18:40:00 +0530669 msgprint(__("Please specify") + ": " +
670 frappe.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
Pratik Vyasb52618c2014-04-14 16:25:30 +0530671 ". " + __("It is needed to fetch Item Details."));
Nabin Hait139dc7b2014-02-12 14:53:18 +0530672 valid = false;
673 }
Anand Doshi3543f302013-05-24 19:25:01 +0530674 }
675 });
676 return valid;
677 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530678
Anand Doshibf3e54a2013-06-05 14:11:32 +0530679 get_terms: function() {
680 var me = this;
681 if(this.frm.doc.tc_name) {
Anand Doshi1fac2a92013-07-29 19:30:39 +0530682 return this.frm.call({
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530683 method: "frappe.client.get_value",
Anand Doshibf3e54a2013-06-05 14:11:32 +0530684 args: {
685 doctype: "Terms and Conditions",
686 fieldname: "terms",
687 filters: { name: this.frm.doc.tc_name },
688 },
689 });
690 }
691 },
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530692
693 taxes_and_charges: function() {
694 var me = this;
695 if(this.frm.doc.taxes_and_charges) {
696 return this.frm.call({
Nabin Hait6b039142014-05-02 15:45:10 +0530697 method: "erpnext.controllers.accounts_controller.get_taxes_and_charges",
698 args: {
Nabin Hait03f3a8a2014-05-13 16:38:31 +0530699 "master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges",
700 this.frm.doc.name).options,
Nabin Hait6b039142014-05-02 15:45:10 +0530701 "master_name": this.frm.doc.taxes_and_charges,
Nabin Hait6b039142014-05-02 15:45:10 +0530702 },
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530703 callback: function(r) {
704 if(!r.exc) {
Nabin Haitdd38a262014-12-26 13:15:21 +0530705 me.frm.set_value("taxes", r.message);
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530706 me.calculate_taxes_and_totals();
707 }
708 }
709 });
Nabin Haitbc83b9c2014-05-02 17:03:18 +0530710 }
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530711 },
712
713 show_item_wise_taxes: function() {
714 if(this.frm.fields_dict.other_charges_calculation) {
Anand Doshidd942bb2015-02-04 18:52:35 +0530715 var html = this.get_item_wise_taxes_html();
716 if (html) {
717 this.frm.toggle_display("other_charges_calculation", true);
718 $(this.frm.fields_dict.other_charges_calculation.wrapper).html(html);
719 } else {
720 this.frm.toggle_display("other_charges_calculation", false);
721 }
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530722 }
723 },
Anand Doshi13945092014-09-21 19:45:49 +0530724
725 is_recurring: function() {
726 // set default values for recurring documents
727 if(this.frm.doc.is_recurring) {
728 var owner_email = this.frm.doc.owner=="Administrator"
729 ? frappe.user_info("Administrator").email
730 : this.frm.doc.owner;
731
732 this.frm.doc.notification_email_address = $.map([cstr(owner_email),
733 cstr(this.frm.doc.contact_email)], function(v) { return v || null; }).join(", ");
734 this.frm.doc.repeat_on_day_of_month = frappe.datetime.str_to_obj(this.frm.doc.posting_date).getDate();
735 }
736
737 refresh_many(["notification_email_address", "repeat_on_day_of_month"]);
738 },
739
740 from_date: function() {
741 // set to_date
742 if(this.frm.doc.from_date) {
743 var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6,
744 'Yearly': 12};
745
746 var months = recurring_type_map[this.frm.doc.recurring_type];
747 if(months) {
748 var to_date = frappe.datetime.add_months(this.frm.doc.from_date,
749 months);
750 this.frm.doc.to_date = frappe.datetime.add_days(to_date, -1);
751 refresh_field('to_date');
752 }
753 }
754 }
Rushabh Mehtaff938022014-04-15 18:40:00 +0530755});
Nabin Haitce245122015-02-22 20:14:49 +0530756
Nabin Hait93b3a372015-02-24 17:08:34 +0530757frappe.ui.form.on(cur_frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
Nabin Haitce245122015-02-22 20:14:49 +0530758 var item = frappe.get_doc(cdt, cdn);
759 frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
760
761 if(item.price_list_rate) {
762 item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
763 } else {
764 item.discount_percentage = 0.0;
765 }
766
767 cur_frm.cscript.calculate_taxes_and_totals();
768})
Nabin Hait613d0812015-02-23 11:58:15 +0530769
770frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
771 cur_frm.cscript.calculate_taxes_and_totals();
772})
773
774frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
775 cur_frm.cscript.calculate_taxes_and_totals();
776})
777
778frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
779 cur_frm.cscript.calculate_taxes_and_totals();
780})
781
782frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
Nabin Hait903c42a2015-02-24 15:24:49 +0530783 cur_frm.cscript.set_dynamic_labels();
Nabin Hait613d0812015-02-23 11:58:15 +0530784 cur_frm.cscript.calculate_taxes_and_totals();
785})
Nabin Hait37b047d2015-02-23 16:01:33 +0530786
787frappe.ui.form.on(cur_frm.doctype, "apply_discount_on", function(frm) {
788 cur_frm.cscript.calculate_taxes_and_totals();
789})
790
791frappe.ui.form.on(cur_frm.doctype, "discount_amount", function(frm) {
Nabin Hait903c42a2015-02-24 15:24:49 +0530792 cur_frm.cscript.set_dynamic_labels();
Nabin Hait37b047d2015-02-23 16:01:33 +0530793 cur_frm.cscript.calculate_taxes_and_totals();
794})
Neil Trini Lasradoe2d8dd02015-06-22 19:06:15 +0530795
796