fix: toggle consumed qty field based on condition

This commit is contained in:
Rohit Waghchaure 2021-06-07 21:20:33 +05:30
parent 9a2db0b5b1
commit 2fb5291785
2 changed files with 14 additions and 2 deletions

View File

@ -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) {

View File

@ -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()