fix: Batch not getting fetched in Clinical Procedure Item

This commit is contained in:
Rucha Mahabal
2020-03-01 14:46:34 +05:30
parent d244ac9c3a
commit 7c5947f041

View File

@@ -8,17 +8,13 @@ frappe.ui.form.on('Clinical Procedure', {
if (!item.item_code) { if (!item.item_code) {
frappe.throw(__('Please enter Item Code to get Batch Number')); frappe.throw(__('Please enter Item Code to get Batch Number'));
} else { } else {
let filters = {'item_code': item.item_code};
if (frm.doc.status == 'In Progress') { if (frm.doc.status == 'In Progress') {
let filters = { filters['posting_date'] = frm.doc.start_date || frappe.datetime.nowdate();
'item_code': item.item_code,
'posting_date': frm.doc.start_date || frappe.datetime.nowdate()
};
if (frm.doc.warehouse) filters['warehouse'] = frm.doc.warehouse; if (frm.doc.warehouse) filters['warehouse'] = frm.doc.warehouse;
} else {
filters = {
'item_code': item.item_code
};
} }
return { return {
query : 'erpnext.controllers.queries.get_batch_no', query : 'erpnext.controllers.queries.get_batch_no',
filters: filters filters: filters
@@ -64,80 +60,78 @@ frappe.ui.form.on('Clinical Procedure', {
function(doc) { return (doc.qty<=doc.actual_qty) ? 'green' : 'orange' ; }); function(doc) { return (doc.qty<=doc.actual_qty) ? 'green' : 'orange' ; });
} }
if (frm.doc.docstatus == 2 && frm.doc.status == 'In Progress') { if (frm.doc.docstatus == 2) {
let btn_label = ''; if (frm.doc.status == 'In Progress') {
let msg = ''; let btn_label = '';
if (frm.doc.consume_stock) { let msg = '';
btn_label = 'Complete and Consume'; if (frm.doc.consume_stock) {
msg = 'Complete '+ frm.doc.name +' and Consume Stock?'; btn_label = __('Complete and Consume');
} else { msg = __('Complete {0} and Consume Stock?', [frm.doc.name]);
btn_label = 'Complete'; } else {
msg = 'Complete '+ frm.doc.name +'?'; btn_label = 'Complete';
} msg = __('Complete {0}?', [frm.doc.name]);
}
frm.add_custom_button(__(btn_label), function () { frm.add_custom_button(__(btn_label), function () {
frappe.confirm( frappe.confirm(
__(msg), msg,
function() { function() {
frappe.call({ frappe.call({
doc: frm.doc, doc: frm.doc,
method: 'complete', method: 'complete_procedure',
callback: function(r) { callback: function(r) {
if (!r.exc) { if (!r.exc) {
cur_frm.reload_doc();
}
}
});
}
);
});
} else if (frm.doc.status == 'Pending') {
frm.add_custom_button(__('Start'), function() {
frappe.call({
doc: frm.doc,
method: 'start_procedure',
callback: function(r) {
if (!r.exc) {
if (r.data.message == 'insufficient stock') {
frappe.confirm(
__('Stock quantity to start the procedure is not available in the warehouse. Do you want to record a Stock Transfer?'),
function() {
frappe.call({
doc: frm.doc,
method: 'make_material_transfer',
callback: function(r) {
if (!r.exc) {
cur_frm.reload_doc();
let doclist = frappe.model.sync(r.message);
frappe.set_route('Form', doclist[0].doctype, doclist[0].name);
}
}
});
}
);
} else {
cur_frm.reload_doc(); cur_frm.reload_doc();
} }
} }
});
}
);
});
} else if (frm.doc.docstatus == 2 && frm.doc.status == 'Pending') {
frm.add_custom_button(__('Start'), function () {
frappe.call({
doc: frm.doc,
method: 'start',
callback: function(r) {
if (!r.exc) {
if (frm.doc.status == 'Draft') {
frappe.confirm(
__('Stock quantity to start procedure is not available in the warehouse. Do you want to record a Stock Transfer'),
function() {
frappe.call({
doc: frm.doc,
method: 'make_material_transfer',
callback: function(r) {
if (!r.exc) {
cur_frm.reload_doc();
let doclist = frappe.model.sync(r.message);
frappe.set_route('Form', doclist[0].doctype, doclist[0].name);
}
}
});
}
);
} else {
cur_frm.reload_doc();
}
} }
} });
}); });
}); }
}
if (frm.doc.__islocal) {
frm.set_df_property('consumables', 'hidden', 1);
} else {
frm.set_df_property('consumables', 'hidden', 0);
} }
}, },
onload: function(frm) { onload: function(frm) {
if (frm.doc.status == 'Completed') {
frm.set_df_property('items', 'read_only', 1);
}
if (frm.is_new()) { if (frm.is_new()) {
frm.add_fetch('procedure_template', 'medical_department', 'medical_department'); frm.add_fetch('procedure_template', 'medical_department', 'medical_department');
frm.set_value('start_time', null); frm.set_value('start_time', null);
} }
}, },
patient: function(frm) { patient: function(frm) {
if (frm.doc.patient) { if (frm.doc.patient) {
frappe.call({ frappe.call({
@@ -149,10 +143,10 @@ frappe.ui.form.on('Clinical Procedure', {
let age = ''; let age = '';
if (data.message.dob) { if (data.message.dob) {
age = calculate_age(data.message.dob); age = calculate_age(data.message.dob);
}else if (data.message.age) { } else if (data.message.age) {
age = data.message.age; age = data.message.age;
if (data.message.age_as_on) { if (data.message.age_as_on) {
age = age+' as on '+data.message.age_as_on; age = __('{0} as on {1}', [age, data.message.age_as_on]);
} }
} }
frm.set_value('patient_age', age); frm.set_value('patient_age', age);
@@ -164,6 +158,7 @@ frappe.ui.form.on('Clinical Procedure', {
frm.set_value('patient_sex', ''); frm.set_value('patient_sex', '');
} }
}, },
appointment: function(frm) { appointment: function(frm) {
if (frm.doc.appointment) { if (frm.doc.appointment) {
frappe.call({ frappe.call({
@@ -184,6 +179,7 @@ frappe.ui.form.on('Clinical Procedure', {
}); });
} }
}, },
procedure_template: function(frm) { procedure_template: function(frm) {
if (frm.doc.procedure_template) { if (frm.doc.procedure_template) {
frappe.call({ frappe.call({
@@ -213,6 +209,7 @@ frappe.ui.form.on('Clinical Procedure', {
frm.set_value('consume_stock', 0); frm.set_value('consume_stock', 0);
} }
}, },
service_unit: function(frm) { service_unit: function(frm) {
if (frm.doc.service_unit) { if (frm.doc.service_unit) {
frappe.call({ frappe.call({
@@ -230,6 +227,7 @@ frappe.ui.form.on('Clinical Procedure', {
}); });
} }
}, },
practitioner: function(frm) { practitioner: function(frm) {
if (frm.doc.practitioner) { if (frm.doc.practitioner) {
frappe.call({ frappe.call({
@@ -254,14 +252,6 @@ cur_frm.set_query('procedure_template', function(doc) {
}; };
}); });
cur_frm.set_query('appointment', function() {
return {
filters: {
status:['in',['Open']]
}
};
});
frappe.ui.form.on('Clinical Procedure Item', { frappe.ui.form.on('Clinical Procedure Item', {
qty: function(frm, cdt, cdn) { qty: function(frm, cdt, cdn) {
let d = locals[cdt][cdn]; let d = locals[cdt][cdn];