blob: 0860d9c667e78e7a152c280f4e9ca609aed2301d [file] [log] [blame]
Rushabh Mehtaf0b45622017-03-31 12:53:05 +05301// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2// License: GNU General Public License v3. See license.txt
3
4frappe.provide("erpnext.buying");
Deepesh Garg8ccb8e32023-07-23 18:50:44 +05305// cur_frm.add_fetch('project', 'cost_center', 'cost_center');
Rushabh Mehtaf0b45622017-03-31 12:53:05 +05306
Deepesh Garg8ccb8e32023-07-23 18:50:44 +05307erpnext.buying = {
8 setup_buying_controller: function() {
9 erpnext.buying.BuyingController = class BuyingController extends erpnext.TransactionController {
10 setup() {
11 super.setup();
rohitwaghchauredd4769e2023-09-20 18:09:03 +053012 this.toggle_enable_for_stock_uom("allow_to_edit_stock_uom_qty_for_purchase");
Deepesh Gargcdc9b622023-07-23 22:44:18 +053013 this.frm.email_field = "contact_email";
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053014 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053015
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053016 onload(doc, cdt, cdn) {
17 this.setup_queries(doc, cdt, cdn);
18 super.onload();
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053019
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053020 this.frm.set_query('shipping_rule', function() {
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053021 return {
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053022 filters: {
23 "shipping_rule_type": "Buying"
24 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053025 };
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053026 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053027
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053028 if (this.frm.doc.__islocal
29 && frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")) {
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053030
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053031 var df = frappe.meta.get_docfield(this.frm.doc.doctype, "disable_rounded_total");
32 var disable = cint(df.default) || cint(frappe.sys_defaults.disable_rounded_total);
33 this.frm.set_value("disable_rounded_total", disable);
s-aga-r6d89b2f2022-06-18 15:46:59 +053034 }
35
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053036
37 // no idea where me is coming from
38 if(this.frm.get_field('shipping_address')) {
39 this.frm.set_query("shipping_address", function() {
40 if(me.frm.doc.customer) {
41 return {
42 query: 'frappe.contacts.doctype.address.address.address_query',
43 filters: { link_doctype: 'Customer', link_name: me.frm.doc.customer }
44 };
45 } else
46 return erpnext.queries.company_address_query(me.frm.doc)
47 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053048 }
Doridel Cahanap2b14d6a2018-11-13 14:37:16 +080049 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053050
51 setup_queries(doc, cdt, cdn) {
52 var me = this;
53
54 if(this.frm.fields_dict.buying_price_list) {
55 this.frm.set_query("buying_price_list", function() {
56 return{
57 filters: { 'buying': 1 }
58 }
59 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053060 }
Rohit Waghchaure3cf24362019-06-02 16:03:05 +053061
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053062 if(this.frm.fields_dict.tc_name) {
63 this.frm.set_query("tc_name", function() {
64 return{
65 filters: { 'buying': 1 }
66 }
67 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053068 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053069
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053070 me.frm.set_query('supplier', erpnext.queries.supplier);
71 me.frm.set_query('contact_person', erpnext.queries.contact_query);
72 me.frm.set_query('supplier_address', erpnext.queries.address_query);
73
74 me.frm.set_query('billing_address', erpnext.queries.company_address_query);
75 erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype);
76
77 if(this.frm.fields_dict.supplier) {
78 this.frm.set_query("supplier", function() {
79 return{ query: "erpnext.controllers.queries.supplier_query" }});
80 }
81
82 this.frm.set_query("item_code", "items", function() {
83 if (me.frm.doc.is_subcontracted) {
84 var filters = {'supplier': me.frm.doc.supplier};
85 if (me.frm.doc.is_old_subcontracting_flow) {
86 filters["is_sub_contracted_item"] = 1;
87 }
88 else {
89 filters["is_stock_item"] = 0;
90 }
91
92 return{
93 query: "erpnext.controllers.queries.item_query",
94 filters: filters
95 }
96 }
97 else {
98 return{
99 query: "erpnext.controllers.queries.item_query",
100 filters: { 'supplier': me.frm.doc.supplier, 'is_purchase_item': 1, 'has_variants': 0}
101 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530102 }
103 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530104
marination8a30cb22020-04-23 00:18:21 +0530105
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530106 this.frm.set_query("manufacturer", "items", function(doc, cdt, cdn) {
107 const row = locals[cdt][cdn];
108 return {
109 query: "erpnext.controllers.queries.item_manufacturer_query",
110 filters:{ 'item_code': row.item_code }
111 }
112 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530113
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530114 if(this.frm.fields_dict["items"].grid.get_field('item_code')) {
115 this.frm.set_query("item_tax_template", "items", function(doc, cdt, cdn) {
116 return me.set_query_for_item_tax_template(doc, cdt, cdn)
117 });
118 }
119 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530120
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530121 refresh(doc) {
122 frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'};
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530123
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530124 this.frm.toggle_display("supplier_name",
125 (this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier));
Deepesh Garg67600772020-06-13 22:40:23 +0530126
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530127 if(this.frm.doc.docstatus==0 &&
128 (this.frm.doctype==="Purchase Order" || this.frm.doctype==="Material Request")) {
129 this.set_from_product_bundle();
130 }
Charles-Henri Decultot8b223102018-06-28 10:57:58 +0200131
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530132 this.toggle_subcontracting_fields();
133 super.refresh();
134 }
135
136 toggle_subcontracting_fields() {
137 if (in_list(['Purchase Receipt', 'Purchase Invoice'], this.frm.doc.doctype)) {
138 this.frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty',
139 'read_only', this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === 'BOM');
140
141 this.frm.set_df_property('supplied_items', 'cannot_add_rows', 1);
142 this.frm.set_df_property('supplied_items', 'cannot_delete_rows', 1);
143 }
144 }
145
146 supplier() {
147 var me = this;
148 erpnext.utils.get_party_details(this.frm, null, null, function(){
149 me.apply_price_list();
150 });
151 }
152
153 supplier_address() {
154 erpnext.utils.get_address_display(this.frm);
155 erpnext.utils.set_taxes_from_address(this.frm, "supplier_address", "supplier_address", "supplier_address");
156 }
157
158 buying_price_list() {
159 this.apply_price_list();
160 }
161
162 discount_percentage(doc, cdt, cdn) {
163 var item = frappe.get_doc(cdt, cdn);
164 item.discount_amount = 0.0;
165 this.price_list_rate(doc, cdt, cdn);
166 }
167
168 discount_amount(doc, cdt, cdn) {
169 var item = frappe.get_doc(cdt, cdn);
170 item.discount_percentage = 0.0;
171 this.price_list_rate(doc, cdt, cdn);
172 }
173
174 qty(doc, cdt, cdn) {
175 if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) {
176 this.calculate_received_qty(doc, cdt, cdn)
177 }
178 super.qty(doc, cdt, cdn);
179 }
180
181 rejected_qty(doc, cdt, cdn) {
182 this.calculate_received_qty(doc, cdt, cdn)
183 }
184
185 calculate_received_qty(doc, cdt, cdn){
186 var item = frappe.get_doc(cdt, cdn);
187 frappe.model.round_floats_in(item, ["qty", "rejected_qty"]);
188
189 if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])){ return }
190
191 let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item));
192 let received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty);
193
194 frappe.model.set_value(cdt, cdn, "received_qty", received_qty);
195 frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty);
196 }
197
198 batch_no(doc, cdt, cdn) {
199 super.batch_no(doc, cdt, cdn);
200 }
201
202 validate_negative_quantity(cdt, cdn, item, fieldnames){
203 if(!item || !fieldnames) { return }
204
205 var is_negative_qty = false;
206 for(var i = 0; i<fieldnames.length; i++) {
207 if(item[fieldnames[i]] < 0){
208 frappe.msgprint(__("Row #{0}: {1} can not be negative for item {2}", [item.idx,__(frappe.meta.get_label(cdt, fieldnames[i], cdn)), item.item_code]));
209 is_negative_qty = true;
210 break;
Charles-Henri Decultot8b223102018-06-28 10:57:58 +0200211 }
212 }
Rohit Waghchaure3cf24362019-06-02 16:03:05 +0530213
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530214 return is_negative_qty
215 }
Rohit Waghchaure3cf24362019-06-02 16:03:05 +0530216
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530217 warehouse(doc, cdt, cdn) {
218 var item = frappe.get_doc(cdt, cdn);
219 if(item.item_code && item.warehouse) {
220 return this.frm.call({
221 method: "erpnext.stock.get_item_details.get_bin_details",
222 child: item,
223 args: {
224 item_code: item.item_code,
225 warehouse: item.warehouse,
226 company: doc.company,
227 include_child_warehouses: true
marination3e7a8ab2020-04-07 21:00:57 +0530228 }
Rohit Waghchaurebc75a7e2022-10-10 13:28:19 +0530229 });
230 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530231 }
Rohit Waghchauree6143ab2023-03-13 14:51:43 +0530232
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530233 project(doc, cdt, cdn) {
234 var item = frappe.get_doc(cdt, cdn);
235 if(item.project) {
236 $.each(this.frm.doc["items"] || [],
237 function(i, other_item) {
238 if(!other_item.project) {
239 other_item.project = item.project;
240 refresh_field("project", other_item.name, other_item.parentfield);
Rohit Waghchauree6143ab2023-03-13 14:51:43 +0530241 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530242 });
243 }
244 }
245
246 rejected_warehouse(doc, cdt) {
247 // trigger autofill_warehouse only if parent rejected_warehouse field is triggered
248 if (["Purchase Invoice", "Purchase Receipt"].includes(cdt)) {
249 this.autofill_warehouse(doc.items, "rejected_warehouse", doc.rejected_warehouse);
250 }
251 }
252
253 category(doc, cdt, cdn) {
254 // should be the category field of tax table
255 if(cdt != doc.doctype) {
256 this.calculate_taxes_and_totals();
257 }
258 }
259 add_deduct_tax(doc, cdt, cdn) {
260 this.calculate_taxes_and_totals();
261 }
262
263 set_from_product_bundle() {
264 var me = this;
265 this.frm.add_custom_button(__("Product Bundle"), function() {
266 erpnext.buying.get_items_from_product_bundle(me.frm);
267 }, __("Get Items From"));
268 }
269
270 shipping_address(){
271 var me = this;
272 erpnext.utils.get_address_display(this.frm, "shipping_address",
273 "shipping_address_display", true);
274 }
275
276 billing_address() {
277 erpnext.utils.get_address_display(this.frm, "billing_address",
278 "billing_address_display", true);
279 }
280
281 tc_name() {
282 this.get_terms();
283 }
284
285 update_auto_repeat_reference(doc) {
286 if (doc.auto_repeat) {
287 frappe.call({
288 method:"frappe.automation.doctype.auto_repeat.auto_repeat.update_reference",
289 args:{
290 docname: doc.auto_repeat,
291 reference:doc.name
292 },
293 callback: function(r){
294 if (r.message=="success") {
295 frappe.show_alert({message:__("Auto repeat document updated"), indicator:'green'});
296 } else {
297 frappe.show_alert({message:__("An error occurred during the update process"), indicator:'red'});
298 }
299 }
300 })
301 }
302 }
303
304 manufacturer(doc, cdt, cdn) {
305 const row = locals[cdt][cdn];
306
307 if(row.manufacturer) {
308 frappe.call({
309 method: "erpnext.stock.doctype.item_manufacturer.item_manufacturer.get_item_manufacturer_part_no",
310 args: {
311 'item_code': row.item_code,
312 'manufacturer': row.manufacturer
313 },
314 callback: function(r) {
315 if (r.message) {
316 frappe.model.set_value(cdt, cdn, 'manufacturer_part_no', r.message);
317 }
318 }
Rohit Waghchauree6143ab2023-03-13 14:51:43 +0530319 });
320 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530321 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530322
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530323 manufacturer_part_no(doc, cdt, cdn) {
324 const row = locals[cdt][cdn];
325
326 if (row.manufacturer_part_no) {
327 frappe.model.get_value('Item Manufacturer',
328 {
329 'item_code': row.item_code,
330 'manufacturer': row.manufacturer,
331 'manufacturer_part_no': row.manufacturer_part_no
332 },
333 'name',
334 function(data) {
335 if (!data) {
336 let msg = {
337 message: __("Manufacturer Part Number <b>{0}</b> is invalid", [row.manufacturer_part_no]),
338 title: __("Invalid Part Number")
339 }
340 frappe.throw(msg);
341 }
342 }
343 );
344 }
345 }
346
347 add_serial_batch_bundle(doc, cdt, cdn) {
348 let item = locals[cdt][cdn];
349 let me = this;
350 let path = "assets/erpnext/js/utils/serial_no_batch_selector.js";
351
352 frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
353 .then((r) => {
354 if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
355 item.has_serial_no = r.message.has_serial_no;
356 item.has_batch_no = r.message.has_batch_no;
357 item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
358 item.is_rejected = false;
359
360 frappe.require(path, function() {
361 new erpnext.SerialBatchPackageSelector(
362 me.frm, item, (r) => {
363 if (r) {
364 let update_values = {
365 "serial_and_batch_bundle": r.name,
366 "qty": Math.abs(r.total_qty)
367 }
368
369 if (r.warehouse) {
370 update_values["warehouse"] = r.warehouse;
371 }
372
373 frappe.model.set_value(item.doctype, item.name, update_values);
374 }
375 }
376 );
377 });
378 }
379 });
380 }
381
382 add_serial_batch_for_rejected_qty(doc, cdt, cdn) {
383 let item = locals[cdt][cdn];
384 let me = this;
385 let path = "assets/erpnext/js/utils/serial_no_batch_selector.js";
386
387 frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
388 .then((r) => {
389 if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
390 item.has_serial_no = r.message.has_serial_no;
391 item.has_batch_no = r.message.has_batch_no;
392 item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
393 item.is_rejected = true;
394
395 frappe.require(path, function() {
396 new erpnext.SerialBatchPackageSelector(
397 me.frm, item, (r) => {
398 if (r) {
399 let update_values = {
400 "serial_and_batch_bundle": r.name,
401 "rejected_qty": Math.abs(r.total_qty)
402 }
403
404 if (r.warehouse) {
405 update_values["rejected_warehouse"] = r.warehouse;
406 }
407
408 frappe.model.set_value(item.doctype, item.name, update_values);
409 }
410 }
411 );
412 });
413 }
414 });
415 }
416 };
417 }
418}
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530419
marinationa1196882020-09-24 15:22:46 +0530420erpnext.buying.link_to_mrs = function(frm) {
marinationa1196882020-09-24 15:22:46 +0530421 frappe.call({
422 method: "erpnext.buying.utils.get_linked_material_requests",
423 args:{
marination359778e2020-10-16 16:47:23 +0530424 items: frm.doc.items.map((item) => item.item_code)
marinationa1196882020-09-24 15:22:46 +0530425 },
426 callback: function(r) {
marination359778e2020-10-16 16:47:23 +0530427 if (!r.message || r.message.length == 0) {
428 frappe.throw({
429 message: __("No pending Material Requests found to link for the given items."),
430 title: __("Note")
431 });
marinationa1196882020-09-24 15:22:46 +0530432 }
marination359778e2020-10-16 16:47:23 +0530433
434 var item_length = frm.doc.items.length;
435 for (let item of frm.doc.items) {
436 var qty = item.qty;
437 (r.message[0] || []).forEach(function(d) {
438 if (d.qty > 0 && qty > 0 && item.item_code == d.item_code && !item.material_request_item)
439 {
440 item.material_request = d.mr_name;
441 item.material_request_item = d.mr_item;
442 var my_qty = Math.min(qty, d.qty);
443 qty = qty - my_qty;
444 d.qty = d.qty - my_qty;
445 item.stock_qty = my_qty*item.conversion_factor;
446 item.qty = my_qty;
447
448 frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + item.idx + ")");
449 if (qty > 0)
marinationa1196882020-09-24 15:22:46 +0530450 {
marination359778e2020-10-16 16:47:23 +0530451 frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
452 var newrow = frappe.model.add_child(frm.doc, item.doctype, "items");
453 item_length++;
marinationa1196882020-09-24 15:22:46 +0530454
marination359778e2020-10-16 16:47:23 +0530455 for (var key in item)
marinationa1196882020-09-24 15:22:46 +0530456 {
marination359778e2020-10-16 16:47:23 +0530457 newrow[key] = item[key];
marinationa1196882020-09-24 15:22:46 +0530458 }
marination359778e2020-10-16 16:47:23 +0530459
460 newrow.idx = item_length;
461 newrow["stock_qty"] = newrow.conversion_factor*qty;
462 newrow["qty"] = qty;
463
464 newrow["material_request"] = "";
465 newrow["material_request_item"] = "";
466
marinationa1196882020-09-24 15:22:46 +0530467 }
marination359778e2020-10-16 16:47:23 +0530468 }
469 });
marinationa1196882020-09-24 15:22:46 +0530470 }
marination359778e2020-10-16 16:47:23 +0530471 refresh_field("items");
marinationa1196882020-09-24 15:22:46 +0530472 }
473 });
474}
475
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530476erpnext.buying.get_default_bom = function(frm) {
477 $.each(frm.doc["items"] || [], function(i, d) {
478 if (d.item_code && d.bom === "") {
479 return frappe.call({
480 type: "GET",
481 method: "erpnext.stock.get_item_details.get_default_bom",
482 args: {
483 "item_code": d.item_code,
484 },
485 callback: function(r) {
486 if(r) {
487 frappe.model.set_value(d.doctype, d.name, "bom", r.message);
488 }
489 }
490 })
491 }
492 });
493}
494
495erpnext.buying.get_items_from_product_bundle = function(frm) {
496 var dialog = new frappe.ui.Dialog({
497 title: __("Get Items from Product Bundle"),
498 fields: [
499 {
500 "fieldtype": "Link",
501 "label": __("Product Bundle"),
502 "fieldname": "product_bundle",
503 "options":"Product Bundle",
504 "reqd": 1
505 },
506 {
507 "fieldtype": "Currency",
508 "label": __("Quantity"),
509 "fieldname": "quantity",
510 "reqd": 1,
511 "default": 1
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530512 }
Marica9942acd2020-04-21 13:13:39 +0530513 ],
514 primary_action_label: 'Get Items',
515 primary_action(args){
516 if(!args) return;
517 dialog.hide();
518 return frappe.call({
519 type: "GET",
520 method: "erpnext.stock.doctype.packed_item.packed_item.get_items_from_product_bundle",
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530521 args: {
marination4c677ea2022-01-25 23:52:52 +0530522 row: {
Marica9942acd2020-04-21 13:13:39 +0530523 item_code: args.product_bundle,
524 quantity: args.quantity,
525 parenttype: frm.doc.doctype,
526 parent: frm.doc.name,
527 supplier: frm.doc.supplier,
528 currency: frm.doc.currency,
529 conversion_rate: frm.doc.conversion_rate,
530 price_list: frm.doc.buying_price_list,
531 price_list_currency: frm.doc.price_list_currency,
532 plc_conversion_rate: frm.doc.plc_conversion_rate,
533 company: frm.doc.company,
534 is_subcontracted: frm.doc.is_subcontracted,
535 transaction_date: frm.doc.transaction_date || frm.doc.posting_date,
536 ignore_pricing_rule: frm.doc.ignore_pricing_rule,
537 doctype: frm.doc.doctype
tundebabzyf35710d2017-08-16 08:55:18 +0100538 }
Marica9942acd2020-04-21 13:13:39 +0530539 },
540 freeze: true,
541 callback: function(r) {
542 const first_row_is_empty = function(child_table){
543 if($.isArray(child_table) && child_table.length > 0) {
544 return !child_table[0].item_code;
545 }
546 return false;
547 };
tundebabzyf35710d2017-08-16 08:55:18 +0100548
Marica9942acd2020-04-21 13:13:39 +0530549 const remove_empty_first_row = function(frm){
550 if (first_row_is_empty(frm.doc.items)){
551 frm.doc.items = frm.doc.items.splice(1);
552 }
553 };
tundebabzyf35710d2017-08-16 08:55:18 +0100554
Marica9942acd2020-04-21 13:13:39 +0530555 if(!r.exc && r.message) {
556 remove_empty_first_row(frm);
Afshaneb4b2aa2020-09-01 15:01:32 +0530557 for (var i=0; i< r.message.length; i++) {
Marica9942acd2020-04-21 13:13:39 +0530558 var d = frm.add_child("items");
559 var item = r.message[i];
Afshaneb4b2aa2020-09-01 15:01:32 +0530560 for (var key in item) {
561 if (!is_null(item[key]) && key !== "doctype") {
Marica9942acd2020-04-21 13:13:39 +0530562 d[key] = item[key];
563 }
564 }
565 if(frappe.meta.get_docfield(d.doctype, "price_list_rate", d.name)) {
566 frm.script_manager.trigger("price_list_rate", d.doctype, d.name);
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530567 }
568 }
Marica9942acd2020-04-21 13:13:39 +0530569 frm.refresh_field("items");
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530570 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530571 }
Marica9942acd2020-04-21 13:13:39 +0530572 })
573 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530574 });
Marica9942acd2020-04-21 13:13:39 +0530575
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530576 dialog.show();
Faris Ansari1fe891b2021-04-23 08:04:00 +0530577}