fix [ux]: Material Request Form Cleanup and UX (#20810)

* fix (ux): Material Request Form Cleanup

* fix: Get Items from popup UX

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
Marica
2020-04-21 13:13:39 +05:30
committed by GitHub
parent 27c6f69435
commit 9942acd9d4
6 changed files with 161 additions and 120 deletions

View File

@@ -444,75 +444,69 @@ erpnext.buying.get_items_from_product_bundle = function(frm) {
"fieldname": "quantity", "fieldname": "quantity",
"reqd": 1, "reqd": 1,
"default": 1 "default": 1
},
{
"fieldtype": "Button",
"label": __("Get Items"),
"fieldname": "get_items",
"cssClass": "btn-primary"
} }
] ],
}); primary_action_label: 'Get Items',
primary_action(args){
dialog.fields_dict.get_items.$input.click(function() { if(!args) return;
var args = dialog.get_values(); dialog.hide();
if(!args) return; return frappe.call({
dialog.hide(); type: "GET",
return frappe.call({ method: "erpnext.stock.doctype.packed_item.packed_item.get_items_from_product_bundle",
type: "GET",
method: "erpnext.stock.doctype.packed_item.packed_item.get_items_from_product_bundle",
args: {
args: { args: {
item_code: args.product_bundle, args: {
quantity: args.quantity, item_code: args.product_bundle,
parenttype: frm.doc.doctype, quantity: args.quantity,
parent: frm.doc.name, parenttype: frm.doc.doctype,
supplier: frm.doc.supplier, parent: frm.doc.name,
currency: frm.doc.currency, supplier: frm.doc.supplier,
conversion_rate: frm.doc.conversion_rate, currency: frm.doc.currency,
price_list: frm.doc.buying_price_list, conversion_rate: frm.doc.conversion_rate,
price_list_currency: frm.doc.price_list_currency, price_list: frm.doc.buying_price_list,
plc_conversion_rate: frm.doc.plc_conversion_rate, price_list_currency: frm.doc.price_list_currency,
company: frm.doc.company, plc_conversion_rate: frm.doc.plc_conversion_rate,
is_subcontracted: frm.doc.is_subcontracted, company: frm.doc.company,
transaction_date: frm.doc.transaction_date || frm.doc.posting_date, is_subcontracted: frm.doc.is_subcontracted,
ignore_pricing_rule: frm.doc.ignore_pricing_rule, transaction_date: frm.doc.transaction_date || frm.doc.posting_date,
doctype: frm.doc.doctype ignore_pricing_rule: frm.doc.ignore_pricing_rule,
} doctype: frm.doc.doctype
},
freeze: true,
callback: function(r) {
const first_row_is_empty = function(child_table){
if($.isArray(child_table) && child_table.length > 0) {
return !child_table[0].item_code;
} }
return false; },
}; freeze: true,
callback: function(r) {
const first_row_is_empty = function(child_table){
if($.isArray(child_table) && child_table.length > 0) {
return !child_table[0].item_code;
}
return false;
};
const remove_empty_first_row = function(frm){ const remove_empty_first_row = function(frm){
if (first_row_is_empty(frm.doc.items)){ if (first_row_is_empty(frm.doc.items)){
frm.doc.items = frm.doc.items.splice(1); frm.doc.items = frm.doc.items.splice(1);
} }
}; };
if(!r.exc && r.message) { if(!r.exc && r.message) {
remove_empty_first_row(frm); remove_empty_first_row(frm);
for ( var i=0; i< r.message.length; i++ ) { for ( var i=0; i< r.message.length; i++ ) {
var d = frm.add_child("items"); var d = frm.add_child("items");
var item = r.message[i]; var item = r.message[i];
for ( var key in item) { for ( var key in item) {
if ( !is_null(item[key]) ) { if ( !is_null(item[key]) ) {
d[key] = item[key]; d[key] = item[key];
}
}
if(frappe.meta.get_docfield(d.doctype, "price_list_rate", d.name)) {
frm.script_manager.trigger("price_list_rate", d.doctype, d.name);
} }
} }
if(frappe.meta.get_docfield(d.doctype, "price_list_rate", d.name)) { frm.refresh_field("items");
frm.script_manager.trigger("price_list_rate", d.doctype, d.name);
}
} }
frm.refresh_field("items");
} }
} })
}) }
}); });
dialog.show(); dialog.show();
} }

View File

@@ -85,7 +85,7 @@ def make_custom_fields(update=True):
hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC', hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description', fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description',
allow_on_submit=1, print_hide=1, fetch_if_empty=1) allow_on_submit=1, print_hide=1, fetch_if_empty=1)
nil_rated_exempt = dict(fieldname='is_nil_exempt', label='Is nil rated or exempted', nil_rated_exempt = dict(fieldname='is_nil_exempt', label='Is Nil Rated or Exempted',
fieldtype='Check', fetch_from='item_code.is_nil_exempt', insert_after='gst_hsn_code', fieldtype='Check', fetch_from='item_code.is_nil_exempt', insert_after='gst_hsn_code',
print_hide=1) print_hide=1)
is_non_gst = dict(fieldname='is_non_gst', label='Is Non GST', is_non_gst = dict(fieldname='is_non_gst', label='Is Non GST',
@@ -388,7 +388,7 @@ def make_custom_fields(update=True):
'Item': [ 'Item': [
dict(fieldname='gst_hsn_code', label='HSN/SAC', dict(fieldname='gst_hsn_code', label='HSN/SAC',
fieldtype='Link', options='GST HSN Code', insert_after='item_group'), fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
dict(fieldname='is_nil_exempt', label='Is nil rated or exempted', dict(fieldname='is_nil_exempt', label='Is Nil Rated or Exempted',
fieldtype='Check', insert_after='gst_hsn_code'), fieldtype='Check', insert_after='gst_hsn_code'),
dict(fieldname='is_non_gst', label='Is Non GST ', dict(fieldname='is_non_gst', label='Is Non GST ',
fieldtype='Check', insert_after='is_nil_exempt') fieldtype='Check', insert_after='is_nil_exempt')

View File

@@ -12,7 +12,8 @@ frappe.ui.form.on('Material Request', {
'Purchase Order': 'Purchase Order', 'Purchase Order': 'Purchase Order',
'Request for Quotation': 'Request for Quotation', 'Request for Quotation': 'Request for Quotation',
'Supplier Quotation': 'Supplier Quotation', 'Supplier Quotation': 'Supplier Quotation',
'Work Order': 'Work Order' 'Work Order': 'Work Order',
'Purchase Receipt': 'Purchase Receipt'
}; };
// formatter for material request item // formatter for material request item
@@ -27,11 +28,20 @@ frappe.ui.form.on('Material Request', {
// set schedule_date // set schedule_date
set_schedule_date(frm); set_schedule_date(frm);
frm.fields_dict["items"].grid.get_field("warehouse").get_query = function(doc) {
let filters = {'company': frm.doc.company}
frm.set_query("warehouse", "items", function() {
return { return {
filters: {'company': doc.company} filters: filters
}; };
}; });
frm.set_query("set_warehouse", function(){
return {
filters: filters
};
});
}, },
onload_post_render: function(frm) { onload_post_render: function(frm) {
@@ -129,12 +139,13 @@ frappe.ui.form.on('Material Request', {
source_doctype: "Sales Order", source_doctype: "Sales Order",
target: frm, target: frm,
setters: { setters: {
company: frm.doc.company customer: frm.doc.customer || undefined
}, },
get_query_filters: { get_query_filters: {
docstatus: 1, docstatus: 1,
status: ["not in", ["Closed", "On Hold"]], status: ["not in", ["Closed", "On Hold"]],
per_delivered: ["<", 99.99], per_delivered: ["<", 99.99],
company: frm.doc.company
} }
}); });
}, },
@@ -182,46 +193,46 @@ frappe.ui.form.on('Material Request', {
options:"BOM", reqd: 1, get_query: function() { options:"BOM", reqd: 1, get_query: function() {
return {filters: { docstatus:1 }}; return {filters: { docstatus:1 }};
}}, }},
{"fieldname":"warehouse", "fieldtype":"Link", "label":__("Warehouse"), {"fieldname":"warehouse", "fieldtype":"Link", "label":__("For Warehouse"),
options:"Warehouse", reqd: 1}, options:"Warehouse", reqd: 1},
{"fieldname":"qty", "fieldtype":"Float", "label":__("Quantity"), {"fieldname":"qty", "fieldtype":"Float", "label":__("Quantity"),
reqd: 1, "default": 1}, reqd: 1, "default": 1},
{"fieldname":"fetch_exploded", "fieldtype":"Check", {"fieldname":"fetch_exploded", "fieldtype":"Check",
"label":__("Fetch exploded BOM (including sub-assemblies)"), "default":1}, "label":__("Fetch exploded BOM (including sub-assemblies)"), "default":1}
{fieldname:"fetch", "label":__("Get Items from BOM"), "fieldtype":"Button"} ],
] primary_action_label: 'Get Items',
}); primary_action(values) {
d.get_input("fetch").on("click", function() { if(!values) return;
var values = d.get_values(); values["company"] = frm.doc.company;
if(!values) return; if(!frm.doc.company) frappe.throw(__("Company field is required"));
values["company"] = frm.doc.company; frappe.call({
if(!frm.doc.company) frappe.throw(__("Company field is required")); method: "erpnext.manufacturing.doctype.bom.bom.get_bom_items",
frappe.call({ args: values,
method: "erpnext.manufacturing.doctype.bom.bom.get_bom_items", callback: function(r) {
args: values, if (!r.message) {
callback: function(r) { frappe.throw(__("BOM does not contain any stock item"));
if (!r.message) { } else {
frappe.throw(__("BOM does not contain any stock item")); erpnext.utils.remove_empty_first_row(frm, "items");
} else { $.each(r.message, function(i, item) {
erpnext.utils.remove_empty_first_row(frm, "items"); var d = frappe.model.add_child(cur_frm.doc, "Material Request Item", "items");
$.each(r.message, function(i, item) { d.item_code = item.item_code;
var d = frappe.model.add_child(cur_frm.doc, "Material Request Item", "items"); d.item_name = item.item_name;
d.item_code = item.item_code; d.description = item.description;
d.item_name = item.item_name; d.warehouse = values.warehouse;
d.description = item.description; d.uom = item.stock_uom;
d.warehouse = values.warehouse; d.stock_uom = item.stock_uom;
d.uom = item.stock_uom; d.conversion_factor = 1;
d.stock_uom = item.stock_uom; d.qty = item.qty;
d.conversion_factor = 1; d.project = item.project;
d.qty = item.qty; });
d.project = item.project; }
}); d.hide();
refresh_field("items");
} }
d.hide(); });
refresh_field("items"); }
}
});
}); });
d.show(); d.show();
}, },
@@ -248,7 +259,8 @@ frappe.ui.form.on('Material Request', {
run_link_triggers: true run_link_triggers: true
}); });
}, },
__('Enter Supplier') __('Enter Supplier'),
__('Create')
) )
}, },

View File

@@ -1,9 +1,11 @@
{ {
"actions": [],
"allow_import": 1, "allow_import": 1,
"autoname": "naming_series:", "autoname": "naming_series:",
"creation": "2013-03-07 14:48:38", "creation": "2013-03-07 14:48:38",
"doctype": "DocType", "doctype": "DocType",
"document_type": "Document", "document_type": "Document",
"engine": "InnoDB",
"field_order": [ "field_order": [
"type_section", "type_section",
"naming_series", "naming_series",
@@ -14,6 +16,8 @@
"schedule_date", "schedule_date",
"company", "company",
"amended_from", "amended_from",
"warehouse_section",
"set_warehouse",
"items_section", "items_section",
"scan_barcode", "scan_barcode",
"items", "items",
@@ -66,7 +70,7 @@
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Type", "label": "Purpose",
"options": "Purchase\nMaterial Transfer\nMaterial Issue\nManufacture\nCustomer Provided", "options": "Purchase\nMaterial Transfer\nMaterial Issue\nManufacture\nCustomer Provided",
"reqd": 1 "reqd": 1
}, },
@@ -85,7 +89,7 @@
"allow_on_submit": 1, "allow_on_submit": 1,
"fieldname": "schedule_date", "fieldname": "schedule_date",
"fieldtype": "Date", "fieldtype": "Date",
"label": "Required Date" "label": "Required By"
}, },
{ {
"fieldname": "company", "fieldname": "company",
@@ -190,6 +194,7 @@
"width": "100px" "width": "100px"
}, },
{ {
"depends_on": "eval:doc.docstatus==1",
"fieldname": "per_ordered", "fieldname": "per_ordered",
"fieldtype": "Percent", "fieldtype": "Percent",
"label": "% Ordered", "label": "% Ordered",
@@ -200,6 +205,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "eval:doc.docstatus==1",
"fieldname": "per_received", "fieldname": "per_received",
"fieldtype": "Percent", "fieldtype": "Percent",
"label": "% Received", "label": "% Received",
@@ -270,12 +276,24 @@
"options": "Job Card", "options": "Job Card",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
},
{
"fieldname": "warehouse_section",
"fieldtype": "Section Break"
},
{
"description": "Sets 'For Warehouse' in each row of the Items table.",
"fieldname": "set_warehouse",
"fieldtype": "Link",
"label": "Set Warehouse",
"options": "Warehouse"
} }
], ],
"icon": "fa fa-ticket", "icon": "fa fa-ticket",
"idx": 70, "idx": 70,
"is_submittable": 1, "is_submittable": 1,
"modified": "2019-04-29 11:45:07.570292", "links": [],
"modified": "2020-03-02 20:21:09.990867",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Material Request", "name": "Material Request",

View File

@@ -8,7 +8,12 @@ def get_data():
'transactions': [ 'transactions': [
{ {
'label': _('Related'), 'label': _('Related'),
'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order', 'Stock Entry', 'Pick List'] 'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order']
},
{
'label': _('Stock'),
'items': ['Stock Entry', 'Purchase Receipt', 'Pick List']
}, },
{ {
'label': _('Manufacturing'), 'label': _('Manufacturing'),

View File

@@ -7,36 +7,38 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"item_code", "item_code",
"col_break1",
"item_name", "item_name",
"col_break1",
"schedule_date",
"section_break_4", "section_break_4",
"description", "description",
"item_group", "item_group",
"brand", "brand",
"image_section", "image_section",
"image", "image",
"manufacture_details",
"manufacturer",
"column_break_12", "column_break_12",
"manufacturer_part_no", "manufacturer_part_no",
"quantity_and_warehouse", "quantity_and_warehouse",
"qty", "qty",
"uom",
"conversion_factor",
"stock_uom", "stock_uom",
"warehouse", "warehouse",
"col_break2", "col_break2",
"schedule_date", "uom",
"rate", "conversion_factor",
"amount",
"stock_qty", "stock_qty",
"rate_and_amount_section_break",
"rate",
"col_break3",
"amount",
"manufacture_details",
"manufacturer",
"more_info", "more_info",
"lead_time_date", "lead_time_date",
"sales_order", "sales_order",
"sales_order_item", "sales_order_item",
"production_plan", "production_plan",
"material_request_plan_item", "material_request_plan_item",
"col_break3", "col_break4",
"min_order_qty", "min_order_qty",
"projected_qty", "projected_qty",
"actual_qty", "actual_qty",
@@ -175,7 +177,7 @@
"fieldname": "schedule_date", "fieldname": "schedule_date",
"fieldtype": "Date", "fieldtype": "Date",
"in_list_view": 1, "in_list_view": 1,
"label": "Required Date", "label": "Required By",
"oldfieldname": "schedule_date", "oldfieldname": "schedule_date",
"oldfieldtype": "Date", "oldfieldtype": "Date",
"print_width": "100px", "print_width": "100px",
@@ -185,14 +187,12 @@
{ {
"fieldname": "rate", "fieldname": "rate",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Rate", "label": "Rate"
"no_copy": 1
}, },
{ {
"fieldname": "amount", "fieldname": "amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Amount", "label": "Amount",
"no_copy": 1,
"read_only": 1 "read_only": 1
}, },
{ {
@@ -204,6 +204,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"collapsible": 1,
"fieldname": "more_info", "fieldname": "more_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "More Information" "label": "More Information"
@@ -331,6 +332,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"collapsible": 1,
"fieldname": "accounting_details", "fieldname": "accounting_details",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Accounting Details" "label": "Accounting Details"
@@ -389,6 +391,7 @@
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"collapsible": 1,
"fieldname": "manufacture_details", "fieldname": "manufacture_details",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Manufacture" "label": "Manufacture"
@@ -406,7 +409,16 @@
{ {
"fieldname": "manufacturer_part_no", "fieldname": "manufacturer_part_no",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Manufacturer Part Number" "label": "Manufacturer Part Number",
"read_only": 1
},
{
"fieldname": "rate_and_amount_section_break",
"fieldtype": "Section Break"
},
{
"fieldname": "col_break4",
"fieldtype": "Column Break"
} }
], ],
"idx": 1, "idx": 1,