From 2fb5291785acf9b1e33f2cf8ebe6a4fa2c9ab887 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 7 Jun 2021 21:20:33 +0530 Subject: [PATCH] fix: toggle consumed qty field based on condition --- .../doctype/purchase_receipt/purchase_receipt.js | 11 +++++++++-- .../doctype/purchase_receipt/purchase_receipt.py | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js index 887b15a211..cac6bf884b 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js @@ -41,8 +41,6 @@ frappe.ui.form.on("Purchase Receipt", { } }); - frm.set_df_property('supplied_items', 'cannot_add_rows', 1); - }, onload: function(frm) { erpnext.queries.setup_queries(frm, "Warehouse", function() { @@ -77,6 +75,15 @@ frappe.ui.form.on("Purchase Receipt", { } frm.events.add_custom_buttons(frm); + frm.trigger('toggle_subcontracting_fields'); + }, + + toggle_subcontracting_fields: function(frm) { + frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty', + 'read_only', frm.doc.__onload && frm.doc.__onload.backflush_based_on === 'BOM'); + + frm.set_df_property('supplied_items', 'cannot_add_rows', 1); + frm.set_df_property('supplied_items', 'cannot_delete_rows', 1); }, add_custom_buttons: function(frm) { diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index b8580f95a3..264561f376 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -102,6 +102,11 @@ class PurchaseReceipt(BuyingController): if self.get("items") and self.apply_putaway_rule and not self.get("is_return"): apply_putaway_rule(self.doctype, self.get("items"), self.company) + def onload(self): + super(PurchaseReceipt, self).onload() + self.set_onload("backflush_based_on", frappe.db.get_single_value('Buying Settings', + 'backflush_raw_materials_of_subcontract_based_on')) + def validate(self): self.validate_posting_time() super(PurchaseReceipt, self).validate()