blob: 8246790abc1b17a635213d2a17dbd536731dd5e7 [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302// License: GNU General Public License v3. See license.txt
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05303frappe.provide("erpnext");
Nabin Haitb072c742014-12-16 12:49:13 +05304frappe.provide("erpnext.utils");
Anand Doshie65e6212012-11-19 15:43:18 +05305
Anand Doshibdee6e02013-07-09 13:03:39 +05306$.extend(erpnext, {
7 get_currency: function(company) {
8 if(!company && cur_frm)
9 company = cur_frm.doc.company;
10 if(company)
Rushabh Mehta66d52b52014-03-27 14:17:33 +053011 return frappe.get_doc(":Company", company).default_currency || frappe.boot.sysdefaults.currency;
Anand Doshibdee6e02013-07-09 13:03:39 +053012 else
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053013 return frappe.boot.sysdefaults.currency;
Anand Doshibdee6e02013-07-09 13:03:39 +053014 },
Rushabh Mehtac38fc712014-04-16 17:21:25 +053015
tundebabzyc8978252018-02-12 10:34:50 +010016 get_presentation_currency_list: () => {
17 const docs = frappe.boot.docs;
Zarrare25dcd22018-06-21 10:53:12 +053018 let currency_list = docs.filter(d => d.doctype === ":Currency").map(d => d.name);
19 currency_list.unshift("");
tundebabzyc8978252018-02-12 10:34:50 +010020 return currency_list;
21 },
22
Anand Doshi8bde7f92014-04-24 18:11:49 +053023 toggle_naming_series: function() {
Rushabh Mehtac38fc712014-04-16 17:21:25 +053024 if(cur_frm.fields_dict.naming_series) {
Anand Doshibdee6e02013-07-09 13:03:39 +053025 cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false);
26 }
27 },
Rushabh Mehtac38fc712014-04-16 17:21:25 +053028
Anand Doshibdee6e02013-07-09 13:03:39 +053029 hide_company: function() {
30 if(cur_frm.fields_dict.company) {
Rushabh Mehta89418412013-10-07 18:22:29 +053031 var companies = Object.keys(locals[":Company"] || {});
Anand Doshibdee6e02013-07-09 13:03:39 +053032 if(companies.length === 1) {
33 if(!cur_frm.doc.company) cur_frm.set_value("company", companies[0]);
34 cur_frm.toggle_display("company", false);
Rushabh Mehta45ca8a42015-04-28 16:02:09 +053035 } else if(erpnext.last_selected_company) {
36 if(!cur_frm.doc.company) cur_frm.set_value("company", erpnext.last_selected_company);
Anand Doshibdee6e02013-07-09 13:03:39 +053037 }
38 }
Anand Doshi1ffc5b52013-07-15 18:09:43 +053039 },
Rushabh Mehtac38fc712014-04-16 17:21:25 +053040
Rohit Waghchauree9ff1912017-06-19 12:54:59 +053041 is_perpetual_inventory_enabled: function(company) {
42 if(company) {
43 return frappe.get_doc(":Company", company).enable_perpetual_inventory
44 }
45 },
46
Makarand Bauskare6712c12017-10-25 12:17:40 +053047 stale_rate_allowed: () => {
rohitwaghchaure7677ff02017-11-02 18:12:14 +053048 return cint(frappe.boot.sysdefaults.allow_stale);
Makarand Bauskare6712c12017-10-25 12:17:40 +053049 },
50
Rushabh Mehta2a21bc92015-02-25 15:08:42 +053051 setup_serial_no: function() {
52 var grid_row = cur_frm.open_grid_row();
akshay14384c22016-07-28 13:53:17 +053053 if(!grid_row || !grid_row.grid_form.fields_dict.serial_no ||
54 grid_row.grid_form.fields_dict.serial_no.get_status()!=="Write") return;
Rushabh Mehtac38fc712014-04-16 17:21:25 +053055
Pratik Vyasb52618c2014-04-14 16:25:30 +053056 var $btn = $('<button class="btn btn-sm btn-default">'+__("Add Serial No")+'</button>')
Rushabh Mehta62030e02013-08-14 18:37:28 +053057 .appendTo($("<div>")
Rushabh Mehta2a21bc92015-02-25 15:08:42 +053058 .css({"margin-bottom": "10px", "margin-top": "10px"})
akshay14384c22016-07-28 13:53:17 +053059 .appendTo(grid_row.grid_form.fields_dict.serial_no.$wrapper));
Rushabh Mehtac38fc712014-04-16 17:21:25 +053060
Rushabh Mehta62030e02013-08-14 18:37:28 +053061 $btn.on("click", function() {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053062 var d = new frappe.ui.Dialog({
Pratik Vyasb52618c2014-04-14 16:25:30 +053063 title: __("Add Serial No"),
Rushabh Mehta62030e02013-08-14 18:37:28 +053064 fields: [
65 {
66 "fieldtype": "Link",
Rohit Waghchaure2087e572017-02-27 13:43:04 +053067 "fieldname": "serial_no",
Rushabh Mehta62030e02013-08-14 18:37:28 +053068 "options": "Serial No",
Pratik Vyasb52618c2014-04-14 16:25:30 +053069 "label": __("Serial No"),
Neil Trini Lasrado3d61bbb2015-03-12 12:51:50 +053070 "get_query": function () {
Rushabh Mehta45ca8a42015-04-28 16:02:09 +053071 return {
72 filters: {
Shreya14bd43d2018-04-27 16:24:05 +053073 item_code:grid_row.doc.item_code,
Nabin Haitb7c0c552015-08-04 12:18:12 +053074 warehouse:cur_frm.doc.is_return ? null : grid_row.doc.warehouse
Neil Trini Lasrado3d61bbb2015-03-12 12:51:50 +053075 }
76 }
Rushabh Mehta62030e02013-08-14 18:37:28 +053077 }
78 },
79 {
80 "fieldtype": "Button",
Kanchan Chauhan69818702017-02-27 12:53:05 +053081 "fieldname": "add",
Pratik Vyasb52618c2014-04-14 16:25:30 +053082 "label": __("Add")
Rushabh Mehta62030e02013-08-14 18:37:28 +053083 }
84 ]
85 });
Rushabh Mehtac38fc712014-04-16 17:21:25 +053086
Rushabh Mehta62030e02013-08-14 18:37:28 +053087 d.get_input("add").on("click", function() {
88 var serial_no = d.get_value("serial_no");
89 if(serial_no) {
90 var val = (grid_row.doc.serial_no || "").split("\n").concat([serial_no]).join("\n");
akshay14384c22016-07-28 13:53:17 +053091 grid_row.grid_form.fields_dict.serial_no.set_model_value(val.trim());
Rushabh Mehta62030e02013-08-14 18:37:28 +053092 }
93 d.hide();
94 return false;
95 });
Rushabh Mehtac38fc712014-04-16 17:21:25 +053096
Rushabh Mehta62030e02013-08-14 18:37:28 +053097 d.show();
98 });
Rushabh Mehta5495bc52015-05-19 12:00:34 +053099 }
Rushabh Mehtac38fc712014-04-16 17:21:25 +0530100});
Rushabh Mehta7d368752014-11-24 14:16:47 +0530101
Nabin Haitb072c742014-12-16 12:49:13 +0530102
103$.extend(erpnext.utils, {
Rushabh Mehta559aa3a2016-09-19 16:04:58 +0530104 set_party_dashboard_indicators: function(frm) {
105 if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
106 var info = frm.doc.__onload.dashboard_info;
107 frm.dashboard.add_indicator(__('Annual Billing: {0}',
Rohit Waghchaurec857f372016-12-05 17:09:30 +0530108 [format_currency(info.billing_this_year, info.currency)]), 'blue');
Rushabh Mehta559aa3a2016-09-19 16:04:58 +0530109 frm.dashboard.add_indicator(__('Total Unpaid: {0}',
Rohit Waghchaurec857f372016-12-05 17:09:30 +0530110 [format_currency(info.total_unpaid, info.currency)]),
Rushabh Mehta559aa3a2016-09-19 16:04:58 +0530111 info.total_unpaid ? 'orange' : 'green');
112 }
113 },
114
Shreya Shah149f7ee2018-03-27 11:29:25 +0530115 get_party_name: function(party_type) {
116 var dict = {'Customer': 'customer_name', 'Supplier': 'supplier_name', 'Employee': 'employee_name',
117 'Member': 'member_name'};
118 return dict[party_type];
119 },
120
Rushabh Mehta49f97472018-08-30 18:50:48 +0530121 copy_value_in_all_rows: function(doc, dt, dn, table_fieldname, fieldname) {
Neil Trini Lasradofe2ffae2015-07-08 18:16:51 +0530122 var d = locals[dt][dn];
123 if(d[fieldname]){
124 var cl = doc[table_fieldname] || [];
125 for(var i = 0; i < cl.length; i++) {
126 if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname];
127 }
128 }
129 refresh_field(table_fieldname);
Makarand Bauskar157c3342017-05-26 21:32:33 +0530130 },
131
132 get_terms: function(tc_name, doc, callback) {
133 if(tc_name) {
134 return frappe.call({
135 method: 'erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions',
136 args: {
137 template_name: tc_name,
138 doc: doc
139 },
140 callback: function(r) {
141 callback(r)
142 }
143 });
144 }
tundebabzy1a947db2017-08-29 13:48:27 +0100145 },
146
rohitwaghchaure713cfc72018-09-11 17:40:37 +0530147 make_bank_account: function(doctype, docname) {
148 frappe.call({
149 method: "erpnext.accounts.doctype.bank_account.bank_account.make_bank_account",
150 args: {
151 doctype: doctype,
152 docname: docname
153 },
154 freeze: true,
155 callback: function(r) {
156 var doclist = frappe.model.sync(r.message);
157 frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
158 }
159 })
160 },
161
rohitwaghchaure166b78f2017-09-07 16:14:22 +0530162 make_subscription: function(doctype, docname) {
163 frappe.call({
rohitwaghchaure79e5b072018-06-21 12:58:14 +0530164 method: "frappe.desk.doctype.auto_repeat.auto_repeat.make_auto_repeat",
rohitwaghchaure166b78f2017-09-07 16:14:22 +0530165 args: {
166 doctype: doctype,
167 docname: docname
168 },
169 callback: function(r) {
170 var doclist = frappe.model.sync(r.message);
171 frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
172 }
173 })
174 },
175
tundebabzy1a947db2017-08-29 13:48:27 +0100176 /**
177 * Checks if the first row of a given child table is empty
178 * @param child_table - Child table Doctype
179 * @return {Boolean}
180 **/
181 first_row_is_empty: function(child_table){
182 if($.isArray(child_table) && child_table.length > 0) {
183 return !child_table[0].item_code;
184 }
185 return false;
186 },
187
188 /**
189 * Removes the first row of a child table if it is empty
190 * @param {_Frm} frm - The current form
191 * @param {String} child_table_name - The child table field name
192 * @return {Boolean}
193 **/
194 remove_empty_first_row: function(frm, child_table_name){
195 const rows = frm['doc'][child_table_name];
196 if (this.first_row_is_empty(rows)){
197 frm['doc'][child_table_name] = rows.splice(1);
198 }
199 return rows;
200 },
Zarrar6ffdf942018-06-14 12:24:16 +0530201 get_tree_options: function(option) {
202 // get valid options for tree based on user permission & locals dict
203 let unscrub_option = frappe.model.unscrub(option);
204 let user_permission = frappe.defaults.get_user_permissions();
205 if(user_permission && user_permission[unscrub_option]) {
206 return user_permission[unscrub_option]["docs"];
207 } else {
208 return $.map(locals[`:${unscrub_option}`], function(c) { return c.name; }).sort();
209 }
210 },
211 get_tree_default: function(option) {
212 // set default for a field based on user permission
213 let options = this.get_tree_options(option);
214 if(options.includes(frappe.defaults.get_default(option))) {
215 return frappe.defaults.get_default(option);
216 } else {
217 return options[0];
218 }
Sanjay Kumar1b49f3a2018-09-06 13:09:35 +0400219 },
220 copy_parent_value_in_all_row: function(doc, dt, dn, table_fieldname, fieldname, parent_fieldname) {
221 var d = locals[dt][dn];
222 if(d[fieldname]){
223 var cl = doc[table_fieldname] || [];
224 for(var i = 0; i < cl.length; i++) {
225 cl[i][fieldname] = doc[parent_fieldname];
226 }
227 }
228 refresh_field(table_fieldname);
229 },
230
Rushabh Mehta95b995b2015-05-28 12:10:55 +0530231});
232
rohitwaghchaurea3c3dec2018-03-28 11:51:44 +0530233erpnext.utils.select_alternate_items = function(opts) {
234 const frm = opts.frm;
235 const warehouse_field = opts.warehouse_field || 'warehouse';
236 const item_field = opts.item_field || 'item_code';
237
238 this.data = [];
239 const dialog = new frappe.ui.Dialog({
240 title: __("Select Alternate Item"),
241 fields: [
242 {fieldtype:'Section Break', label: __('Items')},
243 {
244 fieldname: "alternative_items", fieldtype: "Table", cannot_add_rows: true,
245 in_place_edit: true, data: this.data,
246 get_data: () => {
247 return this.data;
248 },
249 fields: [{
250 fieldtype:'Data',
251 fieldname:"docname",
252 hidden: 1
253 }, {
254 fieldtype:'Link',
255 fieldname:"item_code",
256 options: 'Item',
257 in_list_view: 1,
258 read_only: 1,
259 label: __('Item Code')
260 }, {
261 fieldtype:'Link',
262 fieldname:"alternate_item",
263 options: 'Item',
264 default: "",
265 in_list_view: 1,
266 label: __('Alternate Item'),
267 onchange: function() {
268 const item_code = this.get_value();
269 const warehouse = this.grid_row.on_grid_fields_dict.warehouse.get_value();
270 if (item_code && warehouse) {
271 frappe.call({
272 method: "erpnext.stock.utils.get_latest_stock_qty",
273 args: {
274 item_code: item_code,
275 warehouse: warehouse
276 },
277 callback: (r) => {
278 this.grid_row.on_grid_fields_dict
279 .actual_qty.set_value(r.message || 0);
280 }
281 })
282 }
283 },
284 get_query: (e) => {
285 return {
286 query: "erpnext.stock.doctype.item_alternative.item_alternative.get_alternative_items",
287 filters: {
288 item_code: e.item_code
289 }
290 };
291 }
292 }, {
293 fieldtype:'Link',
294 fieldname:"warehouse",
295 options: 'Warehouse',
296 default: "",
297 in_list_view: 1,
298 label: __('Warehouse'),
299 onchange: function() {
300 const warehouse = this.get_value();
301 const item_code = this.grid_row.on_grid_fields_dict.item_code.get_value();
302 if (item_code && warehouse) {
303 frappe.call({
304 method: "erpnext.stock.utils.get_latest_stock_qty",
305 args: {
306 item_code: item_code,
307 warehouse: warehouse
308 },
309 callback: (r) => {
310 this.grid_row.on_grid_fields_dict
311 .actual_qty.set_value(r.message || 0);
312 }
313 })
314 }
315 },
316 }, {
317 fieldtype:'Float',
318 fieldname:"actual_qty",
319 default: 0,
320 read_only: 1,
321 in_list_view: 1,
322 label: __('Available Qty')
323 }]
324 },
325 ],
326 primary_action: function() {
327 const args = this.get_values()["alternative_items"];
328 const alternative_items = args.filter(d => {
329 if (d.alternate_item && d.item_code != d.alternate_item) {
330 return true;
331 }
332 });
333
334 alternative_items.forEach(d => {
335 let row = frappe.get_doc(opts.child_doctype, d.docname);
Doridel Cahanape42192b2018-05-16 13:28:39 +0800336 let qty = null;
337 if (row.doctype === 'Work Order Item') {
338 qty = row.required_qty;
339 } else {
340 qty = row.qty;
341 }
rohitwaghchaurea3c3dec2018-03-28 11:51:44 +0530342 row[item_field] = d.alternate_item;
rohitwaghchaurea3c3dec2018-03-28 11:51:44 +0530343 frm.script_manager.trigger(item_field, row.doctype, row.name)
344 .then(() => {
345 frappe.model.set_value(row.doctype, row.name, 'qty', qty);
346 frappe.model.set_value(row.doctype, row.name,
347 opts.original_item_field, d.item_code);
348 });
349 });
350
351 refresh_field(opts.child_docname);
352 this.hide();
353 },
354 primary_action_label: __('Update')
355 });
356
357 frm.doc[opts.child_docname].forEach(d => {
358 if (!opts.condition || opts.condition(d)) {
359 dialog.fields_dict.alternative_items.df.data.push({
360 "docname": d.name,
361 "item_code": d[item_field],
362 "warehouse": d[warehouse_field],
363 "actual_qty": d.actual_qty
364 });
365 }
366 })
367
368 this.data = dialog.fields_dict.alternative_items.df.data;
369 dialog.fields_dict.alternative_items.grid.refresh();
370 dialog.show();
371}
372
Doridel Cahanap6f06cc22018-05-17 16:28:58 +0800373erpnext.utils.update_child_items = function(opts) {
374 const frm = opts.frm;
375
376 this.data = [];
377 const dialog = new frappe.ui.Dialog({
378 title: __("Update Items"),
379 fields: [
380 {fieldtype:'Section Break', label: __('Items')},
381 {
382 fieldname: "trans_items", fieldtype: "Table", cannot_add_rows: true,
383 in_place_edit: true, data: this.data,
384 get_data: () => {
385 return this.data;
386 },
387 fields: [{
388 fieldtype:'Data',
389 fieldname:"docname",
390 hidden: 0,
391 }, {
392 fieldtype:'Link',
393 fieldname:"item_code",
394 options: 'Item',
395 in_list_view: 1,
396 read_only: 1,
397 label: __('Item Code')
398 }, {
399 fieldtype:'Float',
400 fieldname:"qty",
401 default: 0,
402 read_only: 0,
403 in_list_view: 1,
404 label: __('Qty')
405 }, {
406 fieldtype:'Currency',
407 fieldname:"rate",
408 default: 0,
409 read_only: 0,
410 in_list_view: 1,
411 label: __('Rate')
412 }]
413 },
414 ],
415 primary_action: function() {
416 const trans_items = this.get_values()["trans_items"];
417 frappe.call({
418 method: 'erpnext.controllers.accounts_controller.update_child_qty_rate',
419 args: {
420 'parent_doctype': frm.doc.doctype,
421 'trans_items': trans_items,
422 'parent_doctype_name': frm.doc.name
423 },
424 callback: function() {
425 frm.reload_doc();
426 }
427 });
428 this.hide();
429 refresh_field("items");
430 },
431 primary_action_label: __('Update')
432 });
433
434 frm.doc[opts.child_docname].forEach(d => {
435 dialog.fields_dict.trans_items.df.data.push({
436 "docname": d.name,
437 "item_code": d.item_code,
438 "qty": d.qty,
439 "rate": d.rate,
440 });
441 this.data = dialog.fields_dict.trans_items.df.data;
442 dialog.fields_dict.trans_items.grid.refresh();
443 })
444 dialog.show();
445}
446
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530447erpnext.utils.map_current_doc = function(opts) {
448 if(opts.get_query_filters) {
449 opts.get_query = function() {
450 return {filters: opts.get_query_filters};
451 }
452 }
453 var _map = function() {
Rushabh Mehta55ea7b12016-07-15 16:43:25 +0530454 if($.isArray(cur_frm.doc.items) && cur_frm.doc.items.length > 0) {
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530455 // remove first item row if empty
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530456 if(!cur_frm.doc.items[0].item_code) {
457 cur_frm.doc.items = cur_frm.doc.items.splice(1);
458 }
bhupen3c7e70f2016-11-30 14:32:11 +0530459
460 // find the doctype of the items table
461 var items_doctype = frappe.meta.get_docfield(cur_frm.doctype, 'items').options;
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530462
bhupen3c7e70f2016-11-30 14:32:11 +0530463 // find the link fieldname from items table for the given
464 // source_doctype
465 var link_fieldname = null;
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530466 frappe.get_meta(items_doctype).fields.forEach(function(d) {
bhupen3c7e70f2016-11-30 14:32:11 +0530467 if(d.options===opts.source_doctype) link_fieldname = d.fieldname; });
468
Nabin Hait802b4352017-01-09 15:32:20 +0530469 // search in existing items if the source_name is already set and full qty fetched
bhupen3c7e70f2016-11-30 14:32:11 +0530470 var already_set = false;
Nabin Hait802b4352017-01-09 15:32:20 +0530471 var item_qty_map = {};
bhupen3c7e70f2016-11-30 14:32:11 +0530472
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530473 $.each(cur_frm.doc.items, function(i, d) {
474 opts.source_name.forEach(function(src) {
475 if(d[link_fieldname]==src) {
476 already_set = true;
477 if (item_qty_map[d.item_code])
478 item_qty_map[d.item_code] += flt(d.qty);
479 else
480 item_qty_map[d.item_code] = flt(d.qty);
481 }
482 });
483 });
484
485 if(already_set) {
486 opts.source_name.forEach(function(src) {
487 frappe.model.with_doc(opts.source_doctype, src, function(r) {
488 var source_doc = frappe.model.get_doc(opts.source_doctype, src);
489 $.each(source_doc.items || [], function(i, row) {
490 if(row.qty > flt(item_qty_map[row.item_code])) {
491 already_set = false;
492 return false;
493 }
494 })
495 })
496
497 if(already_set) {
498 frappe.msgprint(__("You have already selected items from {0} {1}",
499 [opts.source_doctype, src]));
500 return;
501 }
502
503 })
Nabin Hait802b4352017-01-09 15:32:20 +0530504 }
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530505 }
506
507 return frappe.call({
508 // Sometimes we hit the limit for URL length of a GET request
509 // as we send the full target_doc. Hence this is a POST request.
510 type: "POST",
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530511 method: 'frappe.model.mapper.map_docs',
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530512 args: {
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530513 "method": opts.method,
514 "source_names": opts.source_name,
515 "target_doc": cur_frm.doc,
Rushabh Mehta49f97472018-08-30 18:50:48 +0530516 'args': opts.args
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530517 },
518 callback: function(r) {
519 if(!r.exc) {
520 var doc = frappe.model.sync(r.message);
Vishal Dhayagudef06c2812017-12-26 16:22:40 +0530521 cur_frm.dirty();
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530522 cur_frm.refresh();
523 }
524 }
525 });
526 }
527 if(opts.source_doctype) {
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530528 var d = new frappe.ui.form.MultiSelectDialog({
529 doctype: opts.source_doctype,
530 target: opts.target,
531 date_field: opts.date_field || undefined,
532 setters: opts.setters,
533 get_query: opts.get_query,
534 action: function(selections, args) {
535 let values = selections;
536 if(values.length === 0){
Nabin Haita11dcb62017-12-04 13:36:50 +0530537 frappe.msgprint(__("Please select {0}", [opts.source_doctype]))
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530538 return;
539 }
540 opts.source_name = values;
541 opts.setters = args;
542 d.dialog.hide();
543 _map();
544 },
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530545 });
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530546 } else if(opts.source_name) {
Prateeksha Singhedeb4dc2017-05-15 11:32:06 +0530547 opts.source_name = [opts.source_name];
Rushabh Mehta176b63b2016-07-14 17:43:48 +0530548 _map();
549 }
550}
551
Rushabh Mehta180e4352016-07-26 17:57:42 +0530552frappe.form.link_formatters['Item'] = function(value, doc) {
Nabin Hait981f6ea2016-07-31 11:44:43 +0530553 if(doc && doc.item_name && doc.item_name !== value) {
mbauskarbe814422016-10-27 09:49:22 +0530554 return value? value + ': ' + doc.item_name: doc.item_name;
Rushabh Mehta180e4352016-07-26 17:57:42 +0530555 } else {
556 return value;
557 }
558}
559
560frappe.form.link_formatters['Employee'] = function(value, doc) {
Nabin Hait981f6ea2016-07-31 11:44:43 +0530561 if(doc && doc.employee_name && doc.employee_name !== value) {
mbauskarbe814422016-10-27 09:49:22 +0530562 return value? value + ': ' + doc.employee_name: doc.employee_name;
Rushabh Mehta180e4352016-07-26 17:57:42 +0530563 } else {
564 return value;
565 }
566}
567
Rushabh Mehta95b995b2015-05-28 12:10:55 +0530568// add description on posting time
569$(document).on('app_ready', function() {
570 if(!frappe.datetime.is_timezone_same()) {
571 $.each(["Stock Reconciliation", "Stock Entry", "Stock Ledger Entry",
572 "Delivery Note", "Purchase Receipt", "Sales Invoice"], function(i, d) {
573 frappe.ui.form.on(d, "onload", function(frm) {
574 cur_frm.set_df_property("posting_time", "description",
Faris Ansariab74ca72017-05-30 12:54:42 +0530575 frappe.sys_defaults.time_zone);
Rushabh Mehta95b995b2015-05-28 12:10:55 +0530576 });
577 });
578 }
akshay14384c22016-07-28 13:53:17 +0530579});