fix: add requested changes

This commit is contained in:
Rohan Bansal 2021-05-26 14:42:15 +05:30
parent c5b074269a
commit 1cdf5a0dba
3 changed files with 144 additions and 9 deletions

View File

@ -508,7 +508,7 @@ def make_quality_inspections(doctype, docname, items):
inspections = []
for item in items:
if item.get("sample_size") > item.get("qty"):
if flt(item.get("sample_size")) > flt(item.get("qty")):
frappe.throw(_("{item_name}'s Sample Size ({sample_size}) cannot be greater than the Accepted Quantity ({accepted_quantity})").format(
item_name=item.get("item_name"),
sample_size=item.get("sample_size"),
@ -523,14 +523,14 @@ def make_quality_inspections(doctype, docname, items):
"reference_name": docname,
"item_code": item.get("item_code"),
"description": item.get("description"),
"sample_size": item.get("sample_size"),
"sample_size": flt(item.get("sample_size")),
"item_serial_no": item.get("serial_no").split("\n")[0] if item.get("serial_no") else None,
"batch_no": item.get("batch_no")
}).insert()
quality_inspection.save()
inspections.append(quality_inspection)
inspections.append(quality_inspection.name)
return [get_link_to_form("Quality Inspection", inspection.name) for inspection in inspections]
return inspections
def is_reposting_pending():

View File

@ -2039,11 +2039,16 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
},
freeze: true,
callback: function (r) {
if (r.message) {
frappe.msgprint({
message: __("Quality Inspections Created: {0}", [r.message.join(", ")]),
indicator: "green"
});
if (r.message.length > 0) {
if (r.message.length === 1) {
frappe.set_route("Form", "Quality Inspection", r.message[0]);
} else {
frappe.route_options = {
"reference_type": me.frm.doc.doctype,
"reference_name": me.frm.doc.name
};
frappe.set_route("List", "Quality Inspection");
}
}
dialog.hide();
}

View File

@ -115,6 +115,13 @@ frappe.ui.form.on('Stock Entry', {
return;
}
if (!frm.is_new() && frm.doc.docstatus === 0) {
frm.add_custom_button(__("Quality Inspection(s)"), () => {
frm.trigger("make_quality_inspection");
}, __("Create"));
frm.page.set_inner_btn_group_as_primary(__('Create'));
}
let quality_inspection_field = frm.get_docfield("items", "quality_inspection");
quality_inspection_field.get_route_options_for_new_doc = function(row) {
if (frm.is_new()) return;
@ -142,6 +149,129 @@ frappe.ui.form.on('Stock Entry', {
});
},
make_quality_inspection: function (frm) {
let data = [];
const fields = [
{
label: "Items",
fieldtype: "Table",
fieldname: "items",
cannot_add_rows: true,
in_place_edit: true,
data: data,
get_data: () => {
return data;
},
fields: [
{
fieldtype: "Data",
fieldname: "docname",
hidden: true
},
{
fieldtype: "Read Only",
fieldname: "item_code",
label: __("Item Code"),
in_list_view: true
},
{
fieldtype: "Read Only",
fieldname: "item_name",
label: __("Item Name"),
in_list_view: true
},
{
fieldtype: "Float",
fieldname: "qty",
label: __("Accepted Quantity"),
in_list_view: true,
read_only: true
},
{
fieldtype: "Float",
fieldname: "sample_size",
label: __("Sample Size"),
reqd: true,
in_list_view: true
},
{
fieldtype: "Data",
fieldname: "description",
label: __("Description"),
hidden: true
},
{
fieldtype: "Data",
fieldname: "serial_no",
label: __("Serial No"),
hidden: true
},
{
fieldtype: "Data",
fieldname: "batch_no",
label: __("Batch No"),
hidden: true
}
]
}
];
const dialog = new frappe.ui.Dialog({
title: __("Select Items for Quality Inspection"),
fields: fields,
primary_action: function () {
const data = dialog.get_values();
frappe.call({
method: "erpnext.controllers.stock_controller.make_quality_inspections",
args: {
doctype: frm.doc.doctype,
docname: frm.doc.name,
items: data
},
freeze: true,
callback: function (r) {
if (r.message.length > 0) {
if (r.message.length === 1) {
frappe.set_route("Form", "Quality Inspection", r.message[0]);
} else {
frappe.route_options = {
"reference_type": frm.doc.doctype,
"reference_name": frm.doc.name
};
frappe.set_route("List", "Quality Inspection");
}
}
dialog.hide();
}
});
},
primary_action_label: __("Create")
});
frm.doc.items.forEach(item => {
if (!item.quality_inspection) {
let dialog_items = dialog.fields_dict.items;
dialog_items.df.data.push({
"docname": item.name,
"item_code": item.item_code,
"item_name": item.item_name,
"qty": item.qty,
"description": item.description,
"serial_no": item.serial_no,
"batch_no": item.batch_no
});
dialog_items.grid.refresh();
}
});
data = dialog.fields_dict.items.df.data;
if (!data.length) {
frappe.msgprint(__("All items in this document already have a linked Quality Inspection."));
} else {
dialog.show();
}
},
outgoing_stock_entry: function(frm) {
frappe.call({
doc: frm.doc,