blob: 54f0aadb1dd00342db94b4cd26ff7d24bcea3a87 [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();
Deepesh Gargcdc9b622023-07-23 22:44:18 +053012 this.frm.email_field = "contact_email";
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053013 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053014
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053015 onload(doc, cdt, cdn) {
16 this.setup_queries(doc, cdt, cdn);
17 super.onload();
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053018
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053019 this.frm.set_query('shipping_rule', function() {
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053020 return {
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053021 filters: {
22 "shipping_rule_type": "Buying"
23 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053024 };
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053025 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053026
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053027 if (this.frm.doc.__islocal
28 && frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")) {
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053029
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053030 var df = frappe.meta.get_docfield(this.frm.doc.doctype, "disable_rounded_total");
31 var disable = cint(df.default) || cint(frappe.sys_defaults.disable_rounded_total);
32 this.frm.set_value("disable_rounded_total", disable);
s-aga-r6d89b2f2022-06-18 15:46:59 +053033 }
34
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053035
36 // no idea where me is coming from
37 if(this.frm.get_field('shipping_address')) {
38 this.frm.set_query("shipping_address", function() {
39 if(me.frm.doc.customer) {
40 return {
41 query: 'frappe.contacts.doctype.address.address.address_query',
42 filters: { link_doctype: 'Customer', link_name: me.frm.doc.customer }
43 };
44 } else
45 return erpnext.queries.company_address_query(me.frm.doc)
46 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053047 }
Doridel Cahanap2b14d6a2018-11-13 14:37:16 +080048 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053049
50 setup_queries(doc, cdt, cdn) {
51 var me = this;
52
53 if(this.frm.fields_dict.buying_price_list) {
54 this.frm.set_query("buying_price_list", function() {
55 return{
56 filters: { 'buying': 1 }
57 }
58 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053059 }
Rohit Waghchaure3cf24362019-06-02 16:03:05 +053060
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053061 if(this.frm.fields_dict.tc_name) {
62 this.frm.set_query("tc_name", function() {
63 return{
64 filters: { 'buying': 1 }
65 }
66 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053067 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +053068
Deepesh Garg8ccb8e32023-07-23 18:50:44 +053069 me.frm.set_query('supplier', erpnext.queries.supplier);
70 me.frm.set_query('contact_person', erpnext.queries.contact_query);
71 me.frm.set_query('supplier_address', erpnext.queries.address_query);
72
73 me.frm.set_query('billing_address', erpnext.queries.company_address_query);
74 erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype);
75
76 if(this.frm.fields_dict.supplier) {
77 this.frm.set_query("supplier", function() {
78 return{ query: "erpnext.controllers.queries.supplier_query" }});
79 }
80
81 this.frm.set_query("item_code", "items", function() {
82 if (me.frm.doc.is_subcontracted) {
83 var filters = {'supplier': me.frm.doc.supplier};
84 if (me.frm.doc.is_old_subcontracting_flow) {
85 filters["is_sub_contracted_item"] = 1;
86 }
87 else {
88 filters["is_stock_item"] = 0;
89 }
90
91 return{
92 query: "erpnext.controllers.queries.item_query",
93 filters: filters
94 }
95 }
96 else {
97 return{
98 query: "erpnext.controllers.queries.item_query",
99 filters: { 'supplier': me.frm.doc.supplier, 'is_purchase_item': 1, 'has_variants': 0}
100 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530101 }
102 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530103
marination8a30cb22020-04-23 00:18:21 +0530104
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530105 this.frm.set_query("manufacturer", "items", function(doc, cdt, cdn) {
106 const row = locals[cdt][cdn];
107 return {
108 query: "erpnext.controllers.queries.item_manufacturer_query",
109 filters:{ 'item_code': row.item_code }
110 }
111 });
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530112
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530113 if(this.frm.fields_dict["items"].grid.get_field('item_code')) {
114 this.frm.set_query("item_tax_template", "items", function(doc, cdt, cdn) {
115 return me.set_query_for_item_tax_template(doc, cdt, cdn)
116 });
117 }
118 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530119
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530120 refresh(doc) {
121 frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'};
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530122
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530123 this.frm.toggle_display("supplier_name",
124 (this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier));
Deepesh Garg67600772020-06-13 22:40:23 +0530125
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530126 if(this.frm.doc.docstatus==0 &&
127 (this.frm.doctype==="Purchase Order" || this.frm.doctype==="Material Request")) {
128 this.set_from_product_bundle();
129 }
Charles-Henri Decultot8b223102018-06-28 10:57:58 +0200130
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530131 this.toggle_subcontracting_fields();
132 super.refresh();
133 }
134
135 toggle_subcontracting_fields() {
136 if (in_list(['Purchase Receipt', 'Purchase Invoice'], this.frm.doc.doctype)) {
137 this.frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty',
138 'read_only', this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === 'BOM');
139
140 this.frm.set_df_property('supplied_items', 'cannot_add_rows', 1);
141 this.frm.set_df_property('supplied_items', 'cannot_delete_rows', 1);
142 }
143 }
144
145 supplier() {
146 var me = this;
147 erpnext.utils.get_party_details(this.frm, null, null, function(){
148 me.apply_price_list();
149 });
150 }
151
152 supplier_address() {
153 erpnext.utils.get_address_display(this.frm);
154 erpnext.utils.set_taxes_from_address(this.frm, "supplier_address", "supplier_address", "supplier_address");
155 }
156
157 buying_price_list() {
158 this.apply_price_list();
159 }
160
161 discount_percentage(doc, cdt, cdn) {
162 var item = frappe.get_doc(cdt, cdn);
163 item.discount_amount = 0.0;
164 this.price_list_rate(doc, cdt, cdn);
165 }
166
167 discount_amount(doc, cdt, cdn) {
168 var item = frappe.get_doc(cdt, cdn);
169 item.discount_percentage = 0.0;
170 this.price_list_rate(doc, cdt, cdn);
171 }
172
173 qty(doc, cdt, cdn) {
174 if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) {
175 this.calculate_received_qty(doc, cdt, cdn)
176 }
177 super.qty(doc, cdt, cdn);
178 }
179
180 rejected_qty(doc, cdt, cdn) {
181 this.calculate_received_qty(doc, cdt, cdn)
182 }
183
184 calculate_received_qty(doc, cdt, cdn){
185 var item = frappe.get_doc(cdt, cdn);
186 frappe.model.round_floats_in(item, ["qty", "rejected_qty"]);
187
188 if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])){ return }
189
190 let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item));
191 let received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty);
192
193 frappe.model.set_value(cdt, cdn, "received_qty", received_qty);
194 frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty);
195 }
196
197 batch_no(doc, cdt, cdn) {
198 super.batch_no(doc, cdt, cdn);
199 }
200
201 validate_negative_quantity(cdt, cdn, item, fieldnames){
202 if(!item || !fieldnames) { return }
203
204 var is_negative_qty = false;
205 for(var i = 0; i<fieldnames.length; i++) {
206 if(item[fieldnames[i]] < 0){
207 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]));
208 is_negative_qty = true;
209 break;
Charles-Henri Decultot8b223102018-06-28 10:57:58 +0200210 }
211 }
Rohit Waghchaure3cf24362019-06-02 16:03:05 +0530212
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530213 return is_negative_qty
214 }
Rohit Waghchaure3cf24362019-06-02 16:03:05 +0530215
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530216 warehouse(doc, cdt, cdn) {
217 var item = frappe.get_doc(cdt, cdn);
218 if(item.item_code && item.warehouse) {
219 return this.frm.call({
220 method: "erpnext.stock.get_item_details.get_bin_details",
221 child: item,
222 args: {
223 item_code: item.item_code,
224 warehouse: item.warehouse,
225 company: doc.company,
226 include_child_warehouses: true
marination3e7a8ab2020-04-07 21:00:57 +0530227 }
Rohit Waghchaurebc75a7e2022-10-10 13:28:19 +0530228 });
229 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530230 }
Rohit Waghchauree6143ab2023-03-13 14:51:43 +0530231
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530232 project(doc, cdt, cdn) {
233 var item = frappe.get_doc(cdt, cdn);
234 if(item.project) {
235 $.each(this.frm.doc["items"] || [],
236 function(i, other_item) {
237 if(!other_item.project) {
238 other_item.project = item.project;
239 refresh_field("project", other_item.name, other_item.parentfield);
Rohit Waghchauree6143ab2023-03-13 14:51:43 +0530240 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530241 });
242 }
243 }
244
245 rejected_warehouse(doc, cdt) {
246 // trigger autofill_warehouse only if parent rejected_warehouse field is triggered
247 if (["Purchase Invoice", "Purchase Receipt"].includes(cdt)) {
248 this.autofill_warehouse(doc.items, "rejected_warehouse", doc.rejected_warehouse);
249 }
250 }
251
252 category(doc, cdt, cdn) {
253 // should be the category field of tax table
254 if(cdt != doc.doctype) {
255 this.calculate_taxes_and_totals();
256 }
257 }
258 add_deduct_tax(doc, cdt, cdn) {
259 this.calculate_taxes_and_totals();
260 }
261
262 set_from_product_bundle() {
263 var me = this;
264 this.frm.add_custom_button(__("Product Bundle"), function() {
265 erpnext.buying.get_items_from_product_bundle(me.frm);
266 }, __("Get Items From"));
267 }
268
269 shipping_address(){
270 var me = this;
271 erpnext.utils.get_address_display(this.frm, "shipping_address",
272 "shipping_address_display", true);
273 }
274
275 billing_address() {
276 erpnext.utils.get_address_display(this.frm, "billing_address",
277 "billing_address_display", true);
278 }
279
280 tc_name() {
281 this.get_terms();
282 }
283
284 update_auto_repeat_reference(doc) {
285 if (doc.auto_repeat) {
286 frappe.call({
287 method:"frappe.automation.doctype.auto_repeat.auto_repeat.update_reference",
288 args:{
289 docname: doc.auto_repeat,
290 reference:doc.name
291 },
292 callback: function(r){
293 if (r.message=="success") {
294 frappe.show_alert({message:__("Auto repeat document updated"), indicator:'green'});
295 } else {
296 frappe.show_alert({message:__("An error occurred during the update process"), indicator:'red'});
297 }
298 }
299 })
300 }
301 }
302
303 manufacturer(doc, cdt, cdn) {
304 const row = locals[cdt][cdn];
305
306 if(row.manufacturer) {
307 frappe.call({
308 method: "erpnext.stock.doctype.item_manufacturer.item_manufacturer.get_item_manufacturer_part_no",
309 args: {
310 'item_code': row.item_code,
311 'manufacturer': row.manufacturer
312 },
313 callback: function(r) {
314 if (r.message) {
315 frappe.model.set_value(cdt, cdn, 'manufacturer_part_no', r.message);
316 }
317 }
Rohit Waghchauree6143ab2023-03-13 14:51:43 +0530318 });
319 }
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530320 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530321
Deepesh Garg8ccb8e32023-07-23 18:50:44 +0530322 manufacturer_part_no(doc, cdt, cdn) {
323 const row = locals[cdt][cdn];
324
325 if (row.manufacturer_part_no) {
326 frappe.model.get_value('Item Manufacturer',
327 {
328 'item_code': row.item_code,
329 'manufacturer': row.manufacturer,
330 'manufacturer_part_no': row.manufacturer_part_no
331 },
332 'name',
333 function(data) {
334 if (!data) {
335 let msg = {
336 message: __("Manufacturer Part Number <b>{0}</b> is invalid", [row.manufacturer_part_no]),
337 title: __("Invalid Part Number")
338 }
339 frappe.throw(msg);
340 }
341 }
342 );
343 }
344 }
345
346 add_serial_batch_bundle(doc, cdt, cdn) {
347 let item = locals[cdt][cdn];
348 let me = this;
349 let path = "assets/erpnext/js/utils/serial_no_batch_selector.js";
350
351 frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
352 .then((r) => {
353 if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
354 item.has_serial_no = r.message.has_serial_no;
355 item.has_batch_no = r.message.has_batch_no;
356 item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
357 item.is_rejected = false;
358
359 frappe.require(path, function() {
360 new erpnext.SerialBatchPackageSelector(
361 me.frm, item, (r) => {
362 if (r) {
363 let update_values = {
364 "serial_and_batch_bundle": r.name,
365 "qty": Math.abs(r.total_qty)
366 }
367
368 if (r.warehouse) {
369 update_values["warehouse"] = r.warehouse;
370 }
371
372 frappe.model.set_value(item.doctype, item.name, update_values);
373 }
374 }
375 );
376 });
377 }
378 });
379 }
380
381 add_serial_batch_for_rejected_qty(doc, cdt, cdn) {
382 let item = locals[cdt][cdn];
383 let me = this;
384 let path = "assets/erpnext/js/utils/serial_no_batch_selector.js";
385
386 frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
387 .then((r) => {
388 if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
389 item.has_serial_no = r.message.has_serial_no;
390 item.has_batch_no = r.message.has_batch_no;
391 item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
392 item.is_rejected = true;
393
394 frappe.require(path, function() {
395 new erpnext.SerialBatchPackageSelector(
396 me.frm, item, (r) => {
397 if (r) {
398 let update_values = {
399 "serial_and_batch_bundle": r.name,
400 "rejected_qty": Math.abs(r.total_qty)
401 }
402
403 if (r.warehouse) {
404 update_values["rejected_warehouse"] = r.warehouse;
405 }
406
407 frappe.model.set_value(item.doctype, item.name, update_values);
408 }
409 }
410 );
411 });
412 }
413 });
414 }
415 };
416 }
417}
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530418
marinationa1196882020-09-24 15:22:46 +0530419erpnext.buying.link_to_mrs = function(frm) {
marinationa1196882020-09-24 15:22:46 +0530420 frappe.call({
421 method: "erpnext.buying.utils.get_linked_material_requests",
422 args:{
marination359778e2020-10-16 16:47:23 +0530423 items: frm.doc.items.map((item) => item.item_code)
marinationa1196882020-09-24 15:22:46 +0530424 },
425 callback: function(r) {
marination359778e2020-10-16 16:47:23 +0530426 if (!r.message || r.message.length == 0) {
427 frappe.throw({
428 message: __("No pending Material Requests found to link for the given items."),
429 title: __("Note")
430 });
marinationa1196882020-09-24 15:22:46 +0530431 }
marination359778e2020-10-16 16:47:23 +0530432
433 var item_length = frm.doc.items.length;
434 for (let item of frm.doc.items) {
435 var qty = item.qty;
436 (r.message[0] || []).forEach(function(d) {
437 if (d.qty > 0 && qty > 0 && item.item_code == d.item_code && !item.material_request_item)
438 {
439 item.material_request = d.mr_name;
440 item.material_request_item = d.mr_item;
441 var my_qty = Math.min(qty, d.qty);
442 qty = qty - my_qty;
443 d.qty = d.qty - my_qty;
444 item.stock_qty = my_qty*item.conversion_factor;
445 item.qty = my_qty;
446
447 frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + item.idx + ")");
448 if (qty > 0)
marinationa1196882020-09-24 15:22:46 +0530449 {
marination359778e2020-10-16 16:47:23 +0530450 frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
451 var newrow = frappe.model.add_child(frm.doc, item.doctype, "items");
452 item_length++;
marinationa1196882020-09-24 15:22:46 +0530453
marination359778e2020-10-16 16:47:23 +0530454 for (var key in item)
marinationa1196882020-09-24 15:22:46 +0530455 {
marination359778e2020-10-16 16:47:23 +0530456 newrow[key] = item[key];
marinationa1196882020-09-24 15:22:46 +0530457 }
marination359778e2020-10-16 16:47:23 +0530458
459 newrow.idx = item_length;
460 newrow["stock_qty"] = newrow.conversion_factor*qty;
461 newrow["qty"] = qty;
462
463 newrow["material_request"] = "";
464 newrow["material_request_item"] = "";
465
marinationa1196882020-09-24 15:22:46 +0530466 }
marination359778e2020-10-16 16:47:23 +0530467 }
468 });
marinationa1196882020-09-24 15:22:46 +0530469 }
marination359778e2020-10-16 16:47:23 +0530470 refresh_field("items");
marinationa1196882020-09-24 15:22:46 +0530471 }
472 });
473}
474
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530475erpnext.buying.get_default_bom = function(frm) {
476 $.each(frm.doc["items"] || [], function(i, d) {
477 if (d.item_code && d.bom === "") {
478 return frappe.call({
479 type: "GET",
480 method: "erpnext.stock.get_item_details.get_default_bom",
481 args: {
482 "item_code": d.item_code,
483 },
484 callback: function(r) {
485 if(r) {
486 frappe.model.set_value(d.doctype, d.name, "bom", r.message);
487 }
488 }
489 })
490 }
491 });
492}
493
494erpnext.buying.get_items_from_product_bundle = function(frm) {
495 var dialog = new frappe.ui.Dialog({
496 title: __("Get Items from Product Bundle"),
497 fields: [
498 {
499 "fieldtype": "Link",
500 "label": __("Product Bundle"),
501 "fieldname": "product_bundle",
502 "options":"Product Bundle",
503 "reqd": 1
504 },
505 {
506 "fieldtype": "Currency",
507 "label": __("Quantity"),
508 "fieldname": "quantity",
509 "reqd": 1,
510 "default": 1
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530511 }
Marica9942acd2020-04-21 13:13:39 +0530512 ],
513 primary_action_label: 'Get Items',
514 primary_action(args){
515 if(!args) return;
516 dialog.hide();
517 return frappe.call({
518 type: "GET",
519 method: "erpnext.stock.doctype.packed_item.packed_item.get_items_from_product_bundle",
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530520 args: {
marination4c677ea2022-01-25 23:52:52 +0530521 row: {
Marica9942acd2020-04-21 13:13:39 +0530522 item_code: args.product_bundle,
523 quantity: args.quantity,
524 parenttype: frm.doc.doctype,
525 parent: frm.doc.name,
526 supplier: frm.doc.supplier,
527 currency: frm.doc.currency,
528 conversion_rate: frm.doc.conversion_rate,
529 price_list: frm.doc.buying_price_list,
530 price_list_currency: frm.doc.price_list_currency,
531 plc_conversion_rate: frm.doc.plc_conversion_rate,
532 company: frm.doc.company,
533 is_subcontracted: frm.doc.is_subcontracted,
534 transaction_date: frm.doc.transaction_date || frm.doc.posting_date,
535 ignore_pricing_rule: frm.doc.ignore_pricing_rule,
536 doctype: frm.doc.doctype
tundebabzyf35710d2017-08-16 08:55:18 +0100537 }
Marica9942acd2020-04-21 13:13:39 +0530538 },
539 freeze: true,
540 callback: function(r) {
541 const first_row_is_empty = function(child_table){
542 if($.isArray(child_table) && child_table.length > 0) {
543 return !child_table[0].item_code;
544 }
545 return false;
546 };
tundebabzyf35710d2017-08-16 08:55:18 +0100547
Marica9942acd2020-04-21 13:13:39 +0530548 const remove_empty_first_row = function(frm){
549 if (first_row_is_empty(frm.doc.items)){
550 frm.doc.items = frm.doc.items.splice(1);
551 }
552 };
tundebabzyf35710d2017-08-16 08:55:18 +0100553
Marica9942acd2020-04-21 13:13:39 +0530554 if(!r.exc && r.message) {
555 remove_empty_first_row(frm);
Afshaneb4b2aa2020-09-01 15:01:32 +0530556 for (var i=0; i< r.message.length; i++) {
Marica9942acd2020-04-21 13:13:39 +0530557 var d = frm.add_child("items");
558 var item = r.message[i];
Afshaneb4b2aa2020-09-01 15:01:32 +0530559 for (var key in item) {
560 if (!is_null(item[key]) && key !== "doctype") {
Marica9942acd2020-04-21 13:13:39 +0530561 d[key] = item[key];
562 }
563 }
564 if(frappe.meta.get_docfield(d.doctype, "price_list_rate", d.name)) {
565 frm.script_manager.trigger("price_list_rate", d.doctype, d.name);
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530566 }
567 }
Marica9942acd2020-04-21 13:13:39 +0530568 frm.refresh_field("items");
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530569 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530570 }
Marica9942acd2020-04-21 13:13:39 +0530571 })
572 }
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530573 });
Marica9942acd2020-04-21 13:13:39 +0530574
Rushabh Mehtaf0b45622017-03-31 12:53:05 +0530575 dialog.show();
Faris Ansari1fe891b2021-04-23 08:04:00 +0530576}