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 |
Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 3 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 4 | |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 5 | cur_frm.cscript.tax_table = "Sales Taxes and Charges"; |
Rushabh Mehta | 621283c | 2016-04-21 19:00:34 +0530 | [diff] [blame] | 6 | {% include 'erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.js' %} |
Nabin Hait | 613d081 | 2015-02-23 11:58:15 +0530 | [diff] [blame] | 7 | |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 8 | |
Rushabh Mehta | e10cf02 | 2014-09-12 13:09:41 +0530 | [diff] [blame] | 9 | cur_frm.email_field = "contact_email"; |
| 10 | |
Rushabh Mehta | be2ee18 | 2016-04-29 17:22:42 +0530 | [diff] [blame] | 11 | frappe.provide("erpnext.selling"); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 12 | erpnext.selling.SellingController = class SellingController extends erpnext.TransactionController { |
| 13 | setup() { |
| 14 | super.setup(); |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 15 | this.frm.add_fetch("sales_partner", "commission_rate", "commission_rate"); |
| 16 | this.frm.add_fetch("sales_person", "commission_rate", "commission_rate"); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 17 | } |
Rushabh Mehta | 532eedf | 2016-05-19 18:22:49 +0530 | [diff] [blame] | 18 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 19 | onload() { |
| 20 | super.onload(); |
Anand Doshi | 9b49614 | 2013-07-11 19:13:58 +0530 | [diff] [blame] | 21 | this.setup_queries(); |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 22 | this.frm.set_query('shipping_rule', function() { |
| 23 | return { |
| 24 | filters: { |
| 25 | "shipping_rule_type": "Selling" |
| 26 | } |
| 27 | }; |
| 28 | }); |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 29 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 30 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 31 | setup_queries() { |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 32 | var me = this; |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 33 | |
Rushabh Mehta | b92087c | 2017-01-13 18:53:11 +0530 | [diff] [blame] | 34 | $.each([["customer", "customer"], |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 35 | ["lead", "lead"]], |
Anand Doshi | d5d39ac | 2013-07-29 13:28:37 +0530 | [diff] [blame] | 36 | function(i, opts) { |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 37 | if(me.frm.fields_dict[opts[0]]) |
Anand Doshi | d5d39ac | 2013-07-29 13:28:37 +0530 | [diff] [blame] | 38 | me.frm.set_query(opts[0], erpnext.queries[opts[1]]); |
| 39 | }); |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 40 | |
Rushabh Mehta | b92087c | 2017-01-13 18:53:11 +0530 | [diff] [blame] | 41 | me.frm.set_query('contact_person', erpnext.queries.contact_query); |
| 42 | me.frm.set_query('customer_address', erpnext.queries.address_query); |
| 43 | me.frm.set_query('shipping_address_name', erpnext.queries.address_query); |
| 44 | |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 45 | |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 46 | if(this.frm.fields_dict.selling_price_list) { |
| 47 | this.frm.set_query("selling_price_list", function() { |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 48 | return { filters: { selling: 1 } }; |
Anand Doshi | 720a01a | 2013-07-26 11:32:02 +0530 | [diff] [blame] | 49 | }); |
Anand Doshi | 720a01a | 2013-07-26 11:32:02 +0530 | [diff] [blame] | 50 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 51 | |
karthikeyan5 | 7fc6021 | 2019-07-04 22:46:16 +0530 | [diff] [blame] | 52 | if(this.frm.fields_dict.tc_name) { |
| 53 | this.frm.set_query("tc_name", function() { |
| 54 | return { filters: { selling: 1 } }; |
| 55 | }); |
| 56 | } |
| 57 | |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 58 | if(!this.frm.fields_dict["items"]) { |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 59 | return; |
| 60 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 61 | |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 62 | if(this.frm.fields_dict["items"].grid.get_field('item_code')) { |
| 63 | this.frm.set_query("item_code", "items", function() { |
Anand Doshi | 9b49614 | 2013-07-11 19:13:58 +0530 | [diff] [blame] | 64 | return { |
Rushabh Mehta | d973c16 | 2016-08-16 11:32:08 +0530 | [diff] [blame] | 65 | query: "erpnext.controllers.queries.item_query", |
DeeMysterio | aa82624 | 2021-09-14 13:58:18 +0530 | [diff] [blame] | 66 | filters: {'is_sales_item': 1, 'customer': cur_frm.doc.customer} |
Anand Doshi | 9b49614 | 2013-07-11 19:13:58 +0530 | [diff] [blame] | 67 | } |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 68 | }); |
| 69 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 70 | |
Rushabh Mehta | 698c040 | 2016-11-22 23:16:40 +0530 | [diff] [blame] | 71 | if(this.frm.fields_dict["packed_items"] && |
| 72 | this.frm.fields_dict["packed_items"].grid.get_field('batch_no')) { |
Rohit Waghchaure | e887e92 | 2016-11-18 12:16:22 +0530 | [diff] [blame] | 73 | this.frm.set_query("batch_no", "packed_items", function(doc, cdt, cdn) { |
| 74 | return me.set_query_for_batch(doc, cdt, cdn) |
| 75 | }); |
| 76 | } |
Deepesh Garg | ef0d26c | 2020-01-06 15:34:15 +0530 | [diff] [blame] | 77 | |
| 78 | if(this.frm.fields_dict["items"].grid.get_field('item_code')) { |
| 79 | this.frm.set_query("item_tax_template", "items", function(doc, cdt, cdn) { |
| 80 | return me.set_query_for_item_tax_template(doc, cdt, cdn) |
| 81 | }); |
| 82 | } |
| 83 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 84 | } |
Rohit Waghchaure | e887e92 | 2016-11-18 12:16:22 +0530 | [diff] [blame] | 85 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 86 | refresh() { |
| 87 | super.refresh(); |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 88 | |
Rushabh Mehta | 8d39fd9 | 2017-01-16 13:06:07 +0530 | [diff] [blame] | 89 | frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'} |
Rushabh Mehta | b92087c | 2017-01-13 18:53:11 +0530 | [diff] [blame] | 90 | |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 91 | this.frm.toggle_display("customer_name", |
Akhilesh Darjee | 5ce1b8b | 2013-12-09 16:29:04 +0530 | [diff] [blame] | 92 | (this.frm.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer)); |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 93 | |
Nabin Hait | 2029ea9 | 2015-04-16 17:55:35 +0530 | [diff] [blame] | 94 | this.toggle_editable_price_list_rate(); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 95 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 96 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 97 | customer() { |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 98 | var me = this; |
Nabin Hait | e45ec66 | 2018-08-01 17:44:34 +0530 | [diff] [blame] | 99 | erpnext.utils.get_party_details(this.frm, null, null, function() { |
| 100 | me.apply_price_list(); |
| 101 | }); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 102 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 103 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 104 | customer_address() { |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 105 | erpnext.utils.get_address_display(this.frm, "customer_address"); |
Saif Ur Rehman | fd531a6 | 2018-12-29 01:49:11 +0500 | [diff] [blame] | 106 | erpnext.utils.set_taxes_from_address(this.frm, "customer_address", "customer_address", "shipping_address_name"); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 107 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 108 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 109 | shipping_address_name() { |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 110 | erpnext.utils.get_address_display(this.frm, "shipping_address_name", "shipping_address"); |
Saif Ur Rehman | fd531a6 | 2018-12-29 01:49:11 +0500 | [diff] [blame] | 111 | erpnext.utils.set_taxes_from_address(this.frm, "shipping_address_name", "customer_address", "shipping_address_name"); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 112 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 113 | |
Subin Tom | 5265ba3 | 2021-07-13 14:58:17 +0530 | [diff] [blame] | 114 | dispatch_address_name() { |
| 115 | erpnext.utils.get_address_display(this.frm, "dispatch_address_name", "dispatch_address"); |
| 116 | } |
| 117 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 118 | sales_partner() { |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 119 | this.apply_pricing_rule(); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 120 | } |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 121 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 122 | campaign() { |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 123 | this.apply_pricing_rule(); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 124 | } |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 125 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 126 | selling_price_list() { |
Anand Doshi | dffec8f | 2014-07-01 17:45:15 +0530 | [diff] [blame] | 127 | this.apply_price_list(); |
rohitwaghchaure | 8e675eb | 2018-02-13 17:11:06 +0530 | [diff] [blame] | 128 | this.set_dynamic_labels(); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 129 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 130 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 131 | discount_percentage(doc, cdt, cdn) { |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 132 | var item = frappe.get_doc(cdt, cdn); |
Rohit Waghchaure | 8bfe330 | 2019-03-18 14:34:19 +0530 | [diff] [blame] | 133 | item.discount_amount = 0.0; |
| 134 | this.apply_discount_on_item(doc, cdt, cdn, 'discount_percentage'); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 135 | } |
Rohit Waghchaure | 8bfe330 | 2019-03-18 14:34:19 +0530 | [diff] [blame] | 136 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 137 | discount_amount(doc, cdt, cdn) { |
deepeshgarg007 | a9ea49c | 2019-07-04 15:56:34 +0530 | [diff] [blame] | 138 | |
| 139 | if(doc.name === cdn) { |
| 140 | return; |
| 141 | } |
| 142 | |
Nabin Hait | 593242f | 2019-04-05 19:35:02 +0530 | [diff] [blame] | 143 | var item = frappe.get_doc(cdt, cdn); |
| 144 | item.discount_percentage = 0.0; |
Rohit Waghchaure | 8bfe330 | 2019-03-18 14:34:19 +0530 | [diff] [blame] | 145 | this.apply_discount_on_item(doc, cdt, cdn, 'discount_amount'); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 146 | } |
Rohit Waghchaure | 8bfe330 | 2019-03-18 14:34:19 +0530 | [diff] [blame] | 147 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 148 | apply_discount_on_item(doc, cdt, cdn, field) { |
Rohit Waghchaure | 8bfe330 | 2019-03-18 14:34:19 +0530 | [diff] [blame] | 149 | var item = frappe.get_doc(cdt, cdn); |
Nabin Hait | a7f757a | 2014-02-10 17:54:04 +0530 | [diff] [blame] | 150 | if(!item.price_list_rate) { |
Rohit Waghchaure | 8bfe330 | 2019-03-18 14:34:19 +0530 | [diff] [blame] | 151 | item[field] = 0.0; |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 152 | } else { |
Nabin Hait | a7f757a | 2014-02-10 17:54:04 +0530 | [diff] [blame] | 153 | this.price_list_rate(doc, cdt, cdn); |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 154 | } |
Saurabh | 5ada14b | 2016-02-26 18:02:55 +0530 | [diff] [blame] | 155 | this.set_gross_profit(item); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 156 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 157 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 158 | commission_rate() { |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 159 | this.calculate_commission(); |
| 160 | refresh_field("total_commission"); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 161 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 162 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 163 | total_commission() { |
Nabin Hait | 5690be1 | 2015-02-12 16:09:11 +0530 | [diff] [blame] | 164 | if(this.frm.doc.base_net_total) { |
| 165 | frappe.model.round_floats_in(this.frm.doc, ["base_net_total", "total_commission"]); |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 166 | |
Nabin Hait | 5690be1 | 2015-02-12 16:09:11 +0530 | [diff] [blame] | 167 | if(this.frm.doc.base_net_total < this.frm.doc.total_commission) { |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 168 | var msg = (__("[Error]") + " " + |
| 169 | __(frappe.meta.get_label(this.frm.doc.doctype, "total_commission", |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 170 | this.frm.doc.name)) + " > " + |
Nabin Hait | 5690be1 | 2015-02-12 16:09:11 +0530 | [diff] [blame] | 171 | __(frappe.meta.get_label(this.frm.doc.doctype, "base_net_total", this.frm.doc.name))); |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 172 | frappe.msgprint(msg); |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 173 | throw msg; |
| 174 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 175 | |
| 176 | this.frm.set_value("commission_rate", |
Nabin Hait | 5690be1 | 2015-02-12 16:09:11 +0530 | [diff] [blame] | 177 | flt(this.frm.doc.total_commission * 100.0 / this.frm.doc.base_net_total)); |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 178 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 179 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 180 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 181 | allocated_percentage(doc, cdt, cdn) { |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 182 | var sales_person = frappe.get_doc(cdt, cdn); |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 183 | if(sales_person.allocated_percentage) { |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 184 | |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 185 | sales_person.allocated_percentage = flt(sales_person.allocated_percentage, |
| 186 | precision("allocated_percentage", sales_person)); |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 187 | |
Nabin Hait | 5690be1 | 2015-02-12 16:09:11 +0530 | [diff] [blame] | 188 | sales_person.allocated_amount = flt(this.frm.doc.base_net_total * |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 189 | sales_person.allocated_percentage / 100.0, |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 190 | precision("allocated_amount", sales_person)); |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 191 | refresh_field(["allocated_amount"], sales_person); |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 192 | |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 193 | this.calculate_incentive(sales_person); |
| 194 | refresh_field(["allocated_percentage", "allocated_amount", "commission_rate","incentives"], sales_person.name, |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 195 | sales_person.parentfield); |
deepeshgarg007 | d9a768a | 2018-12-29 19:33:44 +0530 | [diff] [blame] | 196 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 197 | } |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 198 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 199 | sales_person(doc, cdt, cdn) { |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 200 | var row = frappe.get_doc(cdt, cdn); |
| 201 | this.calculate_incentive(row); |
| 202 | refresh_field("incentives",row.name,row.parentfield); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 203 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 204 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 205 | warehouse(doc, cdt, cdn) { |
Sambhaji Kolate | 98dbccd | 2015-03-10 15:04:28 +0530 | [diff] [blame] | 206 | var me = this; |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 207 | var item = frappe.get_doc(cdt, cdn); |
Saqib | 14cdb24 | 2020-04-16 16:21:35 +0530 | [diff] [blame] | 208 | |
marination | 734b57d | 2021-11-02 18:34:55 +0530 | [diff] [blame] | 209 | // check if serial nos entered are as much as qty in row |
| 210 | if (item.serial_no) { |
| 211 | let serial_nos = item.serial_no.split(`\n`).filter(sn => sn.trim()); // filter out whitespaces |
| 212 | if (item.qty === serial_nos.length) return; |
Saqib | 14cdb24 | 2020-04-16 16:21:35 +0530 | [diff] [blame] | 213 | } |
| 214 | |
Shreya | a20157a | 2018-04-13 12:03:42 +0530 | [diff] [blame] | 215 | if (item.serial_no && !item.batch_no) { |
| 216 | item.serial_no = null; |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 217 | } |
Saqib | 14cdb24 | 2020-04-16 16:21:35 +0530 | [diff] [blame] | 218 | |
Shreya | a20157a | 2018-04-13 12:03:42 +0530 | [diff] [blame] | 219 | var has_batch_no; |
| 220 | frappe.db.get_value('Item', {'item_code': item.item_code}, 'has_batch_no', (r) => { |
| 221 | has_batch_no = r && r.has_batch_no; |
| 222 | if(item.item_code && item.warehouse) { |
| 223 | return this.frm.call({ |
| 224 | method: "erpnext.stock.get_item_details.get_bin_details_and_serial_nos", |
| 225 | child: item, |
| 226 | args: { |
| 227 | item_code: item.item_code, |
| 228 | warehouse: item.warehouse, |
Rohit Waghchaure | 6daab3c | 2019-09-19 17:01:26 +0530 | [diff] [blame] | 229 | has_batch_no: has_batch_no || 0, |
Shreya | a20157a | 2018-04-13 12:03:42 +0530 | [diff] [blame] | 230 | stock_qty: item.stock_qty, |
| 231 | serial_no: item.serial_no || "", |
| 232 | }, |
| 233 | callback:function(r){ |
| 234 | if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { |
Deepesh Garg | fb29ffc | 2019-06-28 14:08:08 +0530 | [diff] [blame] | 235 | |
| 236 | if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; |
| 237 | |
Shreya | a20157a | 2018-04-13 12:03:42 +0530 | [diff] [blame] | 238 | me.set_batch_number(cdt, cdn); |
| 239 | me.batch_no(doc, cdt, cdn); |
| 240 | } |
| 241 | } |
| 242 | }); |
| 243 | } |
| 244 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 245 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 246 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 247 | toggle_editable_price_list_rate() { |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 248 | var df = frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "price_list_rate", this.frm.doc.name); |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 249 | var editable_price_list_rate = cint(frappe.defaults.get_default("editable_price_list_rate")); |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 250 | |
Anand Doshi | 33fe867 | 2013-08-02 12:39:10 +0530 | [diff] [blame] | 251 | if(df && editable_price_list_rate) { |
Saqib | a5baf90 | 2021-09-13 15:50:20 +0530 | [diff] [blame] | 252 | const parent_field = frappe.meta.get_parentfield(this.frm.doc.doctype, this.frm.doc.doctype + " Item"); |
| 253 | if (!this.frm.fields_dict[parent_field]) return; |
| 254 | |
| 255 | this.frm.fields_dict[parent_field].grid.update_docfield_property( |
| 256 | 'price_list_rate', 'read_only', 0 |
| 257 | ); |
Anand Doshi | 33fe867 | 2013-08-02 12:39:10 +0530 | [diff] [blame] | 258 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 259 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 260 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 261 | calculate_commission() { |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 262 | if(this.frm.fields_dict.commission_rate) { |
| 263 | if(this.frm.doc.commission_rate > 100) { |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 264 | var msg = __(frappe.meta.get_label(this.frm.doc.doctype, "commission_rate", this.frm.doc.name)) + |
| 265 | " " + __("cannot be greater than 100"); |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 266 | frappe.msgprint(msg); |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 267 | throw msg; |
| 268 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 269 | |
Nabin Hait | 5690be1 | 2015-02-12 16:09:11 +0530 | [diff] [blame] | 270 | this.frm.doc.total_commission = flt(this.frm.doc.base_net_total * this.frm.doc.commission_rate / 100.0, |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 271 | precision("total_commission")); |
| 272 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 273 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 274 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 275 | calculate_contribution() { |
Anand Doshi | 2168e39 | 2013-05-23 19:25:08 +0530 | [diff] [blame] | 276 | var me = this; |
Rushabh Mehta | aa355af | 2014-03-26 18:24:30 +0530 | [diff] [blame] | 277 | $.each(this.frm.doc.doctype.sales_team || [], function(i, sales_person) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 278 | frappe.model.round_floats_in(sales_person); |
| 279 | if(sales_person.allocated_percentage) { |
| 280 | sales_person.allocated_amount = flt( |
| 281 | me.frm.doc.base_net_total * sales_person.allocated_percentage / 100.0, |
| 282 | precision("allocated_amount", sales_person)); |
| 283 | } |
| 284 | }); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 285 | } |
Anand Doshi | bd67e87 | 2014-04-11 16:51:27 +0530 | [diff] [blame] | 286 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 287 | calculate_incentive(row) { |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 288 | if(row.allocated_amount) |
| 289 | { |
| 290 | row.incentives = flt( |
| 291 | row.allocated_amount * row.commission_rate / 100.0, |
deepeshgarg007 | c3772f1 | 2018-09-26 15:55:43 +0530 | [diff] [blame] | 292 | precision("incentives", row)); |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 293 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 294 | } |
deepeshgarg007 | 86152eb | 2018-09-25 19:08:16 +0530 | [diff] [blame] | 295 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 296 | batch_no(doc, cdt, cdn) { |
Sambhaji Kolate | 98dbccd | 2015-03-10 15:04:28 +0530 | [diff] [blame] | 297 | var me = this; |
| 298 | var item = frappe.get_doc(cdt, cdn); |
Saqib | a6f98d4 | 2020-07-23 18:51:26 +0530 | [diff] [blame] | 299 | |
| 300 | if (item.serial_no) { |
| 301 | return; |
| 302 | } |
| 303 | |
Shreya | a20157a | 2018-04-13 12:03:42 +0530 | [diff] [blame] | 304 | item.serial_no = null; |
| 305 | var has_serial_no; |
| 306 | frappe.db.get_value('Item', {'item_code': item.item_code}, 'has_serial_no', (r) => { |
| 307 | has_serial_no = r && r.has_serial_no; |
| 308 | if(item.warehouse && item.item_code && item.batch_no) { |
| 309 | return this.frm.call({ |
| 310 | method: "erpnext.stock.get_item_details.get_batch_qty_and_serial_no", |
| 311 | child: item, |
| 312 | args: { |
| 313 | "batch_no": item.batch_no, |
Marica | f0e87f7 | 2019-11-27 15:49:41 +0530 | [diff] [blame] | 314 | "stock_qty": item.stock_qty || item.qty, //if stock_qty field is not available fetch qty (in case of Packed Items table) |
Shreya | a20157a | 2018-04-13 12:03:42 +0530 | [diff] [blame] | 315 | "warehouse": item.warehouse, |
| 316 | "item_code": item.item_code, |
| 317 | "has_serial_no": has_serial_no |
| 318 | }, |
| 319 | "fieldname": "actual_batch_qty" |
| 320 | }); |
| 321 | } |
| 322 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 323 | } |
Sambhaji Kolate | 98dbccd | 2015-03-10 15:04:28 +0530 | [diff] [blame] | 324 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 325 | set_dynamic_labels() { |
| 326 | super.set_dynamic_labels(); |
Neil Trini Lasrado | ed8cecb | 2015-07-07 13:59:23 +0530 | [diff] [blame] | 327 | this.set_product_bundle_help(this.frm.doc); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 328 | } |
Nabin Hait | 0b15755 | 2014-06-24 17:02:45 +0530 | [diff] [blame] | 329 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 330 | set_product_bundle_help(doc) { |
Nabin Hait | 0b15755 | 2014-06-24 17:02:45 +0530 | [diff] [blame] | 331 | if(!cur_frm.fields_dict.packing_list) return; |
Nabin Hait | e7d1536 | 2014-12-25 16:01:55 +0530 | [diff] [blame] | 332 | if ((doc.packed_items || []).length) { |
Nabin Hait | 0b15755 | 2014-06-24 17:02:45 +0530 | [diff] [blame] | 333 | $(cur_frm.fields_dict.packing_list.row.wrapper).toggle(true); |
| 334 | |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 335 | if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { |
| 336 | var help_msg = "<div class='alert alert-warning'>" + |
Neil Trini Lasrado | ed8cecb | 2015-07-07 13:59:23 +0530 | [diff] [blame] | 337 | __("For 'Product Bundle' items, Warehouse, Serial No and Batch No will be considered from the 'Packing List' table. If Warehouse and Batch No are same for all packing items for any 'Product Bundle' item, those values can be entered in the main Item table, values will be copied to 'Packing List' table.")+ |
Nabin Hait | 0b15755 | 2014-06-24 17:02:45 +0530 | [diff] [blame] | 338 | "</div>"; |
Neil Trini Lasrado | ed8cecb | 2015-07-07 13:59:23 +0530 | [diff] [blame] | 339 | frappe.meta.get_docfield(doc.doctype, 'product_bundle_help', doc.name).options = help_msg; |
Nabin Hait | 0b15755 | 2014-06-24 17:02:45 +0530 | [diff] [blame] | 340 | } |
| 341 | } else { |
| 342 | $(cur_frm.fields_dict.packing_list.row.wrapper).toggle(false); |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 343 | if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { |
Neil Trini Lasrado | ed8cecb | 2015-07-07 13:59:23 +0530 | [diff] [blame] | 344 | frappe.meta.get_docfield(doc.doctype, 'product_bundle_help', doc.name).options = ''; |
Nabin Hait | 0b15755 | 2014-06-24 17:02:45 +0530 | [diff] [blame] | 345 | } |
| 346 | } |
Neil Trini Lasrado | ed8cecb | 2015-07-07 13:59:23 +0530 | [diff] [blame] | 347 | refresh_field('product_bundle_help'); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 348 | } |
Anand Doshi | 01de945 | 2016-01-26 16:22:50 +0530 | [diff] [blame] | 349 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 350 | company_address() { |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 351 | var me = this; |
| 352 | if(this.frm.doc.company_address) { |
| 353 | frappe.call({ |
| 354 | method: "frappe.contacts.doctype.address.address.get_address_display", |
| 355 | args: {"address_dict": this.frm.doc.company_address }, |
| 356 | callback: function(r) { |
| 357 | if(r.message) { |
| 358 | me.frm.set_value("company_address_display", r.message) |
| 359 | } |
| 360 | } |
| 361 | }) |
| 362 | } else { |
| 363 | this.frm.set_value("company_address_display", ""); |
| 364 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 365 | } |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 366 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 367 | conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) { |
| 368 | super.conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate); |
tundebabzy | f9b5c74 | 2018-01-25 19:21:05 +0100 | [diff] [blame] | 369 | if(frappe.meta.get_docfield(cdt, "stock_qty", cdn) && |
| 370 | in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { |
Deepesh Garg | fb29ffc | 2019-06-28 14:08:08 +0530 | [diff] [blame] | 371 | if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; |
| 372 | this.set_batch_number(cdt, cdn); |
| 373 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 374 | } |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 375 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 376 | batch_no(doc, cdt, cdn) { |
| 377 | super.batch_no(doc, cdt, cdn); |
| 378 | } |
Deepesh Garg | bd9bdc5 | 2021-01-28 12:05:57 +0530 | [diff] [blame] | 379 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 380 | qty(doc, cdt, cdn) { |
| 381 | super.qty(doc, cdt, cdn); |
Deepesh Garg | fb29ffc | 2019-06-28 14:08:08 +0530 | [diff] [blame] | 382 | |
| 383 | if(in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { |
| 384 | if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; |
| 385 | this.set_batch_number(cdt, cdn); |
| 386 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 387 | } |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 388 | |
| 389 | /* Determine appropriate batch number and set it in the form. |
| 390 | * @param {string} cdt - Document Doctype |
| 391 | * @param {string} cdn - Document name |
| 392 | */ |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 393 | set_batch_number(cdt, cdn) { |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 394 | const doc = frappe.get_doc(cdt, cdn); |
Saqib | faea854 | 2020-03-26 13:18:57 +0530 | [diff] [blame] | 395 | if (doc && doc.has_batch_no && doc.warehouse) { |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 396 | this._set_batch_number(doc); |
| 397 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 398 | } |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 399 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 400 | _set_batch_number(doc) { |
Rohit Waghchaure | e1f0704 | 2021-08-23 14:27:55 +0530 | [diff] [blame] | 401 | if (doc.batch_no) { |
| 402 | return |
| 403 | } |
| 404 | |
Saqib | faea854 | 2020-03-26 13:18:57 +0530 | [diff] [blame] | 405 | let args = {'item_code': doc.item_code, 'warehouse': doc.warehouse, 'qty': flt(doc.qty) * flt(doc.conversion_factor)}; |
| 406 | if (doc.has_serial_no && doc.serial_no) { |
| 407 | args['serial_no'] = doc.serial_no |
| 408 | } |
marination | 8a30cb2 | 2020-04-23 00:18:21 +0530 | [diff] [blame] | 409 | |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 410 | return frappe.call({ |
| 411 | method: 'erpnext.stock.doctype.batch.batch.get_batch_no', |
Saqib | faea854 | 2020-03-26 13:18:57 +0530 | [diff] [blame] | 412 | args: args, |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 413 | callback: function(r) { |
| 414 | if(r.message) { |
| 415 | frappe.model.set_value(doc.doctype, doc.name, 'batch_no', r.message); |
tundebabzy | 8ae53ca | 2017-11-30 07:07:21 +0100 | [diff] [blame] | 416 | } else { |
| 417 | frappe.model.set_value(doc.doctype, doc.name, 'batch_no', r.message); |
tundebabzy | acccdb3 | 2017-11-23 08:35:15 +0100 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | }); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 421 | } |
Charles-Henri Decultot | 8b22310 | 2018-06-28 10:57:58 +0200 | [diff] [blame] | 422 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 423 | update_auto_repeat_reference(doc) { |
Charles-Henri Decultot | 8b22310 | 2018-06-28 10:57:58 +0200 | [diff] [blame] | 424 | if (doc.auto_repeat) { |
| 425 | frappe.call({ |
Rucha Mahabal | 65a627c | 2019-07-17 13:50:32 +0530 | [diff] [blame] | 426 | method:"frappe.automation.doctype.auto_repeat.auto_repeat.update_reference", |
deepeshgarg007 | d9a768a | 2018-12-29 19:33:44 +0530 | [diff] [blame] | 427 | args:{ |
Charles-Henri Decultot | 8b22310 | 2018-06-28 10:57:58 +0200 | [diff] [blame] | 428 | docname: doc.auto_repeat, |
| 429 | reference:doc.name |
| 430 | }, |
| 431 | callback: function(r){ |
| 432 | if (r.message=="success") { |
| 433 | frappe.show_alert({message:__("Auto repeat document updated"), indicator:'green'}); |
| 434 | } else { |
| 435 | frappe.show_alert({message:__("An error occurred during the update process"), indicator:'red'}); |
| 436 | } |
| 437 | } |
| 438 | }) |
| 439 | } |
| 440 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 441 | }; |
Anand Doshi | 43f087c | 2014-08-26 14:25:53 +0530 | [diff] [blame] | 442 | |
Neil Trini Lasrado | 6e343e2 | 2016-03-09 17:02:59 +0530 | [diff] [blame] | 443 | frappe.ui.form.on(cur_frm.doctype,"project", function(frm) { |
Nabin Hait | 10b155a | 2014-10-23 13:18:59 +0530 | [diff] [blame] | 444 | if(in_list(["Delivery Note", "Sales Invoice"], frm.doc.doctype)) { |
Rushabh Mehta | 532eedf | 2016-05-19 18:22:49 +0530 | [diff] [blame] | 445 | if(frm.doc.project) { |
| 446 | frappe.call({ |
| 447 | method:'erpnext.projects.doctype.project.project.get_cost_center_name' , |
| 448 | args: { project: frm.doc.project }, |
| 449 | callback: function(r, rt) { |
| 450 | if(!r.exc) { |
| 451 | $.each(frm.doc["items"] || [], function(i, row) { |
| 452 | if(r.message) { |
| 453 | frappe.model.set_value(row.doctype, row.name, "cost_center", r.message); |
Mohammad Hasnain Mohsin Rajan | e15b6a9 | 2020-11-25 15:36:41 +0530 | [diff] [blame] | 454 | frappe.msgprint(__("Cost Center For Item with Item Code {0} has been Changed to {1}", [row.item_name, r.message])); |
Rushabh Mehta | 532eedf | 2016-05-19 18:22:49 +0530 | [diff] [blame] | 455 | } |
| 456 | }) |
| 457 | } |
Nabin Hait | 10b155a | 2014-10-23 13:18:59 +0530 | [diff] [blame] | 458 | } |
Rushabh Mehta | 532eedf | 2016-05-19 18:22:49 +0530 | [diff] [blame] | 459 | }) |
| 460 | } |
Nabin Hait | 10b155a | 2014-10-23 13:18:59 +0530 | [diff] [blame] | 461 | } |
Nabin Hait | e45ec66 | 2018-08-01 17:44:34 +0530 | [diff] [blame] | 462 | }) |
deepeshgarg007 | d9a768a | 2018-12-29 19:33:44 +0530 | [diff] [blame] | 463 | |
| 464 | frappe.ui.form.on(cur_frm.doctype, { |
| 465 | set_as_lost_dialog: function(frm) { |
| 466 | var dialog = new frappe.ui.Dialog({ |
| 467 | title: __("Set as Lost"), |
| 468 | fields: [ |
Anupam Kumar | e447c79 | 2020-08-13 09:20:36 +0530 | [diff] [blame] | 469 | { |
| 470 | "fieldtype": "Table MultiSelect", |
| 471 | "label": __("Lost Reasons"), |
| 472 | "fieldname": "lost_reason", |
| 473 | "options": frm.doctype === 'Opportunity' ? 'Opportunity Lost Reason Detail': 'Quotation Lost Reason Detail', |
| 474 | "reqd": 1 |
| 475 | }, |
| 476 | { |
Anupam Kumar | 6954dd6 | 2021-11-09 19:36:27 +0530 | [diff] [blame] | 477 | "fieldtype": "Table MultiSelect", |
| 478 | "label": __("Competitors"), |
| 479 | "fieldname": "competitors", |
| 480 | "options": "Competitor Detail" |
| 481 | }, |
| 482 | { |
Anupam Kumar | e447c79 | 2020-08-13 09:20:36 +0530 | [diff] [blame] | 483 | "fieldtype": "Text", |
| 484 | "label": __("Detailed Reason"), |
| 485 | "fieldname": "detailed_reason" |
| 486 | }, |
deepeshgarg007 | d9a768a | 2018-12-29 19:33:44 +0530 | [diff] [blame] | 487 | ], |
| 488 | primary_action: function() { |
Anupam Kumar | 6954dd6 | 2021-11-09 19:36:27 +0530 | [diff] [blame] | 489 | let values = dialog.get_values(); |
deepeshgarg007 | d9a768a | 2018-12-29 19:33:44 +0530 | [diff] [blame] | 490 | |
| 491 | frm.call({ |
| 492 | doc: frm.doc, |
| 493 | method: 'declare_enquiry_lost', |
| 494 | args: { |
Anupam Kumar | 6954dd6 | 2021-11-09 19:36:27 +0530 | [diff] [blame] | 495 | 'lost_reasons_list': values.lost_reason, |
| 496 | 'competitors': values.competitors, |
| 497 | 'detailed_reason': values.detailed_reason |
deepeshgarg007 | d9a768a | 2018-12-29 19:33:44 +0530 | [diff] [blame] | 498 | }, |
| 499 | callback: function(r) { |
| 500 | dialog.hide(); |
| 501 | frm.reload_doc(); |
| 502 | }, |
| 503 | }); |
deepeshgarg007 | d9a768a | 2018-12-29 19:33:44 +0530 | [diff] [blame] | 504 | }, |
| 505 | primary_action_label: __('Declare Lost') |
| 506 | }); |
| 507 | |
| 508 | dialog.show(); |
| 509 | } |
Anupam Kumar | 6954dd6 | 2021-11-09 19:36:27 +0530 | [diff] [blame] | 510 | }) |