Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | // License: GNU General Public License v3. See license.txt |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 3 | |
Nabin Hait | b4a3dfa | 2015-01-22 17:13:13 +0530 | [diff] [blame] | 4 | erpnext.TransactionController = erpnext.taxes_and_totals.extend({ |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 5 | setup: function() { |
Rushabh Mehta | 2cb7a9f | 2016-06-15 16:45:03 +0530 | [diff] [blame] | 6 | this._super(); |
Rohit Waghchaure | 6ab6303 | 2017-09-01 15:28:44 +0530 | [diff] [blame] | 7 | frappe.flags.hide_serial_batch_dialog = false; |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 8 | frappe.ui.form.on(this.frm.doctype + " Item", "rate", function(frm, cdt, cdn) { |
| 9 | var item = frappe.get_doc(cdt, cdn); |
Rushabh Mehta | f69ffeb | 2017-05-17 19:40:40 +0530 | [diff] [blame] | 10 | var has_margin_field = frappe.meta.has_field(cdt, 'margin_type'); |
| 11 | |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 12 | frappe.model.round_floats_in(item, ["rate", "price_list_rate"]); |
| 13 | |
| 14 | if(item.price_list_rate) { |
Rushabh Mehta | f69ffeb | 2017-05-17 19:40:40 +0530 | [diff] [blame] | 15 | if(item.rate > item.price_list_rate && has_margin_field) { |
| 16 | // if rate is greater than price_list_rate, set margin |
| 17 | // or set discount |
| 18 | item.discount_percentage = 0; |
Nabin Hait | e72c98d | 2017-05-24 09:01:44 +0530 | [diff] [blame] | 19 | item.margin_type = 'Amount'; |
Rushabh Mehta | 3631102 | 2017-06-20 09:30:53 +0530 | [diff] [blame] | 20 | item.margin_rate_or_amount = flt(item.rate - item.price_list_rate, |
Nabin Hait | e72c98d | 2017-05-24 09:01:44 +0530 | [diff] [blame] | 21 | precision("margin_rate_or_amount", item)); |
| 22 | item.rate_with_margin = item.rate; |
Rushabh Mehta | f69ffeb | 2017-05-17 19:40:40 +0530 | [diff] [blame] | 23 | } else { |
Rushabh Mehta | 3631102 | 2017-06-20 09:30:53 +0530 | [diff] [blame] | 24 | item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, |
Rushabh Mehta | f69ffeb | 2017-05-17 19:40:40 +0530 | [diff] [blame] | 25 | precision("discount_percentage", item)); |
| 26 | item.margin_type = ''; |
| 27 | item.margin_rate_or_amount = 0; |
| 28 | item.rate_with_margin = 0; |
| 29 | } |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 30 | } else { |
| 31 | item.discount_percentage = 0.0; |
Rushabh Mehta | f69ffeb | 2017-05-17 19:40:40 +0530 | [diff] [blame] | 32 | item.margin_type = ''; |
| 33 | item.margin_rate_or_amount = 0; |
| 34 | item.rate_with_margin = 0; |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | cur_frm.cscript.set_gross_profit(item); |
| 38 | cur_frm.cscript.calculate_taxes_and_totals(); |
Vishal Dhayagude | d42242d | 2017-11-29 16:09:59 +0530 | [diff] [blame] | 39 | |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 40 | }); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 41 | |
Vishal Dhayagude | d42242d | 2017-11-29 16:09:59 +0530 | [diff] [blame] | 42 | |
| 43 | |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 44 | frappe.ui.form.on(this.frm.cscript.tax_table, "rate", function(frm, cdt, cdn) { |
| 45 | cur_frm.cscript.calculate_taxes_and_totals(); |
Rushabh Mehta | 764aa92 | 2016-05-02 13:28:46 +0530 | [diff] [blame] | 46 | }); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 47 | |
| 48 | frappe.ui.form.on(this.frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) { |
| 49 | cur_frm.cscript.calculate_taxes_and_totals(); |
Rushabh Mehta | 764aa92 | 2016-05-02 13:28:46 +0530 | [diff] [blame] | 50 | }); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 51 | |
| 52 | frappe.ui.form.on(this.frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) { |
| 53 | cur_frm.cscript.calculate_taxes_and_totals(); |
Rushabh Mehta | 764aa92 | 2016-05-02 13:28:46 +0530 | [diff] [blame] | 54 | }); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 55 | |
| 56 | frappe.ui.form.on(this.frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) { |
| 57 | cur_frm.cscript.set_dynamic_labels(); |
| 58 | cur_frm.cscript.calculate_taxes_and_totals(); |
Rushabh Mehta | 764aa92 | 2016-05-02 13:28:46 +0530 | [diff] [blame] | 59 | }); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 60 | |
| 61 | frappe.ui.form.on(this.frm.doctype, "apply_discount_on", function(frm) { |
| 62 | if(frm.doc.additional_discount_percentage) { |
| 63 | frm.trigger("additional_discount_percentage"); |
| 64 | } else { |
| 65 | cur_frm.cscript.calculate_taxes_and_totals(); |
| 66 | } |
Rushabh Mehta | 764aa92 | 2016-05-02 13:28:46 +0530 | [diff] [blame] | 67 | }); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 68 | |
| 69 | frappe.ui.form.on(this.frm.doctype, "additional_discount_percentage", function(frm) { |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 70 | if(!frm.doc.apply_discount_on) { |
| 71 | frappe.msgprint(__("Please set 'Apply Additional Discount On'")); |
Rushabh Mehta | 233a19a | 2017-07-07 13:05:11 +0530 | [diff] [blame] | 72 | return; |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | frm.via_discount_percentage = true; |
| 76 | |
| 77 | if(frm.doc.additional_discount_percentage && frm.doc.discount_amount) { |
| 78 | // Reset discount amount and net / grand total |
Rushabh Mehta | 6705ab3 | 2017-07-07 13:14:08 +0530 | [diff] [blame] | 79 | frm.doc.discount_amount = 0; |
| 80 | frm.cscript.calculate_taxes_and_totals(); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | var total = flt(frm.doc[frappe.model.scrub(frm.doc.apply_discount_on)]); |
| 84 | var discount_amount = flt(total*flt(frm.doc.additional_discount_percentage) / 100, |
| 85 | precision("discount_amount")); |
| 86 | |
Rushabh Mehta | 233a19a | 2017-07-07 13:05:11 +0530 | [diff] [blame] | 87 | frm.set_value("discount_amount", discount_amount) |
| 88 | .then(() => delete frm.via_discount_percentage); |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 89 | }); |
| 90 | |
| 91 | frappe.ui.form.on(this.frm.doctype, "discount_amount", function(frm) { |
| 92 | frm.cscript.set_dynamic_labels(); |
| 93 | |
| 94 | if (!frm.via_discount_percentage) { |
Rushabh Mehta | 233a19a | 2017-07-07 13:05:11 +0530 | [diff] [blame] | 95 | frm.doc.additional_discount_percentage = 0; |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | frm.cscript.calculate_taxes_and_totals(); |
| 99 | }); |
Makarand Bauskar | c196d74 | 2017-06-02 17:28:40 +0530 | [diff] [blame] | 100 | |
| 101 | var me = this; |
| 102 | if(this.frm.fields_dict["items"].grid.get_field('batch_no')) { |
| 103 | this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) { |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 104 | return me.set_query_for_batch(doc, cdt, cdn); |
Makarand Bauskar | c196d74 | 2017-06-02 17:28:40 +0530 | [diff] [blame] | 105 | }); |
| 106 | } |
Akhilesh Darjee | 564c621 | 2013-10-17 11:31:11 +0530 | [diff] [blame] | 107 | |
tundebabzy | 590bd0a | 2017-12-25 07:10:19 +0100 | [diff] [blame] | 108 | if( |
| 109 | this.frm.fields_dict["payment_terms_template"] |
| 110 | && this.frm.fields_dict["payment_schedule"] |
| 111 | && this.frm.doc.payment_terms_template |
| 112 | && !this.frm.doc.payment_schedule.length |
| 113 | ){ |
tunde | df3a175 | 2017-09-11 11:02:57 +0100 | [diff] [blame] | 114 | this.frm.trigger("payment_terms_template"); |
| 115 | } |
| 116 | |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 117 | if(this.frm.fields_dict["taxes"]) { |
| 118 | this["taxes_remove"] = this.calculate_taxes_and_totals; |
Anand Doshi | a91c95f | 2013-08-23 13:00:47 +0530 | [diff] [blame] | 119 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 120 | |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 121 | if(this.frm.fields_dict["items"]) { |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 122 | this["items_remove"] = this.calculate_net_weight; |
Anand Doshi | 1e4fb68 | 2013-08-23 12:56:33 +0530 | [diff] [blame] | 123 | } |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 124 | |
Neil Trini Lasrado | e2d8dd0 | 2015-06-22 19:06:15 +0530 | [diff] [blame] | 125 | if(this.frm.fields_dict["recurring_print_format"]) { |
| 126 | this.frm.set_query("recurring_print_format", function(doc) { |
| 127 | return{ |
| 128 | filters: [ |
| 129 | ['Print Format', 'doc_type', '=', cur_frm.doctype], |
| 130 | ] |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 131 | }; |
Neil Trini Lasrado | e2d8dd0 | 2015-06-22 19:06:15 +0530 | [diff] [blame] | 132 | }); |
| 133 | } |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 134 | |
Nabin Hait | 1d21842 | 2015-07-17 15:19:02 +0530 | [diff] [blame] | 135 | if(this.frm.fields_dict["return_against"]) { |
| 136 | this.frm.set_query("return_against", function(doc) { |
| 137 | var filters = { |
| 138 | "docstatus": 1, |
| 139 | "is_return": 0, |
| 140 | "company": doc.company |
| 141 | }; |
| 142 | if (me.frm.fields_dict["customer"] && doc.customer) filters["customer"] = doc.customer; |
| 143 | if (me.frm.fields_dict["supplier"] && doc.supplier) filters["supplier"] = doc.supplier; |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 144 | |
Nabin Hait | 1d21842 | 2015-07-17 15:19:02 +0530 | [diff] [blame] | 145 | return { |
| 146 | filters: filters |
Nabin Hait | 7b6eaee | 2017-10-03 01:09:46 +0530 | [diff] [blame] | 147 | }; |
Nabin Hait | 1d21842 | 2015-07-17 15:19:02 +0530 | [diff] [blame] | 148 | }); |
| 149 | } |
Nabin Hait | 7b6eaee | 2017-10-03 01:09:46 +0530 | [diff] [blame] | 150 | }, |
| 151 | onload: function() { |
| 152 | var me = this; |
Rushabh Mehta | 6b53792 | 2017-03-14 16:59:11 +0530 | [diff] [blame] | 153 | |
Nabin Hait | 8af429d | 2016-11-16 17:21:59 +0530 | [diff] [blame] | 154 | this.setup_quality_inspection(); |
Nabin Hait | 7b6eaee | 2017-10-03 01:09:46 +0530 | [diff] [blame] | 155 | |
| 156 | if(this.frm.doc.__islocal) { |
| 157 | var currency = frappe.defaults.get_user_default("currency"); |
| 158 | |
| 159 | let set_value = (fieldname, value) => { |
| 160 | if(me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname]) { |
| 161 | return me.frm.set_value(fieldname, value); |
| 162 | } |
| 163 | }; |
| 164 | |
| 165 | return frappe.run_serially([ |
| 166 | () => set_value('currency', currency), |
| 167 | () => set_value('price_list_currency', currency), |
| 168 | () => set_value('status', 'Draft'), |
| 169 | () => set_value('is_subcontracted', 'No'), |
| 170 | () => { |
| 171 | if(this.frm.doc.company && !this.frm.doc.amended_from) { |
| 172 | this.frm.trigger("company"); |
| 173 | } |
| 174 | } |
| 175 | ]); |
| 176 | } |
Manas Solanki | c2cd3fd | 2016-11-14 21:57:05 +0530 | [diff] [blame] | 177 | }, |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 178 | |
Nabin Hait | 8af429d | 2016-11-16 17:21:59 +0530 | [diff] [blame] | 179 | setup_quality_inspection: function() { |
| 180 | if(!in_list(["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype)) { |
| 181 | return; |
| 182 | } |
Manas Solanki | c2cd3fd | 2016-11-14 21:57:05 +0530 | [diff] [blame] | 183 | var me = this; |
Rushabh Mehta | 6b53792 | 2017-03-14 16:59:11 +0530 | [diff] [blame] | 184 | var inspection_type = in_list(["Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype) |
Nabin Hait | 8af429d | 2016-11-16 17:21:59 +0530 | [diff] [blame] | 185 | ? "Incoming" : "Outgoing"; |
Rushabh Mehta | 6b53792 | 2017-03-14 16:59:11 +0530 | [diff] [blame] | 186 | |
Manas Solanki | a8d1bc7 | 2016-11-15 14:48:23 +0530 | [diff] [blame] | 187 | var quality_inspection_field = this.frm.get_docfield("items", "quality_inspection"); |
Nabin Hait | 8af429d | 2016-11-16 17:21:59 +0530 | [diff] [blame] | 188 | quality_inspection_field.get_route_options_for_new_doc = function(row) { |
Manas Solanki | c2cd3fd | 2016-11-14 21:57:05 +0530 | [diff] [blame] | 189 | if(me.frm.is_new()) return; |
Manas Solanki | c2cd3fd | 2016-11-14 21:57:05 +0530 | [diff] [blame] | 190 | return { |
| 191 | "inspection_type": inspection_type, |
Manas Solanki | 34feab1 | 2016-11-16 14:36:28 +0530 | [diff] [blame] | 192 | "reference_type": me.frm.doc.doctype, |
Manas Solanki | dbc2511 | 2016-11-16 15:06:08 +0530 | [diff] [blame] | 193 | "reference_name": me.frm.doc.name, |
Nabin Hait | 8af429d | 2016-11-16 17:21:59 +0530 | [diff] [blame] | 194 | "item_code": row.doc.item_code, |
| 195 | "description": row.doc.description, |
| 196 | "item_serial_no": row.doc.serial_no ? row.doc.serial_no.split("\n")[0] : null, |
| 197 | "batch_no": row.doc.batch_no |
Manas Solanki | c2cd3fd | 2016-11-14 21:57:05 +0530 | [diff] [blame] | 198 | } |
| 199 | } |
Rushabh Mehta | 6b53792 | 2017-03-14 16:59:11 +0530 | [diff] [blame] | 200 | |
Manas Solanki | c2cd3fd | 2016-11-14 21:57:05 +0530 | [diff] [blame] | 201 | this.frm.set_query("quality_inspection", "items", function(doc, cdt, cdn) { |
| 202 | var d = locals[cdt][cdn]; |
| 203 | return { |
| 204 | filters: { |
| 205 | docstatus: 1, |
| 206 | inspection_type: inspection_type, |
| 207 | item_code: d.item_code |
| 208 | } |
| 209 | } |
| 210 | }); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 211 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 212 | |
Anand Doshi | 5e4e5d7 | 2013-08-06 17:23:44 +0530 | [diff] [blame] | 213 | onload_post_render: function() { |
Nabin Hait | ffc7f3f | 2015-05-12 15:07:02 +0530 | [diff] [blame] | 214 | if(this.frm.doc.__islocal && !(this.frm.doc.taxes || []).length |
| 215 | && !(this.frm.doc.__onload ? this.frm.doc.__onload.load_after_mapping : false)) { |
Nabin Hait | 7b6eaee | 2017-10-03 01:09:46 +0530 | [diff] [blame] | 216 | frappe.after_ajax(() => this.apply_default_taxes()); |
Anand Doshi | 70f57eb | 2015-11-27 14:37:40 +0530 | [diff] [blame] | 217 | } else if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] |
Nabin Hait | bdfb070 | 2015-10-28 15:38:08 +0530 | [diff] [blame] | 218 | && !this.frm.doc.is_pos) { |
Nabin Hait | 7b6eaee | 2017-10-03 01:09:46 +0530 | [diff] [blame] | 219 | frappe.after_ajax(() => this.calculate_taxes_and_totals()); |
Anand Doshi | 5e4e5d7 | 2013-08-06 17:23:44 +0530 | [diff] [blame] | 220 | } |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 221 | if(frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "item_code")) { |
Rushabh Mehta | 203cc96 | 2016-04-07 15:25:43 +0530 | [diff] [blame] | 222 | this.setup_item_selector(); |
Rushabh Mehta | b6843f2 | 2014-06-04 13:10:41 +0530 | [diff] [blame] | 223 | } |
Anand Doshi | 5e4e5d7 | 2013-08-06 17:23:44 +0530 | [diff] [blame] | 224 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 225 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 226 | refresh: function() { |
Anand Doshi | 8bde7f9 | 2014-04-24 18:11:49 +0530 | [diff] [blame] | 227 | erpnext.toggle_naming_series(); |
Anand Doshi | bdee6e0 | 2013-07-09 13:03:39 +0530 | [diff] [blame] | 228 | erpnext.hide_company(); |
Nabin Hait | 1f996c3 | 2013-07-29 19:00:53 +0530 | [diff] [blame] | 229 | this.set_dynamic_labels(); |
Rushabh Mehta | 614e7ab | 2015-02-18 19:51:48 +0530 | [diff] [blame] | 230 | this.setup_sms(); |
| 231 | }, |
Rushabh Mehta | 4a3c805 | 2015-05-19 11:10:12 +0530 | [diff] [blame] | 232 | |
Nabin Hait | ffc7f3f | 2015-05-12 15:07:02 +0530 | [diff] [blame] | 233 | apply_default_taxes: function() { |
| 234 | var me = this; |
Rushabh Mehta | 4984bcc | 2015-05-21 12:51:07 +0530 | [diff] [blame] | 235 | var taxes_and_charges_field = frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges", |
| 236 | me.frm.doc.name); |
| 237 | |
rohitwaghchaure | 1f39feb | 2018-01-05 12:25:45 +0530 | [diff] [blame] | 238 | if (!this.frm.doc.taxes_and_charges && this.frm.doc.taxes) { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | if (taxes_and_charges_field) { |
Nabin Hait | bdfb070 | 2015-10-28 15:38:08 +0530 | [diff] [blame] | 243 | return frappe.call({ |
Rushabh Mehta | 4984bcc | 2015-05-21 12:51:07 +0530 | [diff] [blame] | 244 | method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges", |
| 245 | args: { |
rohitwaghchaure | 505661b | 2017-12-11 14:52:28 +0530 | [diff] [blame] | 246 | "master_doctype": taxes_and_charges_field.options, |
Nabin Hait | a2426fc | 2018-01-15 17:45:46 +0530 | [diff] [blame] | 247 | "tax_template": me.frm.doc.taxes_and_charges, |
rohitwaghchaure | 505661b | 2017-12-11 14:52:28 +0530 | [diff] [blame] | 248 | "company": me.frm.doc.company |
Rushabh Mehta | 4984bcc | 2015-05-21 12:51:07 +0530 | [diff] [blame] | 249 | }, |
| 250 | callback: function(r) { |
Nabin Hait | a2426fc | 2018-01-15 17:45:46 +0530 | [diff] [blame] | 251 | if(!r.exc && r.message) { |
Rushabh Mehta | 98aa581 | 2017-11-14 09:32:32 +0530 | [diff] [blame] | 252 | frappe.run_serially([ |
| 253 | () => { |
| 254 | // directly set in doc, so as not to call triggers |
rohitwaghchaure | 1bc47fa | 2017-12-16 10:49:58 +0530 | [diff] [blame] | 255 | if(r.message.taxes_and_charges) { |
| 256 | me.frm.doc.taxes_and_charges = r.message.taxes_and_charges; |
| 257 | } |
Rushabh Mehta | 98aa581 | 2017-11-14 09:32:32 +0530 | [diff] [blame] | 258 | |
| 259 | // set taxes table |
rohitwaghchaure | 1bc47fa | 2017-12-16 10:49:58 +0530 | [diff] [blame] | 260 | if(r.message.taxes) { |
| 261 | me.frm.set_value("taxes", r.message.taxes); |
| 262 | } |
Rushabh Mehta | 98aa581 | 2017-11-14 09:32:32 +0530 | [diff] [blame] | 263 | }, |
| 264 | () => me.calculate_taxes_and_totals() |
| 265 | ]); |
Rushabh Mehta | 4984bcc | 2015-05-21 12:51:07 +0530 | [diff] [blame] | 266 | } |
Nabin Hait | ffc7f3f | 2015-05-12 15:07:02 +0530 | [diff] [blame] | 267 | } |
Rushabh Mehta | 4984bcc | 2015-05-21 12:51:07 +0530 | [diff] [blame] | 268 | }); |
| 269 | } |
Nabin Hait | ffc7f3f | 2015-05-12 15:07:02 +0530 | [diff] [blame] | 270 | }, |
Rushabh Mehta | 614e7ab | 2015-02-18 19:51:48 +0530 | [diff] [blame] | 271 | |
| 272 | setup_sms: function() { |
| 273 | var me = this; |
Nabin Hait | 7132bd3 | 2016-04-13 15:19:37 +0530 | [diff] [blame] | 274 | if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped", "Closed"], this.frm.doc.status) |
Rushabh Mehta | 4a3c805 | 2015-05-19 11:10:12 +0530 | [diff] [blame] | 275 | && this.frm.doctype != "Purchase Invoice") { |
Rushabh Mehta | 614e7ab | 2015-02-18 19:51:48 +0530 | [diff] [blame] | 276 | this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); }); |
| 277 | } |
| 278 | }, |
| 279 | |
| 280 | send_sms: function() { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 281 | var sms_man = new erpnext.SMSManager(this.frm.doc); |
Nabin Hait | 239c2c3 | 2015-01-15 14:21:41 +0530 | [diff] [blame] | 282 | }, |
Anand Doshi | 50d7e8c | 2015-01-06 17:14:13 +0530 | [diff] [blame] | 283 | |
Neil Trini Lasrado | d015195 | 2015-06-09 15:21:50 +0530 | [diff] [blame] | 284 | barcode: function(doc, cdt, cdn) { |
| 285 | var d = locals[cdt][cdn]; |
| 286 | if(d.barcode=="" || d.barcode==null) { |
| 287 | // barcode cleared, remove item |
| 288 | d.item_code = ""; |
| 289 | } |
Rushabh Mehta | 675f9c6 | 2016-06-02 16:34:00 +0530 | [diff] [blame] | 290 | this.item_code(doc, cdt, cdn, true); |
Neil Trini Lasrado | d015195 | 2015-06-09 15:21:50 +0530 | [diff] [blame] | 291 | }, |
| 292 | |
Rushabh Mehta | 675f9c6 | 2016-06-02 16:34:00 +0530 | [diff] [blame] | 293 | item_code: function(doc, cdt, cdn, from_barcode) { |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 294 | var me = this; |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 295 | var item = frappe.get_doc(cdt, cdn); |
pratu16x7 | 5f389c9 | 2017-06-26 13:38:24 +0530 | [diff] [blame] | 296 | var update_stock = 0, show_batch_dialog = 0; |
pratu16x7 | 577e4c4 | 2017-06-23 11:39:03 +0530 | [diff] [blame] | 297 | |
rohitwaghchaure | 5999ade | 2017-08-09 17:24:13 +0530 | [diff] [blame] | 298 | if(['Sales Invoice'].includes(this.frm.doc.doctype)) { |
pratu16x7 | 577e4c4 | 2017-06-23 11:39:03 +0530 | [diff] [blame] | 299 | update_stock = cint(me.frm.doc.update_stock); |
| 300 | show_batch_dialog = update_stock; |
pratu16x7 | ae450fc | 2017-06-26 15:31:46 +0530 | [diff] [blame] | 301 | |
| 302 | } else if((this.frm.doc.doctype === 'Purchase Receipt' && me.frm.doc.is_return) || |
| 303 | this.frm.doc.doctype === 'Delivery Note') { |
pratu16x7 | 89d001c | 2017-06-26 17:45:49 +0530 | [diff] [blame] | 304 | show_batch_dialog = 1; |
pratu16x7 | 577e4c4 | 2017-06-23 11:39:03 +0530 | [diff] [blame] | 305 | } |
Rushabh Mehta | 675f9c6 | 2016-06-02 16:34:00 +0530 | [diff] [blame] | 306 | |
| 307 | // clear barcode if setting item (else barcode will take priority) |
| 308 | if(!from_barcode) { |
| 309 | item.barcode = null; |
| 310 | } |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 311 | if(item.item_code || item.barcode || item.serial_no) { |
| 312 | if(!this.validate_company_and_party()) { |
pratu16x7 | 577e4c4 | 2017-06-23 11:39:03 +0530 | [diff] [blame] | 313 | this.frm.fields_dict["items"].grid.grid_rows[item.idx - 1].remove(); |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 314 | } else { |
| 315 | return this.frm.call({ |
| 316 | method: "erpnext.stock.get_item_details.get_item_details", |
| 317 | child: item, |
| 318 | args: { |
| 319 | args: { |
| 320 | item_code: item.item_code, |
| 321 | barcode: item.barcode, |
| 322 | serial_no: item.serial_no, |
| 323 | warehouse: item.warehouse, |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 324 | customer: me.frm.doc.customer, |
| 325 | supplier: me.frm.doc.supplier, |
| 326 | currency: me.frm.doc.currency, |
pratu16x7 | 577e4c4 | 2017-06-23 11:39:03 +0530 | [diff] [blame] | 327 | update_stock: update_stock, |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 328 | conversion_rate: me.frm.doc.conversion_rate, |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 329 | price_list: me.frm.doc.selling_price_list || me.frm.doc.buying_price_list, |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 330 | price_list_currency: me.frm.doc.price_list_currency, |
| 331 | plc_conversion_rate: me.frm.doc.plc_conversion_rate, |
| 332 | company: me.frm.doc.company, |
| 333 | order_type: me.frm.doc.order_type, |
| 334 | is_pos: cint(me.frm.doc.is_pos), |
| 335 | is_subcontracted: me.frm.doc.is_subcontracted, |
Nabin Hait | a1bf43b | 2015-03-17 10:50:47 +0530 | [diff] [blame] | 336 | transaction_date: me.frm.doc.transaction_date || me.frm.doc.posting_date, |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 337 | ignore_pricing_rule: me.frm.doc.ignore_pricing_rule, |
Anand Doshi | afe85bd | 2016-01-21 21:04:16 +0530 | [diff] [blame] | 338 | doctype: me.frm.doc.doctype, |
| 339 | name: me.frm.doc.name, |
Neil Trini Lasrado | 6e343e2 | 2016-03-09 17:02:59 +0530 | [diff] [blame] | 340 | project: item.project || me.frm.doc.project, |
mbauskar | ba41242 | 2017-04-19 12:35:51 +0530 | [diff] [blame] | 341 | qty: item.qty || 1, |
Rohit Waghchaure | dc981dc | 2017-04-03 14:17:08 +0530 | [diff] [blame] | 342 | stock_qty: item.stock_qty, |
rohitwaghchaure | c037dc7 | 2017-11-28 16:11:15 +0530 | [diff] [blame] | 343 | conversion_factor: item.conversion_factor, |
Vishal Dhayagude | d42242d | 2017-11-29 16:09:59 +0530 | [diff] [blame] | 344 | weight_per_unit: item.weight_per_unit, |
| 345 | weight_uom: item.weight_uom, |
rohitwaghchaure | c037dc7 | 2017-11-28 16:11:15 +0530 | [diff] [blame] | 346 | pos_profile: me.frm.doc.doctype == 'Sales Invoice' ? me.frm.doc.pos_profile : '' |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 347 | } |
| 348 | }, |
Anand Doshi | 1394509 | 2014-09-21 19:45:49 +0530 | [diff] [blame] | 349 | |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 350 | callback: function(r) { |
| 351 | if(!r.exc) { |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 352 | frappe.run_serially([ |
| 353 | () => me.frm.script_manager.trigger("price_list_rate", cdt, cdn), |
| 354 | () => me.toggle_conversion_factor(item), |
| 355 | () => { |
| 356 | if(show_batch_dialog && !frappe.flags.hide_serial_batch_dialog) { |
| 357 | var d = locals[cdt][cdn]; |
| 358 | $.each(r.message, function(k, v) { |
| 359 | if(!d[k]) d[k] = v; |
| 360 | }); |
Rohit Waghchaure | 6ab6303 | 2017-09-01 15:28:44 +0530 | [diff] [blame] | 361 | |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 362 | erpnext.show_serial_batch_selector(me.frm, d, (item) => { |
| 363 | me.frm.script_manager.trigger('qty', item.doctype, item.name); |
| 364 | }); |
| 365 | } |
| 366 | }, |
| 367 | () => me.conversion_factor(doc, cdt, cdn, true) |
| 368 | ]); |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | }); |
| 372 | } |
| 373 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 374 | }, |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 375 | |
| 376 | serial_no: function(doc, cdt, cdn) { |
| 377 | var me = this; |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 378 | var item = frappe.get_doc(cdt, cdn); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 379 | |
| 380 | if (item.serial_no) { |
| 381 | if (!item.item_code) { |
Rushabh Mehta | b66edd1 | 2017-03-30 21:21:56 +0530 | [diff] [blame] | 382 | this.frm.trigger("item_code", cdt, cdn); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 383 | } |
| 384 | else { |
Nabin Hait | 79c2191 | 2017-07-12 14:10:43 +0530 | [diff] [blame] | 385 | var valid_serial_nos = []; |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 386 | |
| 387 | // Replacing all occurences of comma with carriage return |
| 388 | var serial_nos = item.serial_no.trim().replace(/,/g, '\n'); |
| 389 | |
| 390 | serial_nos = serial_nos.trim().split('\n'); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 391 | |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 392 | // Trim each string and push unique string to new list |
| 393 | for (var x=0; x<=serial_nos.length - 1; x++) { |
Nabin Hait | 79c2191 | 2017-07-12 14:10:43 +0530 | [diff] [blame] | 394 | if (serial_nos[x].trim() != "" && valid_serial_nos.indexOf(serial_nos[x].trim()) == -1) { |
| 395 | valid_serial_nos.push(serial_nos[x].trim()); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | // Add the new list to the serial no. field in grid with each in new line |
Nabin Hait | 79c2191 | 2017-07-12 14:10:43 +0530 | [diff] [blame] | 400 | item.serial_no = valid_serial_nos.join('\n'); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 401 | |
| 402 | refresh_field("serial_no", item.name, item.parentfield); |
Nabin Hait | b7c0c55 | 2015-08-04 12:18:12 +0530 | [diff] [blame] | 403 | if(!doc.is_return) { |
Rushabh Mehta | 6b53792 | 2017-03-14 16:59:11 +0530 | [diff] [blame] | 404 | frappe.model.set_value(item.doctype, item.name, |
Nabin Hait | 79c2191 | 2017-07-12 14:10:43 +0530 | [diff] [blame] | 405 | "qty", valid_serial_nos.length / item.conversion_factor); |
| 406 | frappe.model.set_value(item.doctype, item.name, "stock_qty", valid_serial_nos.length); |
Nabin Hait | b7c0c55 | 2015-08-04 12:18:12 +0530 | [diff] [blame] | 407 | } |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 411 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 412 | validate: function() { |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 413 | this.calculate_taxes_and_totals(false); |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 414 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 415 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 416 | company: function() { |
Neil Trini Lasrado | eaae58f | 2014-10-09 15:00:10 +0530 | [diff] [blame] | 417 | var me = this; |
Nabin Hait | a731ad4 | 2016-02-04 17:21:28 +0530 | [diff] [blame] | 418 | var set_pricing = function() { |
Neil Trini Lasrado | eaae58f | 2014-10-09 15:00:10 +0530 | [diff] [blame] | 419 | if(me.frm.doc.company && me.frm.fields_dict.currency) { |
| 420 | var company_currency = me.get_company_currency(); |
Rushabh Mehta | 5495bc5 | 2015-05-19 12:00:34 +0530 | [diff] [blame] | 421 | var company_doc = frappe.get_doc(":Company", me.frm.doc.company); |
tundebabzy | 5510d07 | 2017-09-29 10:51:59 +0100 | [diff] [blame] | 422 | |
Nabin Hait | 1f10d69 | 2017-10-02 13:20:51 +0530 | [diff] [blame] | 423 | if (!me.frm.doc.currency) { |
Neil Trini Lasrado | eaae58f | 2014-10-09 15:00:10 +0530 | [diff] [blame] | 424 | me.frm.set_value("currency", company_currency); |
| 425 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 426 | |
Neil Trini Lasrado | eaae58f | 2014-10-09 15:00:10 +0530 | [diff] [blame] | 427 | if (me.frm.doc.currency == company_currency) { |
| 428 | me.frm.set_value("conversion_rate", 1.0); |
| 429 | } |
| 430 | if (me.frm.doc.price_list_currency == company_currency) { |
| 431 | me.frm.set_value('plc_conversion_rate', 1.0); |
| 432 | } |
Rushabh Mehta | 5495bc5 | 2015-05-19 12:00:34 +0530 | [diff] [blame] | 433 | if (company_doc.default_letter_head) { |
Rushabh Mehta | c185734 | 2015-05-27 12:29:57 +0530 | [diff] [blame] | 434 | if(me.frm.fields_dict.letter_head) { |
| 435 | me.frm.set_value("letter_head", company_doc.default_letter_head); |
| 436 | } |
Rushabh Mehta | 5495bc5 | 2015-05-19 12:00:34 +0530 | [diff] [blame] | 437 | } |
Rohit Waghchaure | 585448b | 2016-12-30 15:41:55 +0530 | [diff] [blame] | 438 | if (company_doc.default_terms && me.frm.doc.doctype != "Purchase Invoice" && frappe.meta.has_field(me.frm.doc.doctype, "tc_name")) { |
Rushabh Mehta | 5495bc5 | 2015-05-19 12:00:34 +0530 | [diff] [blame] | 439 | me.frm.set_value("tc_name", company_doc.default_terms); |
| 440 | } |
Akhilesh Darjee | 1797cfe | 2013-10-11 13:34:10 +0530 | [diff] [blame] | 441 | |
rohitwaghchaure | 505661b | 2017-12-11 14:52:28 +0530 | [diff] [blame] | 442 | frappe.run_serially([ |
| 443 | () => me.frm.script_manager.trigger("currency"), |
| 444 | () => me.apply_default_taxes(), |
| 445 | () => me.apply_pricing_rule() |
| 446 | ]); |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 447 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 448 | } |
Rushabh Mehta | 8d1c7a2 | 2016-02-10 13:08:42 +0530 | [diff] [blame] | 449 | |
Nabin Hait | a731ad4 | 2016-02-04 17:21:28 +0530 | [diff] [blame] | 450 | var set_party_account = function(set_pricing) { |
| 451 | if (in_list(["Sales Invoice", "Purchase Invoice"], me.frm.doc.doctype)) { |
| 452 | if(me.frm.doc.doctype=="Sales Invoice") { |
| 453 | var party_type = "Customer"; |
| 454 | var party_account_field = 'debit_to'; |
| 455 | } else { |
| 456 | var party_type = "Supplier"; |
| 457 | var party_account_field = 'credit_to'; |
| 458 | } |
Anand Doshi | 39a2891 | 2016-02-15 11:42:18 +0530 | [diff] [blame] | 459 | |
Nabin Hait | ef86440 | 2016-02-10 14:47:25 +0530 | [diff] [blame] | 460 | var party = me.frm.doc[frappe.model.scrub(party_type)]; |
Faris Ansari | f7717b9 | 2018-02-08 11:09:54 +0530 | [diff] [blame] | 461 | if(party && me.frm.doc.company) { |
Rushabh Mehta | 8d1c7a2 | 2016-02-10 13:08:42 +0530 | [diff] [blame] | 462 | return frappe.call({ |
| 463 | method: "erpnext.accounts.party.get_party_account", |
| 464 | args: { |
| 465 | company: me.frm.doc.company, |
| 466 | party_type: party_type, |
Nabin Hait | ef86440 | 2016-02-10 14:47:25 +0530 | [diff] [blame] | 467 | party: party |
Rushabh Mehta | 8d1c7a2 | 2016-02-10 13:08:42 +0530 | [diff] [blame] | 468 | }, |
| 469 | callback: function(r) { |
| 470 | if(!r.exc && r.message) { |
| 471 | me.frm.set_value(party_account_field, r.message); |
| 472 | set_pricing(); |
| 473 | } |
Nabin Hait | a731ad4 | 2016-02-04 17:21:28 +0530 | [diff] [blame] | 474 | } |
Rushabh Mehta | 8d1c7a2 | 2016-02-10 13:08:42 +0530 | [diff] [blame] | 475 | }); |
Nabin Hait | ef86440 | 2016-02-10 14:47:25 +0530 | [diff] [blame] | 476 | } else { |
| 477 | set_pricing(); |
Rushabh Mehta | 8d1c7a2 | 2016-02-10 13:08:42 +0530 | [diff] [blame] | 478 | } |
Nabin Hait | a731ad4 | 2016-02-04 17:21:28 +0530 | [diff] [blame] | 479 | } else { |
| 480 | set_pricing(); |
| 481 | } |
Rushabh Mehta | 8d1c7a2 | 2016-02-10 13:08:42 +0530 | [diff] [blame] | 482 | |
Nabin Hait | a731ad4 | 2016-02-04 17:21:28 +0530 | [diff] [blame] | 483 | } |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 484 | |
Neil Trini Lasrado | eaae58f | 2014-10-09 15:00:10 +0530 | [diff] [blame] | 485 | if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date; |
| 486 | else var date = this.frm.doc.transaction_date; |
Rushabh Mehta | 5dfe20c | 2016-04-26 12:59:08 +0530 | [diff] [blame] | 487 | |
| 488 | if (frappe.meta.get_docfield(this.frm.doctype, "shipping_address") && |
Rohit Waghchaure | b2e7a1f | 2016-04-11 12:10:20 +0530 | [diff] [blame] | 489 | in_list(['Purchase Order', 'Purchase Receipt', 'Purchase Invoice'], this.frm.doctype)){ |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 490 | erpnext.utils.get_shipping_address(this.frm, function(){ |
| 491 | set_party_account(set_pricing); |
| 492 | }) |
| 493 | } else { |
Rohit Waghchaure | b2e7a1f | 2016-04-11 12:10:20 +0530 | [diff] [blame] | 494 | set_party_account(set_pricing); |
| 495 | } |
Rushabh Mehta | 45ca8a4 | 2015-04-28 16:02:09 +0530 | [diff] [blame] | 496 | |
| 497 | if(this.frm.doc.company) { |
| 498 | erpnext.last_selected_company = this.frm.doc.company; |
| 499 | } |
Neil Trini Lasrado | eaae58f | 2014-10-09 15:00:10 +0530 | [diff] [blame] | 500 | }, |
| 501 | |
| 502 | transaction_date: function() { |
Anand Doshi | 87da662 | 2015-10-19 14:59:32 +0530 | [diff] [blame] | 503 | if (this.frm.doc.transaction_date) { |
| 504 | this.frm.transaction_date = this.frm.doc.transaction_date; |
Nabin Hait | 288a18e | 2016-12-08 15:36:23 +0530 | [diff] [blame] | 505 | frappe.ui.form.trigger(this.frm.doc.doctype, "currency"); |
Anand Doshi | 87da662 | 2015-10-19 14:59:32 +0530 | [diff] [blame] | 506 | } |
Neil Trini Lasrado | 78fa695 | 2014-10-03 17:43:02 +0530 | [diff] [blame] | 507 | }, |
| 508 | |
| 509 | posting_date: function() { |
Nabin Hait | 40e92b6 | 2015-07-09 17:12:23 +0530 | [diff] [blame] | 510 | var me = this; |
| 511 | if (this.frm.doc.posting_date) { |
Anand Doshi | 87da662 | 2015-10-19 14:59:32 +0530 | [diff] [blame] | 512 | this.frm.posting_date = this.frm.doc.posting_date; |
| 513 | |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 514 | if ((this.frm.doc.doctype == "Sales Invoice" && this.frm.doc.customer) || |
Nabin Hait | 40e92b6 | 2015-07-09 17:12:23 +0530 | [diff] [blame] | 515 | (this.frm.doc.doctype == "Purchase Invoice" && this.frm.doc.supplier)) { |
| 516 | return frappe.call({ |
| 517 | method: "erpnext.accounts.party.get_due_date", |
| 518 | args: { |
| 519 | "posting_date": me.frm.doc.posting_date, |
| 520 | "party_type": me.frm.doc.doctype == "Sales Invoice" ? "Customer" : "Supplier", |
| 521 | "party": me.frm.doc.doctype == "Sales Invoice" ? me.frm.doc.customer : me.frm.doc.supplier, |
| 522 | "company": me.frm.doc.company |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 523 | }, |
Nabin Hait | 40e92b6 | 2015-07-09 17:12:23 +0530 | [diff] [blame] | 524 | callback: function(r, rt) { |
| 525 | if(r.message) { |
Nabin Hait | cfa9d1a | 2018-01-29 16:07:21 +0530 | [diff] [blame] | 526 | me.frm.doc.due_date = r.message; |
| 527 | refresh_field("due_date"); |
Nabin Hait | 87d7027 | 2016-12-08 14:43:11 +0530 | [diff] [blame] | 528 | frappe.ui.form.trigger(me.frm.doc.doctype, "currency"); |
tundebabzy | 650a1ee | 2018-01-02 07:32:30 +0100 | [diff] [blame] | 529 | me.recalculate_terms(); |
Nabin Hait | 40e92b6 | 2015-07-09 17:12:23 +0530 | [diff] [blame] | 530 | } |
Nabin Hait | 40e92b6 | 2015-07-09 17:12:23 +0530 | [diff] [blame] | 531 | } |
| 532 | }) |
Nabin Hait | 87d7027 | 2016-12-08 14:43:11 +0530 | [diff] [blame] | 533 | } else { |
| 534 | frappe.ui.form.trigger(me.frm.doc.doctype, "currency"); |
Nabin Hait | 40e92b6 | 2015-07-09 17:12:23 +0530 | [diff] [blame] | 535 | } |
| 536 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 537 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 538 | |
tundebabzy | da22167 | 2018-01-09 06:28:44 +0100 | [diff] [blame] | 539 | due_date: function() { |
| 540 | // due_date is to be changed, payment terms template and/or payment schedule must |
| 541 | // be removed as due_date is automatically changed based on payment terms |
rohitwaghchaure | 52beb77 | 2018-01-29 17:40:44 +0530 | [diff] [blame] | 542 | if (this.frm.doc.due_date && !this.frm.updating_party_details && !this.frm.doc.is_pos) { |
Saurabh | 3959aeb | 2018-01-23 15:40:29 +0530 | [diff] [blame] | 543 | if (this.frm.doc.payment_terms_template || |
| 544 | (this.frm.doc.payment_schedule && this.frm.doc.payment_schedule.length)) { |
tundebabzy | da22167 | 2018-01-09 06:28:44 +0100 | [diff] [blame] | 545 | var message1 = ""; |
| 546 | var message2 = ""; |
| 547 | var final_message = "Please clear the "; |
| 548 | |
| 549 | if (this.frm.doc.payment_terms_template) { |
| 550 | message1 = "selected Payment Terms Template"; |
| 551 | final_message = final_message + message1; |
| 552 | } |
| 553 | |
Nabin Hait | 2bfa180 | 2018-01-17 14:39:05 +0530 | [diff] [blame] | 554 | if ((this.frm.doc.payment_schedule || []).length) { |
tundebabzy | da22167 | 2018-01-09 06:28:44 +0100 | [diff] [blame] | 555 | message2 = "Payment Schedule Table"; |
| 556 | if (message1.length !== 0) message2 = " and " + message2; |
| 557 | final_message = final_message + message2; |
| 558 | } |
tundebabzy | da22167 | 2018-01-09 06:28:44 +0100 | [diff] [blame] | 559 | frappe.msgprint(final_message); |
| 560 | } |
Nabin Hait | cfa9d1a | 2018-01-29 16:07:21 +0530 | [diff] [blame] | 561 | } |
tundebabzy | da22167 | 2018-01-09 06:28:44 +0100 | [diff] [blame] | 562 | }, |
| 563 | |
tundebabzy | 650a1ee | 2018-01-02 07:32:30 +0100 | [diff] [blame] | 564 | recalculate_terms: function() { |
| 565 | const doc = this.frm.doc; |
| 566 | |
| 567 | if (doc.payment_terms_template) { |
| 568 | this.payment_terms_template(); |
| 569 | } else if (doc.payment_schedule) { |
| 570 | const me = this; |
tundebabzy | 650a1ee | 2018-01-02 07:32:30 +0100 | [diff] [blame] | 571 | doc.payment_schedule.forEach( |
| 572 | function(term) { |
| 573 | if (term.payment_term) { |
| 574 | me.payment_term(doc, term.doctype, term.name); |
| 575 | } else { |
| 576 | frappe.model.set_value( |
| 577 | term.doctype, term.name, 'due_date', |
| 578 | doc.posting_date || doc.transaction_date |
| 579 | ); |
| 580 | } |
| 581 | } |
| 582 | ); |
| 583 | } |
| 584 | }, |
| 585 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 586 | get_company_currency: function() { |
| 587 | return erpnext.get_currency(this.frm.doc.company); |
| 588 | }, |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 589 | |
Neil Trini Lasrado | 09a66c4 | 2015-07-07 16:41:37 +0530 | [diff] [blame] | 590 | contact_person: function() { |
| 591 | erpnext.utils.get_contact_details(this.frm); |
| 592 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 593 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 594 | currency: function() { |
Chude Osiegbu | 256ec17 | 2016-09-19 03:53:37 +0100 | [diff] [blame] | 595 | /* manqala 19/09/2016: let the translation date be whichever of the transaction_date or posting_date is available */ |
Nabin Hait | 288a18e | 2016-12-08 15:36:23 +0530 | [diff] [blame] | 596 | var transaction_date = this.frm.doc.transaction_date || this.frm.doc.posting_date; |
Chude Osiegbu | 256ec17 | 2016-09-19 03:53:37 +0100 | [diff] [blame] | 597 | /* end manqala */ |
Rushabh Mehta | 6b53792 | 2017-03-14 16:59:11 +0530 | [diff] [blame] | 598 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 599 | var me = this; |
| 600 | this.set_dynamic_labels(); |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 601 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 602 | var company_currency = this.get_company_currency(); |
Nabin Hait | 69cdf59 | 2015-05-02 18:46:10 +0530 | [diff] [blame] | 603 | // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc |
Rushabh Mehta | 76b1341 | 2016-07-18 14:30:18 +0530 | [diff] [blame] | 604 | if(this.frm.doc.currency && this.frm.doc.currency !== company_currency |
Nabin Hait | 3950507 | 2016-07-07 11:11:32 +0530 | [diff] [blame] | 605 | && !this.frm.doc.ignore_pricing_rule) { |
Nabin Hait | 288a18e | 2016-12-08 15:36:23 +0530 | [diff] [blame] | 606 | this.get_exchange_rate(transaction_date, this.frm.doc.currency, company_currency, |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 607 | function(exchange_rate) { |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 608 | me.frm.set_value("conversion_rate", exchange_rate); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 609 | }); |
| 610 | } else { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 611 | this.conversion_rate(); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 612 | } |
| 613 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 614 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 615 | conversion_rate: function() { |
tundebabzy | ab5b030 | 2017-09-21 10:20:39 +0100 | [diff] [blame] | 616 | const me = this.frm; |
Anand Doshi | 535d833 | 2013-07-19 13:51:07 +0530 | [diff] [blame] | 617 | if(this.frm.doc.currency === this.get_company_currency()) { |
| 618 | this.frm.set_value("conversion_rate", 1.0); |
Akhilesh Darjee | acf65a7 | 2013-10-17 13:04:26 +0530 | [diff] [blame] | 619 | } |
| 620 | if(this.frm.doc.currency === this.frm.doc.price_list_currency && |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 621 | this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 622 | this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 623 | } |
Rushabh Mehta | 4a3c805 | 2015-05-19 11:10:12 +0530 | [diff] [blame] | 624 | |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 625 | if(flt(this.frm.doc.conversion_rate)>0.0) { |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 626 | if(this.frm.doc.ignore_pricing_rule) { |
| 627 | this.calculate_taxes_and_totals(); |
Anand Doshi | 51f722d | 2014-07-04 15:44:26 +0530 | [diff] [blame] | 628 | } else if (!this.in_apply_price_list){ |
Nabin Hait | a9c9b69 | 2017-08-31 19:40:09 +0530 | [diff] [blame] | 629 | this.set_actual_charges_based_on_currency(); |
Anand Doshi | 51f722d | 2014-07-04 15:44:26 +0530 | [diff] [blame] | 630 | this.apply_price_list(); |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 631 | } |
| 632 | |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 633 | } |
tundebabzy | ab5b030 | 2017-09-21 10:20:39 +0100 | [diff] [blame] | 634 | // Make read only if Accounts Settings doesn't allow stale rates |
tundebabzy | bc7c387 | 2017-11-28 18:10:05 +0100 | [diff] [blame] | 635 | this.frm.set_df_property("conversion_rate", "read_only", erpnext.stale_rate_allowed() ? 0 : 1); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 636 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 637 | |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 638 | shipping_rule: function() { |
| 639 | var me = this; |
| 640 | if(this.frm.doc.shipping_rule) { |
| 641 | return this.frm.call({ |
| 642 | doc: this.frm.doc, |
| 643 | method: "apply_shipping_rule", |
| 644 | callback: function(r) { |
| 645 | if(!r.exc) { |
| 646 | me.calculate_taxes_and_totals(); |
| 647 | } |
| 648 | } |
| 649 | }).fail(() => this.frm.set_value('shipping_rule', '')); |
| 650 | } |
Shreya | 39adc8f | 2018-01-22 13:08:05 +0530 | [diff] [blame] | 651 | else { |
| 652 | me.calculate_taxes_and_totals(); |
| 653 | } |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 654 | }, |
| 655 | |
Nabin Hait | a9c9b69 | 2017-08-31 19:40:09 +0530 | [diff] [blame] | 656 | set_actual_charges_based_on_currency: function() { |
| 657 | var me = this; |
| 658 | $.each(this.frm.doc.taxes || [], function(i, d) { |
| 659 | if(d.charge_type == "Actual") { |
| 660 | frappe.model.set_value(d.doctype, d.name, "tax_amount", |
| 661 | flt(d.tax_amount) / flt(me.frm.doc.conversion_rate)); |
| 662 | } |
| 663 | }); |
| 664 | }, |
| 665 | |
Nabin Hait | 288a18e | 2016-12-08 15:36:23 +0530 | [diff] [blame] | 666 | get_exchange_rate: function(transaction_date, from_currency, to_currency, callback) { |
Nabin Hait | 17179ee | 2017-05-06 13:23:12 +0530 | [diff] [blame] | 667 | if (!transaction_date || !from_currency || !to_currency) return; |
Nabin Hait | bdfb070 | 2015-10-28 15:38:08 +0530 | [diff] [blame] | 668 | return frappe.call({ |
Rushabh Mehta | 66fa1ff | 2015-05-07 12:25:33 +0530 | [diff] [blame] | 669 | method: "erpnext.setup.utils.get_exchange_rate", |
| 670 | args: { |
Nabin Hait | 288a18e | 2016-12-08 15:36:23 +0530 | [diff] [blame] | 671 | transaction_date: transaction_date, |
Rushabh Mehta | 66fa1ff | 2015-05-07 12:25:33 +0530 | [diff] [blame] | 672 | from_currency: from_currency, |
| 673 | to_currency: to_currency |
| 674 | }, |
| 675 | callback: function(r) { |
| 676 | callback(flt(r.message)); |
| 677 | } |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 678 | }); |
| 679 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 680 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 681 | price_list_currency: function() { |
Akhilesh Darjee | db59ffb | 2013-09-11 13:05:24 +0530 | [diff] [blame] | 682 | var me=this; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 683 | this.set_dynamic_labels(); |
Nabin Hait | ec361ea | 2015-05-11 18:14:45 +0530 | [diff] [blame] | 684 | |
| 685 | var company_currency = this.get_company_currency(); |
| 686 | // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc |
| 687 | if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.ignore_pricing_rule) { |
Chude Osiegbu | fbf27b5 | 2016-09-07 03:06:08 +0100 | [diff] [blame] | 688 | this.get_exchange_rate(this.frm.doc.posting_date, this.frm.doc.price_list_currency, company_currency, |
Nabin Hait | ec361ea | 2015-05-11 18:14:45 +0530 | [diff] [blame] | 689 | function(exchange_rate) { |
| 690 | me.frm.set_value("plc_conversion_rate", exchange_rate); |
| 691 | }); |
| 692 | } else { |
| 693 | this.plc_conversion_rate(); |
| 694 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 695 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 696 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 697 | plc_conversion_rate: function() { |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 698 | if(this.frm.doc.price_list_currency === this.get_company_currency()) { |
| 699 | this.frm.set_value("plc_conversion_rate", 1.0); |
Rushabh Mehta | a208c56 | 2015-08-03 13:18:54 +0530 | [diff] [blame] | 700 | } else if(this.frm.doc.price_list_currency === this.frm.doc.currency |
Nabin Hait | 1d21842 | 2015-07-17 15:19:02 +0530 | [diff] [blame] | 701 | && this.frm.doc.plc_conversion_rate && cint(this.frm.doc.plc_conversion_rate) != 1 && |
Nabin Hait | ec361ea | 2015-05-11 18:14:45 +0530 | [diff] [blame] | 702 | cint(this.frm.doc.plc_conversion_rate) != cint(this.frm.doc.conversion_rate)) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 703 | this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate); |
Akhilesh Darjee | 564c621 | 2013-10-17 11:31:11 +0530 | [diff] [blame] | 704 | } |
Rushabh Mehta | 4a3c805 | 2015-05-19 11:10:12 +0530 | [diff] [blame] | 705 | |
Nabin Hait | ec361ea | 2015-05-11 18:14:45 +0530 | [diff] [blame] | 706 | if(!this.in_apply_price_list) { |
| 707 | this.apply_price_list(); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 708 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 709 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 710 | |
Kanchan Chauhan | 5a980ac | 2017-02-10 14:27:11 +0530 | [diff] [blame] | 711 | uom: function(doc, cdt, cdn) { |
| 712 | var me = this; |
| 713 | var item = frappe.get_doc(cdt, cdn); |
| 714 | if(item.item_code && item.uom) { |
| 715 | return this.frm.call({ |
| 716 | method: "erpnext.stock.get_item_details.get_conversion_factor", |
| 717 | child: item, |
| 718 | args: { |
| 719 | item_code: item.item_code, |
| 720 | uom: item.uom |
| 721 | }, |
| 722 | callback: function(r) { |
| 723 | if(!r.exc) { |
| 724 | me.conversion_factor(me.frm.doc, cdt, cdn); |
| 725 | } |
| 726 | } |
| 727 | }); |
| 728 | } |
| 729 | }, |
| 730 | |
Nabin Hait | 3257aee | 2017-05-06 12:47:14 +0530 | [diff] [blame] | 731 | conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) { |
Kanchan Chauhan | 5a980ac | 2017-02-10 14:27:11 +0530 | [diff] [blame] | 732 | if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) { |
| 733 | var item = frappe.get_doc(cdt, cdn); |
| 734 | frappe.model.round_floats_in(item, ["qty", "conversion_factor"]); |
| 735 | item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item)); |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 736 | item.total_weight = flt(item.stock_qty * item.weight_per_unit); |
Kanchan Chauhan | 5a980ac | 2017-02-10 14:27:11 +0530 | [diff] [blame] | 737 | refresh_field("stock_qty", item.name, item.parentfield); |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 738 | refresh_field("total_weight", item.name, item.parentfield); |
mbauskar | 287fe81 | 2017-04-10 19:15:57 +0530 | [diff] [blame] | 739 | this.toggle_conversion_factor(item); |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 740 | this.calculate_net_weight(); |
rohitwaghchaure | e8ccc0e | 2017-11-21 16:17:22 +0530 | [diff] [blame] | 741 | if (!dont_fetch_price_list_rate && |
| 742 | frappe.meta.has_field(doc.doctype, "price_list_currency")) { |
| 743 | this.apply_price_list(item, true); |
| 744 | } |
Kanchan Chauhan | 5a980ac | 2017-02-10 14:27:11 +0530 | [diff] [blame] | 745 | } |
| 746 | }, |
| 747 | |
mbauskar | 287fe81 | 2017-04-10 19:15:57 +0530 | [diff] [blame] | 748 | toggle_conversion_factor: function(item) { |
| 749 | // toggle read only property for conversion factor field if the uom and stock uom are same |
Rushabh Mehta | 3631102 | 2017-06-20 09:30:53 +0530 | [diff] [blame] | 750 | if(this.frm.get_field('items').grid.fields_map.conversion_factor) { |
| 751 | this.frm.fields_dict.items.grid.toggle_enable("conversion_factor", |
| 752 | (item.uom != item.stock_uom)? true: false); |
| 753 | } |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 754 | |
mbauskar | 287fe81 | 2017-04-10 19:15:57 +0530 | [diff] [blame] | 755 | }, |
| 756 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 757 | qty: function(doc, cdt, cdn) { |
Nabin Hait | 3257aee | 2017-05-06 12:47:14 +0530 | [diff] [blame] | 758 | this.conversion_factor(doc, cdt, cdn, true); |
| 759 | this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true); |
Vishal Dhayagude | d42242d | 2017-11-29 16:09:59 +0530 | [diff] [blame] | 760 | }, |
| 761 | |
Vishal Dhayagude | d377018 | 2017-12-14 18:06:02 +0530 | [diff] [blame] | 762 | calculate_net_weight: function(){ |
| 763 | /* Calculate Total Net Weight then further applied shipping rule to calculate shipping charges.*/ |
| 764 | var me = this; |
| 765 | this.frm.doc.total_net_weight= 0.0; |
| 766 | |
| 767 | $.each(this.frm.doc["items"] || [], function(i, item) { |
| 768 | me.frm.doc.total_net_weight += flt(item.total_weight); |
| 769 | }); |
| 770 | refresh_field("total_net_weight"); |
| 771 | this.shipping_rule(); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 772 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 773 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 774 | set_dynamic_labels: function() { |
| 775 | // What TODO? should we make price list system non-mandatory? |
| 776 | this.frm.toggle_reqd("plc_conversion_rate", |
| 777 | !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency)); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 778 | |
Rushabh Mehta | bb8c6de | 2016-03-29 17:52:22 +0530 | [diff] [blame] | 779 | if(this.frm.doc_currency!==this.frm.doc.currency) { |
| 780 | // reset names only when the currency is different |
| 781 | |
| 782 | var company_currency = this.get_company_currency(); |
| 783 | this.change_form_labels(company_currency); |
| 784 | this.change_grid_labels(company_currency); |
| 785 | this.frm.refresh_fields(); |
| 786 | this.frm.doc_currency = this.frm.doc.currency; |
| 787 | } |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 788 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 789 | |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 790 | change_form_labels: function(company_currency) { |
| 791 | var me = this; |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 792 | |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 793 | this.frm.set_currency_labels(["base_total", "base_net_total", "base_total_taxes_and_charges", |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 794 | "base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words", |
| 795 | "base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay", |
Rushabh Mehta | 6b53792 | 2017-03-14 16:59:11 +0530 | [diff] [blame] | 796 | "base_paid_amount", "base_write_off_amount", "base_change_amount", "base_operating_cost", |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 797 | "base_raw_material_cost", "base_total_cost", "base_scrap_material_cost", |
| 798 | "base_rounding_adjustment"], company_currency); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 799 | |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 800 | this.frm.set_currency_labels(["total", "net_total", "total_taxes_and_charges", "discount_amount", |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 801 | "grand_total", "taxes_and_charges_added", "taxes_and_charges_deducted", |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 802 | "rounded_total", "in_words", "paid_amount", "write_off_amount", "operating_cost", |
| 803 | "scrap_material_cost", "rounding_adjustment", "raw_material_cost", |
| 804 | "total_cost"], this.frm.doc.currency); |
Anand Doshi | 87da662 | 2015-10-19 14:59:32 +0530 | [diff] [blame] | 805 | |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 806 | this.frm.set_currency_labels(["outstanding_amount", "total_advance"], |
| 807 | this.frm.doc.party_account_currency); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 808 | |
| 809 | cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 810 | + " = [?] " + company_currency); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 811 | |
| 812 | if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) { |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 813 | cur_frm.set_df_property("plc_conversion_rate", "description", "1 " |
| 814 | + this.frm.doc.price_list_currency + " = [?] " + company_currency); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // toggle fields |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 818 | this.frm.toggle_display(["conversion_rate", "base_total", "base_net_total", |
| 819 | "base_total_taxes_and_charges", "base_taxes_and_charges_added", "base_taxes_and_charges_deducted", |
Nabin Hait | 4ffd7f3 | 2015-08-27 12:28:36 +0530 | [diff] [blame] | 820 | "base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount", |
Nabin Hait | 2e4de83 | 2017-09-19 14:53:16 +0530 | [diff] [blame] | 821 | "base_paid_amount", "base_write_off_amount", "base_operating_cost", "base_raw_material_cost", |
| 822 | "base_total_cost", "base_scrap_material_cost", "base_rounding_adjustment"], |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 823 | this.frm.doc.currency != company_currency); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 824 | |
| 825 | this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"], |
| 826 | this.frm.doc.price_list_currency != company_currency); |
| 827 | |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 828 | var show = cint(cur_frm.doc.discount_amount) || |
Nabin Hait | 903c42a | 2015-02-24 15:24:49 +0530 | [diff] [blame] | 829 | ((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length); |
| 830 | |
| 831 | if(frappe.meta.get_docfield(cur_frm.doctype, "net_total")) |
| 832 | cur_frm.toggle_display("net_total", show); |
| 833 | |
| 834 | if(frappe.meta.get_docfield(cur_frm.doctype, "base_net_total")) |
| 835 | cur_frm.toggle_display("base_net_total", (show && (me.frm.doc.currency != company_currency))); |
| 836 | |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 837 | }, |
| 838 | |
| 839 | change_grid_labels: function(company_currency) { |
| 840 | var me = this; |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 841 | |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 842 | this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"], |
| 843 | company_currency, "items"); |
| 844 | |
| 845 | this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount"], |
| 846 | this.frm.doc.currency, "items"); |
| 847 | |
| 848 | if(this.frm.fields_dict["operations"]) { |
| 849 | this.frm.set_currency_labels(["operating_cost", "hour_rate"], this.frm.doc.currency, "operations"); |
| 850 | this.frm.set_currency_labels(["base_operating_cost", "base_hour_rate"], company_currency, "operations"); |
| 851 | |
| 852 | var item_grid = this.frm.fields_dict["operations"].grid; |
| 853 | $.each(["base_operating_cost", "base_hour_rate"], function(i, fname) { |
| 854 | if(frappe.meta.get_docfield(item_grid.doctype, fname)) |
| 855 | item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 856 | }); |
| 857 | } |
| 858 | |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 859 | if(this.frm.fields_dict["scrap_items"]) { |
| 860 | this.frm.set_currency_labels(["rate", "amount"], this.frm.doc.currency, "scrap_items"); |
| 861 | this.frm.set_currency_labels(["base_rate", "base_amount"], company_currency, "scrap_items"); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 862 | |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 863 | var item_grid = this.frm.fields_dict["scrap_items"].grid; |
| 864 | $.each(["base_rate", "base_amount"], function(i, fname) { |
| 865 | if(frappe.meta.get_docfield(item_grid.doctype, fname)) |
| 866 | item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency); |
| 867 | }); |
| 868 | } |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 869 | |
| 870 | if(this.frm.fields_dict["taxes"]) { |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 871 | this.frm.set_currency_labels(["tax_amount", "total", "tax_amount_after_discount"], this.frm.doc.currency, "taxes"); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 872 | |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 873 | this.frm.set_currency_labels(["base_tax_amount", "base_total", "base_tax_amount_after_discount"], company_currency, "taxes"); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | if(this.frm.fields_dict["advances"]) { |
Rohit Waghchaure | b1b3288 | 2016-10-21 19:31:54 +0530 | [diff] [blame] | 877 | this.frm.set_currency_labels(["advance_amount", "allocated_amount"], |
Nabin Hait | aa01590 | 2015-10-16 13:08:33 +0530 | [diff] [blame] | 878 | this.frm.doc.party_account_currency, "advances"); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | // toggle columns |
| 882 | var item_grid = this.frm.fields_dict["items"].grid; |
| 883 | $.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) { |
| 884 | if(frappe.meta.get_docfield(item_grid.doctype, fname)) |
| 885 | item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency); |
| 886 | }); |
| 887 | |
| 888 | var show = (cint(cur_frm.doc.discount_amount)) || |
| 889 | ((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length); |
| 890 | |
| 891 | $.each(["net_rate", "net_amount"], function(i, fname) { |
| 892 | if(frappe.meta.get_docfield(item_grid.doctype, fname)) |
| 893 | item_grid.set_column_disp(fname, show); |
| 894 | }); |
| 895 | |
| 896 | $.each(["base_net_rate", "base_net_amount"], function(i, fname) { |
| 897 | if(frappe.meta.get_docfield(item_grid.doctype, fname)) |
| 898 | item_grid.set_column_disp(fname, (show && (me.frm.doc.currency != company_currency))); |
| 899 | }); |
| 900 | |
| 901 | // set labels |
| 902 | var $wrapper = $(this.frm.wrapper); |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 903 | }, |
| 904 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 905 | recalculate: function() { |
| 906 | this.calculate_taxes_and_totals(); |
| 907 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 908 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 909 | recalculate_values: function() { |
| 910 | this.calculate_taxes_and_totals(); |
| 911 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 912 | |
Anand Doshi | d0b0072 | 2013-05-28 18:54:48 +0530 | [diff] [blame] | 913 | calculate_charges: function() { |
| 914 | this.calculate_taxes_and_totals(); |
| 915 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 916 | |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 917 | ignore_pricing_rule: function() { |
Nabin Hait | 8c9fb76 | 2017-04-28 14:23:03 +0530 | [diff] [blame] | 918 | if(this.frm.doc.ignore_pricing_rule) { |
| 919 | var me = this; |
| 920 | var item_list = []; |
Rushabh Mehta | 3631102 | 2017-06-20 09:30:53 +0530 | [diff] [blame] | 921 | |
Nabin Hait | 8c9fb76 | 2017-04-28 14:23:03 +0530 | [diff] [blame] | 922 | $.each(this.frm.doc["items"] || [], function(i, d) { |
| 923 | if (d.item_code) { |
| 924 | item_list.push({ |
| 925 | "doctype": d.doctype, |
| 926 | "name": d.name, |
| 927 | "pricing_rule": d.pricing_rule |
| 928 | }) |
| 929 | } |
| 930 | }); |
| 931 | return this.frm.call({ |
| 932 | method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.remove_pricing_rules", |
| 933 | args: { item_list: item_list }, |
| 934 | callback: function(r) { |
| 935 | if (!r.exc && r.message) { |
| 936 | me._set_values_for_item_list(r.message); |
| 937 | me.calculate_taxes_and_totals(); |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 938 | if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on"); |
Nabin Hait | 8c9fb76 | 2017-04-28 14:23:03 +0530 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | }); |
| 942 | } else { |
| 943 | this.apply_pricing_rule(); |
| 944 | } |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 945 | }, |
| 946 | |
| 947 | apply_pricing_rule: function(item, calculate_taxes_and_totals) { |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 948 | var me = this; |
Anand Doshi | 70f57eb | 2015-11-27 14:37:40 +0530 | [diff] [blame] | 949 | var args = this._get_args(item); |
Rushabh Mehta | b46069d | 2016-01-15 16:59:26 +0530 | [diff] [blame] | 950 | if (!(args.items && args.items.length)) { |
Anand Doshi | 70f57eb | 2015-11-27 14:37:40 +0530 | [diff] [blame] | 951 | if(calculate_taxes_and_totals) me.calculate_taxes_and_totals(); |
| 952 | return; |
| 953 | } |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 954 | return this.frm.call({ |
| 955 | method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule", |
Anand Doshi | 70f57eb | 2015-11-27 14:37:40 +0530 | [diff] [blame] | 956 | args: { args: args }, |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 957 | callback: function(r) { |
Anand Doshi | f214bfc | 2014-07-16 17:52:08 +0530 | [diff] [blame] | 958 | if (!r.exc && r.message) { |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 959 | me._set_values_for_item_list(r.message); |
Saurabh | 2d7af63 | 2016-02-26 11:09:20 +0530 | [diff] [blame] | 960 | if(item) me.set_gross_profit(item); |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 961 | if(calculate_taxes_and_totals) me.calculate_taxes_and_totals(); |
Rohit Waghchaure | deaee7c | 2016-09-22 14:02:53 +0530 | [diff] [blame] | 962 | if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on") |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | }); |
| 966 | }, |
| 967 | |
| 968 | _get_args: function(item) { |
| 969 | var me = this; |
| 970 | return { |
Rushabh Mehta | b46069d | 2016-01-15 16:59:26 +0530 | [diff] [blame] | 971 | "items": this._get_item_list(item), |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 972 | "customer": me.frm.doc.customer, |
| 973 | "customer_group": me.frm.doc.customer_group, |
| 974 | "territory": me.frm.doc.territory, |
| 975 | "supplier": me.frm.doc.supplier, |
| 976 | "supplier_type": me.frm.doc.supplier_type, |
| 977 | "currency": me.frm.doc.currency, |
| 978 | "conversion_rate": me.frm.doc.conversion_rate, |
| 979 | "price_list": me.frm.doc.selling_price_list || me.frm.doc.buying_price_list, |
Nabin Hait | dd82bf2 | 2015-05-11 16:49:17 +0530 | [diff] [blame] | 980 | "price_list_currency": me.frm.doc.price_list_currency, |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 981 | "plc_conversion_rate": me.frm.doc.plc_conversion_rate, |
| 982 | "company": me.frm.doc.company, |
| 983 | "transaction_date": me.frm.doc.transaction_date || me.frm.doc.posting_date, |
| 984 | "campaign": me.frm.doc.campaign, |
| 985 | "sales_partner": me.frm.doc.sales_partner, |
| 986 | "ignore_pricing_rule": me.frm.doc.ignore_pricing_rule, |
Rushabh Mehta | b46069d | 2016-01-15 16:59:26 +0530 | [diff] [blame] | 987 | "doctype": me.frm.doc.doctype, |
Rohit Waghchaure | 5ecbaa4 | 2017-03-28 12:09:07 +0530 | [diff] [blame] | 988 | "name": me.frm.doc.name, |
Rohit Waghchaure | dc981dc | 2017-04-03 14:17:08 +0530 | [diff] [blame] | 989 | "is_return": cint(me.frm.doc.is_return), |
| 990 | "update_stock": in_list(['Sales Invoice', 'Purchase Invoice'], me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0, |
rohitwaghchaure | c037dc7 | 2017-11-28 16:11:15 +0530 | [diff] [blame] | 991 | "conversion_factor": me.frm.doc.conversion_factor, |
| 992 | "pos_profile": me.frm.doc.doctype == 'Sales Invoice' ? me.frm.doc.pos_profile : '' |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 993 | }; |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 994 | }, |
| 995 | |
| 996 | _get_item_list: function(item) { |
| 997 | var item_list = []; |
| 998 | var append_item = function(d) { |
Anand Doshi | 39edcbc | 2014-07-28 16:00:19 +0530 | [diff] [blame] | 999 | if (d.item_code) { |
| 1000 | item_list.push({ |
| 1001 | "doctype": d.doctype, |
| 1002 | "name": d.name, |
| 1003 | "item_code": d.item_code, |
| 1004 | "item_group": d.item_group, |
| 1005 | "brand": d.brand, |
Anand Doshi | 39a2891 | 2016-02-15 11:42:18 +0530 | [diff] [blame] | 1006 | "qty": d.qty, |
| 1007 | "parenttype": d.parenttype, |
Rohit Waghchaure | 43b5080 | 2016-10-24 14:04:46 +0530 | [diff] [blame] | 1008 | "parent": d.parent, |
Kanchan Chauhan | af0d637 | 2016-11-13 21:19:09 +0530 | [diff] [blame] | 1009 | "pricing_rule": d.pricing_rule, |
| 1010 | "warehouse": d.warehouse, |
Rohit Waghchaure | dc981dc | 2017-04-03 14:17:08 +0530 | [diff] [blame] | 1011 | "serial_no": d.serial_no, |
Rohit Waghchaure | b12f210 | 2017-07-12 13:33:59 +0530 | [diff] [blame] | 1012 | "discount_percentage": d.discount_percentage || 0.0, |
mbauskar | 287fe81 | 2017-04-10 19:15:57 +0530 | [diff] [blame] | 1013 | "conversion_factor": d.conversion_factor || 1.0 |
Anand Doshi | 39edcbc | 2014-07-28 16:00:19 +0530 | [diff] [blame] | 1014 | }); |
mbauskar | c79415e | 2016-01-18 16:32:24 +0530 | [diff] [blame] | 1015 | |
| 1016 | // if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list |
mbauskar | a52472c | 2016-03-05 15:10:25 +0530 | [diff] [blame] | 1017 | if (in_list(["Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item"]), d.doctype){ |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 1018 | item_list[0]["margin_type"] = d.margin_type; |
| 1019 | item_list[0]["margin_rate_or_amount"] = d.margin_rate_or_amount; |
Rushabh Mehta | bb8c6de | 2016-03-29 17:52:22 +0530 | [diff] [blame] | 1020 | } |
Anand Doshi | 39edcbc | 2014-07-28 16:00:19 +0530 | [diff] [blame] | 1021 | } |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 1022 | }; |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 1023 | |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 1024 | if (item) { |
| 1025 | append_item(item); |
Nabin Hait | c1367d9 | 2014-05-30 11:43:00 +0530 | [diff] [blame] | 1026 | } else { |
Nabin Hait | 9633934 | 2015-01-21 17:22:11 +0530 | [diff] [blame] | 1027 | $.each(this.frm.doc["items"] || [], function(i, d) { |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 1028 | append_item(d); |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 1029 | }); |
| 1030 | } |
Nabin Hait | 444f956 | 2014-06-20 15:59:49 +0530 | [diff] [blame] | 1031 | return item_list; |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 1032 | }, |
| 1033 | |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1034 | _set_values_for_item_list: function(children) { |
Nabin Hait | 49a2729 | 2014-12-17 11:21:32 +0530 | [diff] [blame] | 1035 | var me = this; |
Nabin Hait | 7d8fa80 | 2014-12-30 15:35:45 +0530 | [diff] [blame] | 1036 | var price_list_rate_changed = false; |
Anand Doshi | dea3fb0 | 2015-02-05 15:05:58 +0530 | [diff] [blame] | 1037 | for(var i=0, l=children.length; i<l; i++) { |
| 1038 | var d = children[i]; |
Nabin Hait | 49a2729 | 2014-12-17 11:21:32 +0530 | [diff] [blame] | 1039 | var existing_pricing_rule = frappe.model.get_value(d.doctype, d.name, "pricing_rule"); |
Anand Doshi | dea3fb0 | 2015-02-05 15:05:58 +0530 | [diff] [blame] | 1040 | for(var k in d) { |
| 1041 | var v = d[k]; |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1042 | if (["doctype", "name"].indexOf(k)===-1) { |
Nabin Hait | 7d8fa80 | 2014-12-30 15:35:45 +0530 | [diff] [blame] | 1043 | if(k=="price_list_rate") { |
| 1044 | if(flt(v) != flt(d.price_list_rate)) price_list_rate_changed = true; |
| 1045 | } |
mbauskar | 287fe81 | 2017-04-10 19:15:57 +0530 | [diff] [blame] | 1046 | frappe.model.set_value(d.doctype, d.name, k, v); |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1047 | } |
Anand Doshi | dea3fb0 | 2015-02-05 15:05:58 +0530 | [diff] [blame] | 1048 | } |
| 1049 | |
Nabin Hait | 49a2729 | 2014-12-17 11:21:32 +0530 | [diff] [blame] | 1050 | // if pricing rule set as blank from an existing value, apply price_list |
Nabin Hait | cfe3c54 | 2014-12-22 10:42:48 +0530 | [diff] [blame] | 1051 | if(!me.frm.doc.ignore_pricing_rule && existing_pricing_rule && !d.pricing_rule) { |
Nabin Hait | 49a2729 | 2014-12-17 11:21:32 +0530 | [diff] [blame] | 1052 | me.apply_price_list(frappe.get_doc(d.doctype, d.name)); |
| 1053 | } |
Anand Doshi | dea3fb0 | 2015-02-05 15:05:58 +0530 | [diff] [blame] | 1054 | } |
Nabin Hait | 7d8fa80 | 2014-12-30 15:35:45 +0530 | [diff] [blame] | 1055 | |
Anand Doshi | dea3fb0 | 2015-02-05 15:05:58 +0530 | [diff] [blame] | 1056 | if(!price_list_rate_changed) me.calculate_taxes_and_totals(); |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1057 | }, |
| 1058 | |
Nabin Hait | 49a2729 | 2014-12-17 11:21:32 +0530 | [diff] [blame] | 1059 | apply_price_list: function(item) { |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1060 | var me = this; |
Rushabh Mehta | 052bd62 | 2015-01-30 16:57:24 +0530 | [diff] [blame] | 1061 | var args = this._get_args(item); |
Rushabh Mehta | b46069d | 2016-01-15 16:59:26 +0530 | [diff] [blame] | 1062 | if (!((args.items && args.items.length) || args.price_list)) { |
Anand Doshi | 70f57eb | 2015-11-27 14:37:40 +0530 | [diff] [blame] | 1063 | return; |
| 1064 | } |
Nabin Hait | 37b047d | 2015-02-23 16:01:33 +0530 | [diff] [blame] | 1065 | |
Rushabh Mehta | 98aa581 | 2017-11-14 09:32:32 +0530 | [diff] [blame] | 1066 | if (me.in_apply_price_list == true) return; |
| 1067 | |
| 1068 | me.in_apply_price_list = true; |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1069 | return this.frm.call({ |
| 1070 | method: "erpnext.stock.get_item_details.apply_price_list", |
Rushabh Mehta | 052bd62 | 2015-01-30 16:57:24 +0530 | [diff] [blame] | 1071 | args: { args: args }, |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1072 | callback: function(r) { |
| 1073 | if (!r.exc) { |
Rushabh Mehta | 98aa581 | 2017-11-14 09:32:32 +0530 | [diff] [blame] | 1074 | frappe.run_serially([ |
| 1075 | () => me.frm.set_value("price_list_currency", r.message.parent.price_list_currency), |
| 1076 | () => me.frm.set_value("plc_conversion_rate", r.message.parent.plc_conversion_rate), |
| 1077 | () => { |
| 1078 | if(args.items.length) { |
| 1079 | me._set_values_for_item_list(r.message.children); |
| 1080 | } |
| 1081 | }, |
| 1082 | () => { me.in_apply_price_list = false; } |
| 1083 | ]); |
Nabin Hait | 37b047d | 2015-02-23 16:01:33 +0530 | [diff] [blame] | 1084 | |
Rushabh Mehta | 98aa581 | 2017-11-14 09:32:32 +0530 | [diff] [blame] | 1085 | } else { |
| 1086 | me.in_apply_price_list = false; |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | }); |
| 1090 | }, |
| 1091 | |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 1092 | validate_company_and_party: function() { |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 1093 | var me = this; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 1094 | var valid = true; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 1095 | |
Nabin Hait | 0f23106 | 2014-02-20 11:27:47 +0530 | [diff] [blame] | 1096 | $.each(["company", "customer"], function(i, fieldname) { |
Nabin Hait | ae07f22 | 2017-06-02 13:57:08 +0530 | [diff] [blame] | 1097 | if(frappe.meta.has_field(me.frm.doc.doctype, fieldname) && me.frm.doc.doctype != "Purchase Order") { |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 1098 | if (!me.frm.doc[fieldname]) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1099 | frappe.msgprint(__("Please specify") + ": " + |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 1100 | frappe.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) + |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 1101 | ". " + __("It is needed to fetch Item Details.")); |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1102 | valid = false; |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 1103 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 1104 | } |
| 1105 | }); |
| 1106 | return valid; |
| 1107 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 1108 | |
Anand Doshi | bf3e54a | 2013-06-05 14:11:32 +0530 | [diff] [blame] | 1109 | get_terms: function() { |
| 1110 | var me = this; |
Makarand Bauskar | 157c334 | 2017-05-26 21:32:33 +0530 | [diff] [blame] | 1111 | |
| 1112 | erpnext.utils.get_terms(this.frm.doc.tc_name, this.frm.doc, function(r) { |
| 1113 | if(!r.exc) { |
| 1114 | me.frm.set_value("terms", r.message); |
| 1115 | } |
| 1116 | }); |
Anand Doshi | bf3e54a | 2013-06-05 14:11:32 +0530 | [diff] [blame] | 1117 | }, |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 1118 | |
| 1119 | taxes_and_charges: function() { |
| 1120 | var me = this; |
| 1121 | if(this.frm.doc.taxes_and_charges) { |
| 1122 | return this.frm.call({ |
Nabin Hait | 6b03914 | 2014-05-02 15:45:10 +0530 | [diff] [blame] | 1123 | method: "erpnext.controllers.accounts_controller.get_taxes_and_charges", |
| 1124 | args: { |
Nabin Hait | 03f3a8a | 2014-05-13 16:38:31 +0530 | [diff] [blame] | 1125 | "master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges", |
| 1126 | this.frm.doc.name).options, |
Nabin Hait | 6b03914 | 2014-05-02 15:45:10 +0530 | [diff] [blame] | 1127 | "master_name": this.frm.doc.taxes_and_charges, |
Nabin Hait | 6b03914 | 2014-05-02 15:45:10 +0530 | [diff] [blame] | 1128 | }, |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 1129 | callback: function(r) { |
| 1130 | if(!r.exc) { |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 1131 | me.frm.set_value("taxes", r.message); |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 1132 | me.calculate_taxes_and_totals(); |
| 1133 | } |
| 1134 | } |
| 1135 | }); |
Nabin Hait | bc83b9c | 2014-05-02 17:03:18 +0530 | [diff] [blame] | 1136 | } |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 1137 | }, |
| 1138 | |
Anand Doshi | 1394509 | 2014-09-21 19:45:49 +0530 | [diff] [blame] | 1139 | is_recurring: function() { |
| 1140 | // set default values for recurring documents |
Rushabh Mehta | 756e518 | 2016-03-03 13:00:17 +0530 | [diff] [blame] | 1141 | if(this.frm.doc.is_recurring && this.frm.doc.__islocal) { |
| 1142 | frappe.msgprint(__("Please set recurring after saving")); |
| 1143 | this.frm.set_value('is_recurring', 0); |
| 1144 | return; |
| 1145 | } |
| 1146 | |
Anand Doshi | 1394509 | 2014-09-21 19:45:49 +0530 | [diff] [blame] | 1147 | if(this.frm.doc.is_recurring) { |
Nabin Hait | 68a628e | 2016-03-21 12:03:16 +0530 | [diff] [blame] | 1148 | if(!this.frm.doc.recurring_id) { |
| 1149 | this.frm.set_value('recurring_id', this.frm.doc.name); |
| 1150 | } |
Rushabh Mehta | bb8c6de | 2016-03-29 17:52:22 +0530 | [diff] [blame] | 1151 | |
Anand Doshi | 1394509 | 2014-09-21 19:45:49 +0530 | [diff] [blame] | 1152 | var owner_email = this.frm.doc.owner=="Administrator" |
| 1153 | ? frappe.user_info("Administrator").email |
| 1154 | : this.frm.doc.owner; |
| 1155 | |
| 1156 | this.frm.doc.notification_email_address = $.map([cstr(owner_email), |
| 1157 | cstr(this.frm.doc.contact_email)], function(v) { return v || null; }).join(", "); |
| 1158 | this.frm.doc.repeat_on_day_of_month = frappe.datetime.str_to_obj(this.frm.doc.posting_date).getDate(); |
| 1159 | } |
| 1160 | |
| 1161 | refresh_many(["notification_email_address", "repeat_on_day_of_month"]); |
| 1162 | }, |
| 1163 | |
| 1164 | from_date: function() { |
| 1165 | // set to_date |
| 1166 | if(this.frm.doc.from_date) { |
| 1167 | var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, |
| 1168 | 'Yearly': 12}; |
| 1169 | |
| 1170 | var months = recurring_type_map[this.frm.doc.recurring_type]; |
| 1171 | if(months) { |
| 1172 | var to_date = frappe.datetime.add_months(this.frm.doc.from_date, |
| 1173 | months); |
| 1174 | this.frm.doc.to_date = frappe.datetime.add_days(to_date, -1); |
| 1175 | refresh_field('to_date'); |
| 1176 | } |
| 1177 | } |
Saurabh | d313553 | 2016-02-25 18:59:20 +0530 | [diff] [blame] | 1178 | }, |
Rushabh Mehta | bb8c6de | 2016-03-29 17:52:22 +0530 | [diff] [blame] | 1179 | |
Saurabh | 2d7af63 | 2016-02-26 11:09:20 +0530 | [diff] [blame] | 1180 | set_gross_profit: function(item) { |
Saurabh | 5ada14b | 2016-02-26 18:02:55 +0530 | [diff] [blame] | 1181 | if (this.frm.doc.doctype == "Sales Order" && item.valuation_rate) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1182 | var rate = flt(item.rate) * flt(this.frm.doc.conversion_rate || 1); |
Kanchan Chauhan | 5a980ac | 2017-02-10 14:27:11 +0530 | [diff] [blame] | 1183 | item.gross_profit = flt(((rate - item.valuation_rate) * item.stock_qty), precision("amount", item)); |
Saurabh | 2d7af63 | 2016-02-26 11:09:20 +0530 | [diff] [blame] | 1184 | } |
Rushabh Mehta | 203cc96 | 2016-04-07 15:25:43 +0530 | [diff] [blame] | 1185 | }, |
| 1186 | |
| 1187 | setup_item_selector: function() { |
Rushabh Mehta | bc92824 | 2016-05-29 23:08:22 +0530 | [diff] [blame] | 1188 | // TODO: remove item selector |
| 1189 | |
| 1190 | return; |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 1191 | // if(!this.item_selector) { |
| 1192 | // this.item_selector = new erpnext.ItemSelector({frm: this.frm}); |
| 1193 | // } |
Nabin Hait | 28a0528 | 2016-06-27 17:41:39 +0530 | [diff] [blame] | 1194 | }, |
Rushabh Mehta | 76b1341 | 2016-07-18 14:30:18 +0530 | [diff] [blame] | 1195 | |
Nabin Hait | 28a0528 | 2016-06-27 17:41:39 +0530 | [diff] [blame] | 1196 | get_advances: function() { |
| 1197 | if(!this.frm.is_return) { |
| 1198 | return this.frm.call({ |
| 1199 | method: "set_advances", |
| 1200 | doc: this.frm.doc, |
| 1201 | callback: function(r, rt) { |
| 1202 | refresh_field("advances"); |
| 1203 | } |
| 1204 | }) |
| 1205 | } |
Nabin Hait | 05aefbb | 2016-06-28 19:42:19 +0530 | [diff] [blame] | 1206 | }, |
Rushabh Mehta | 76b1341 | 2016-07-18 14:30:18 +0530 | [diff] [blame] | 1207 | |
Nabin Hait | 05aefbb | 2016-06-28 19:42:19 +0530 | [diff] [blame] | 1208 | make_payment_entry: function() { |
| 1209 | return frappe.call({ |
Rohit Waghchaure | b7a5502 | 2016-10-05 16:24:41 +0530 | [diff] [blame] | 1210 | method: cur_frm.cscript.get_method_for_payment(), |
Nabin Hait | 05aefbb | 2016-06-28 19:42:19 +0530 | [diff] [blame] | 1211 | args: { |
| 1212 | "dt": cur_frm.doc.doctype, |
| 1213 | "dn": cur_frm.doc.name |
| 1214 | }, |
| 1215 | callback: function(r) { |
| 1216 | var doclist = frappe.model.sync(r.message); |
| 1217 | frappe.set_route("Form", doclist[0].doctype, doclist[0].name); |
Nabin Hait | 56548cb | 2016-07-01 15:58:39 +0530 | [diff] [blame] | 1218 | // cur_frm.refresh_fields() |
Nabin Hait | 05aefbb | 2016-06-28 19:42:19 +0530 | [diff] [blame] | 1219 | } |
| 1220 | }); |
Rohit Waghchaure | b7a5502 | 2016-10-05 16:24:41 +0530 | [diff] [blame] | 1221 | }, |
| 1222 | |
| 1223 | get_method_for_payment: function(){ |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 1224 | var method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry"; |
Rohit Waghchaure | 7d52989 | 2016-10-06 14:35:04 +0530 | [diff] [blame] | 1225 | if(cur_frm.doc.__onload && cur_frm.doc.__onload.make_payment_via_journal_entry){ |
Rohit Waghchaure | b7a5502 | 2016-10-05 16:24:41 +0530 | [diff] [blame] | 1226 | if(in_list(['Sales Invoice', 'Purchase Invoice'], cur_frm.doc.doctype)){ |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 1227 | method = "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_invoice"; |
Rohit Waghchaure | b7a5502 | 2016-10-05 16:24:41 +0530 | [diff] [blame] | 1228 | }else { |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 1229 | method= "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_order"; |
Rohit Waghchaure | b7a5502 | 2016-10-05 16:24:41 +0530 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | return method |
Manas Solanki | cc90241 | 2016-11-10 19:15:11 +0530 | [diff] [blame] | 1234 | }, |
Makarand Bauskar | c196d74 | 2017-06-02 17:28:40 +0530 | [diff] [blame] | 1235 | |
| 1236 | set_query_for_batch: function(doc, cdt, cdn) { |
| 1237 | // Show item's batches in the dropdown of batch no |
| 1238 | |
| 1239 | var me = this; |
| 1240 | var item = frappe.get_doc(cdt, cdn); |
| 1241 | |
| 1242 | if(!item.item_code) { |
| 1243 | frappe.throw(__("Please enter Item Code to get batch no")); |
Rushabh Mehta | 3631102 | 2017-06-20 09:30:53 +0530 | [diff] [blame] | 1244 | } else if (doc.doctype == "Purchase Receipt" || |
Makarand Bauskar | c196d74 | 2017-06-02 17:28:40 +0530 | [diff] [blame] | 1245 | (doc.doctype == "Purchase Invoice" && doc.update_stock)) { |
| 1246 | |
| 1247 | return { |
| 1248 | filters: {'item': item.item_code} |
| 1249 | } |
| 1250 | } else { |
Rushabh Mehta | 98aa581 | 2017-11-14 09:32:32 +0530 | [diff] [blame] | 1251 | let filters = { |
Makarand Bauskar | c196d74 | 2017-06-02 17:28:40 +0530 | [diff] [blame] | 1252 | 'item_code': item.item_code, |
| 1253 | 'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(), |
| 1254 | } |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 1255 | if (item.warehouse) filters["warehouse"] = item.warehouse; |
Makarand Bauskar | c196d74 | 2017-06-02 17:28:40 +0530 | [diff] [blame] | 1256 | |
KanchanChauhan | 0fe455a | 2017-11-17 20:08:15 +0530 | [diff] [blame] | 1257 | return { |
Makarand Bauskar | c196d74 | 2017-06-02 17:28:40 +0530 | [diff] [blame] | 1258 | query : "erpnext.controllers.queries.get_batch_no", |
| 1259 | filters: filters |
| 1260 | } |
| 1261 | } |
| 1262 | }, |
Nabin Hait | 9275969 | 2017-08-15 08:23:51 +0530 | [diff] [blame] | 1263 | |
| 1264 | payment_terms_template: function() { |
| 1265 | var me = this; |
rohitwaghchaure | efbc066 | 2017-12-11 14:54:20 +0530 | [diff] [blame] | 1266 | if(this.frm.doc.payment_terms_template) { |
rohitwaghchaure | da941af | 2018-01-17 16:23:04 +0530 | [diff] [blame] | 1267 | var posting_date = this.frm.doc.bill_date || |
| 1268 | this.frm.doc.posting_date || this.frm.doc.transaction_date; |
| 1269 | |
Nabin Hait | 9275969 | 2017-08-15 08:23:51 +0530 | [diff] [blame] | 1270 | frappe.call({ |
| 1271 | method: "erpnext.controllers.accounts_controller.get_payment_terms", |
| 1272 | args: { |
| 1273 | terms_template: this.frm.doc.payment_terms_template, |
rohitwaghchaure | da941af | 2018-01-17 16:23:04 +0530 | [diff] [blame] | 1274 | posting_date: posting_date, |
Nabin Hait | 0551f7b | 2017-11-21 19:58:16 +0530 | [diff] [blame] | 1275 | grand_total: this.frm.doc.rounded_total || this.frm.doc.grand_total |
Nabin Hait | 9275969 | 2017-08-15 08:23:51 +0530 | [diff] [blame] | 1276 | }, |
| 1277 | callback: function(r) { |
| 1278 | if(r.message && !r.exc) { |
| 1279 | me.frm.set_value("payment_schedule", r.message); |
| 1280 | } |
| 1281 | } |
| 1282 | }) |
| 1283 | } |
| 1284 | }, |
| 1285 | |
| 1286 | payment_term: function(doc, cdt, cdn) { |
| 1287 | var row = locals[cdt][cdn]; |
| 1288 | if(row.payment_term) { |
| 1289 | frappe.call({ |
| 1290 | method: "erpnext.controllers.accounts_controller.get_payment_term_details", |
| 1291 | args: { |
| 1292 | term: row.payment_term, |
| 1293 | posting_date: this.frm.doc.posting_date || this.frm.doc.transaction_date, |
Nabin Hait | 0551f7b | 2017-11-21 19:58:16 +0530 | [diff] [blame] | 1294 | grand_total: this.frm.doc.rounded_total || this.frm.doc.grand_total |
Nabin Hait | 9275969 | 2017-08-15 08:23:51 +0530 | [diff] [blame] | 1295 | }, |
| 1296 | callback: function(r) { |
| 1297 | if(r.message && !r.exc) { |
| 1298 | for (var d in r.message) { |
| 1299 | frappe.model.set_value(cdt, cdn, d, r.message[d]); |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | }) |
| 1304 | } |
| 1305 | } |
Nabin Hait | 6e74079 | 2017-05-06 12:45:16 +0530 | [diff] [blame] | 1306 | }); |
pratu16x7 | ae450fc | 2017-06-26 15:31:46 +0530 | [diff] [blame] | 1307 | |
rohitwaghchaure | 2b95a54 | 2017-12-14 16:06:23 +0530 | [diff] [blame] | 1308 | erpnext.show_serial_batch_selector = function(frm, d, callback, on_close, show_dialog) { |
pratu16x7 | ae450fc | 2017-06-26 15:31:46 +0530 | [diff] [blame] | 1309 | frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() { |
pratu16x7 | 89d001c | 2017-06-26 17:45:49 +0530 | [diff] [blame] | 1310 | new erpnext.SerialNoBatchSelector({ |
pratu16x7 | ae450fc | 2017-06-26 15:31:46 +0530 | [diff] [blame] | 1311 | frm: frm, |
| 1312 | item: d, |
| 1313 | warehouse_details: { |
| 1314 | type: "Warehouse", |
| 1315 | name: d.warehouse |
| 1316 | }, |
rohitwaghchaure | 2b95a54 | 2017-12-14 16:06:23 +0530 | [diff] [blame] | 1317 | callback: callback, |
| 1318 | on_close: on_close |
Rohit Waghchaure | 6ab6303 | 2017-09-01 15:28:44 +0530 | [diff] [blame] | 1319 | }, show_dialog); |
pratu16x7 | ae450fc | 2017-06-26 15:31:46 +0530 | [diff] [blame] | 1320 | }); |
| 1321 | } |