Skip to content

Commit

Permalink
fix: production plan UX
Browse files Browse the repository at this point in the history
(cherry picked from commit 8cb7112)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Nov 27, 2022
1 parent 6e5fd55 commit 4607590
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Warehouse",
"label": "For Warehouse",
"options": "Warehouse",
"reqd": 1
},
Expand Down Expand Up @@ -173,7 +173,7 @@
],
"istable": 1,
"links": [],
"modified": "2021-08-23 18:17:58.400462",
"modified": "2022-11-26 14:59:25.879631",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Material Request Plan Item",
Expand All @@ -182,5 +182,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
93 changes: 51 additions & 42 deletions erpnext/manufacturing/doctype/production_plan/production_plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

frappe.ui.form.on('Production Plan', {

before_save: function(frm) {
before_save(frm) {
// preserve temporary names on production plan item to re-link sub-assembly items
frm.doc.po_items.forEach(item => {
item.temporary_name = item.name;
});
},
setup: function(frm) {
setup(frm) {
frm.custom_make_buttons = {
'Work Order': 'Work Order / Subcontract PO',
'Material Request': 'Material Request',
Expand Down Expand Up @@ -70,7 +70,7 @@ frappe.ui.form.on('Production Plan', {
}
},

refresh: function(frm) {
refresh(frm) {
if (frm.doc.docstatus === 1) {
frm.trigger("show_progress");

Expand Down Expand Up @@ -158,7 +158,7 @@ frappe.ui.form.on('Production Plan', {
set_field_options("projected_qty_formula", projected_qty_formula);
},

close_open_production_plan: (frm, close=false) => {
close_open_production_plan(frm, close=false) {
frappe.call({
method: "set_status",
freeze: true,
Expand All @@ -170,7 +170,7 @@ frappe.ui.form.on('Production Plan', {
});
},

make_work_order: function(frm) {
make_work_order(frm) {
frappe.call({
method: "make_work_order",
freeze: true,
Expand All @@ -181,7 +181,7 @@ frappe.ui.form.on('Production Plan', {
});
},

make_material_request: function(frm) {
make_material_request(frm) {

frappe.confirm(__("Do you want to submit the material request"),
function() {
Expand All @@ -193,7 +193,7 @@ frappe.ui.form.on('Production Plan', {
);
},

create_material_request: function(frm, submit) {
create_material_request(frm, submit) {
frm.doc.submit_material_request = submit;

frappe.call({
Expand All @@ -206,7 +206,7 @@ frappe.ui.form.on('Production Plan', {
});
},

get_sales_orders: function(frm) {
get_sales_orders(frm) {
frappe.call({
method: "get_open_sales_orders",
doc: frm.doc,
Expand All @@ -216,7 +216,7 @@ frappe.ui.form.on('Production Plan', {
});
},

get_material_request: function(frm) {
get_material_request(frm) {
frappe.call({
method: "get_pending_material_requests",
doc: frm.doc,
Expand All @@ -226,7 +226,7 @@ frappe.ui.form.on('Production Plan', {
});
},

get_items: function (frm) {
get_items(frm) {
frm.clear_table('prod_plan_references');

frappe.call({
Expand All @@ -238,7 +238,7 @@ frappe.ui.form.on('Production Plan', {
}
});
},
combine_items: function (frm) {
combine_items(frm) {
frm.clear_table("prod_plan_references");

frappe.call({
Expand All @@ -254,14 +254,14 @@ frappe.ui.form.on('Production Plan', {
});
},

combine_sub_items: (frm) => {
combine_sub_items(frm) {
if (frm.doc.sub_assembly_items.length > 0) {
frm.clear_table("sub_assembly_items");
frm.trigger("get_sub_assembly_items");
}
},

get_sub_assembly_items: function(frm) {
get_sub_assembly_items(frm) {
frm.dirty();

frappe.call({
Expand All @@ -274,9 +274,25 @@ frappe.ui.form.on('Production Plan', {
});
},

get_items_for_mr: function(frm) {
toggle_for_warehouse(frm) {
frm.toggle_reqd("for_warehouse", true);
},

get_items_for_mr(frm) {
if (!frm.doc.for_warehouse) {
frappe.throw(__("To make material requests, 'Make Material Request for Warehouse' field is mandatory"));
frm.trigger("toggle_for_warehouse");
frappe.throw(__("Select the Warehouse"));
}

frm.events.get_items_for_material_requests(frm, [{
warehouse: frm.doc.for_warehouse
}]);
},

transfer_materials(frm) {
if (!frm.doc.for_warehouse) {
frm.trigger("toggle_for_warehouse");
frappe.throw(__("Select the Warehouse"));
}

if (frm.doc.ignore_existing_ordered_qty) {
Expand All @@ -287,18 +303,10 @@ frappe.ui.form.on('Production Plan', {
title: title,
fields: [
{
'label': __('Target Warehouse'),
'fieldtype': 'Link',
'fieldname': 'target_warehouse',
'read_only': true,
'default': frm.doc.for_warehouse
},
{
'label': __('Source Warehouses (Optional)'),
'label': __('Transfer From Warehouses'),
'fieldtype': 'Table MultiSelect',
'fieldname': 'warehouses',
'options': 'Production Plan Material Request Warehouse',
'description': __('If source warehouse selected then system will create the material request with type Material Transfer from Source to Target warehouse. If not selected then will create the material request with type Purchase for the target warehouse.'),
get_query: function () {
return {
filters: {
Expand All @@ -307,6 +315,13 @@ frappe.ui.form.on('Production Plan', {
};
},
},
{
'label': __('For Warehouse'),
'fieldtype': 'Link',
'fieldname': 'target_warehouse',
'read_only': true,
'default': frm.doc.for_warehouse
}
]
});

Expand All @@ -320,8 +335,8 @@ frappe.ui.form.on('Production Plan', {
}
},

get_items_for_material_requests: function(frm, warehouses) {
const set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom', 'from_warehouse',
get_items_for_material_requests(frm, warehouses) {
let set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom', 'from_warehouse',
'min_order_qty', 'required_bom_qty', 'quantity', 'sales_order', 'warehouse', 'projected_qty', 'ordered_qty',
'reserved_qty_for_production', 'material_request_type'];

Expand All @@ -335,27 +350,21 @@ frappe.ui.form.on('Production Plan', {
callback: function(r) {
if(r.message) {
frm.set_value('mr_items', []);
$.each(r.message, function(i, d) {
var item = frm.add_child('mr_items');
for (let key in d) {
if (d[key] && in_list(set_fields, key)) {
item[key] = d[key];
r.message.forEach(row => {
let d = frm.add_child('mr_items');
set_fields.forEach(field => {
if (row[field]) {
d[field] = row[field];
}
}
});
});
}
refresh_field('mr_items');
}
});
},

for_warehouse: function(frm) {
if (frm.doc.mr_items && frm.doc.for_warehouse) {
frm.trigger("get_items_for_mr");
}
},

download_materials_required: function(frm) {
download_materials_required(frm) {
const fields = [{
fieldname: 'warehouses',
fieldtype: 'Table MultiSelect',
Expand All @@ -381,7 +390,7 @@ frappe.ui.form.on('Production Plan', {
}, __('Select Warehouses to get Stock for Materials Planning'), __('Get Stock'));
},

show_progress: function(frm) {
show_progress(frm) {
var bars = [];
var message = '';
var title = '';
Expand Down Expand Up @@ -416,7 +425,7 @@ frappe.ui.form.on('Production Plan', {
});

frappe.ui.form.on("Production Plan Item", {
item_code: function(frm, cdt, cdn) {
item_code(frm, cdt, cdn) {
const row = locals[cdt][cdn];
if (row.item_code) {
frappe.call({
Expand All @@ -435,7 +444,7 @@ frappe.ui.form.on("Production Plan Item", {
});

frappe.ui.form.on("Material Request Plan Item", {
warehouse: function(frm, cdt, cdn) {
warehouse(frm, cdt, cdn) {
const row = locals[cdt][cdn];
if (row.warehouse && row.item_code && frm.doc.company) {
frappe.call({
Expand Down
25 changes: 19 additions & 6 deletions erpnext/manufacturing/doctype/production_plan/production_plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@
"get_sub_assembly_items",
"combine_sub_items",
"sub_assembly_items",
"download_materials_request_plan_section_section",
"download_materials_required",
"material_request_planning",
"include_non_stock_items",
"include_subcontracted_items",
"include_safety_stock",
"ignore_existing_ordered_qty",
"column_break_25",
"for_warehouse",
"download_materials_required",
"get_items_for_mr",
"transfer_materials",
"section_break_27",
"mr_items",
"other_details",
Expand Down Expand Up @@ -206,7 +208,7 @@
{
"fieldname": "material_request_planning",
"fieldtype": "Section Break",
"label": "Material Requirement Planning"
"label": "Material Request Planning"
},
{
"default": "1",
Expand Down Expand Up @@ -235,12 +237,12 @@
"depends_on": "eval:!doc.__islocal",
"fieldname": "download_materials_required",
"fieldtype": "Button",
"label": "Download Required Materials"
"label": "Download Materials Request Plan"
},
{
"fieldname": "get_items_for_mr",
"fieldtype": "Button",
"label": "Get Raw Materials For Production"
"label": "Get Raw Materials for Purchase"
},
{
"fieldname": "section_break_27",
Expand Down Expand Up @@ -304,7 +306,7 @@
{
"fieldname": "for_warehouse",
"fieldtype": "Link",
"label": "Make Material Request for Warehouse",
"label": "Raw Materials Warehouse",
"options": "Warehouse"
},
{
Expand Down Expand Up @@ -378,13 +380,24 @@
"fieldname": "combine_sub_items",
"fieldtype": "Check",
"label": "Consolidate Sub Assembly Items"
},
{
"fieldname": "transfer_materials",
"fieldtype": "Button",
"label": "Get Raw Materials for Transfer"
},
{
"collapsible": 1,
"fieldname": "download_materials_request_plan_section_section",
"fieldtype": "Section Break",
"label": "Download Materials Request Plan Section"
}
],
"icon": "fa fa-calendar",
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-03-25 09:15:25.017664",
"modified": "2022-11-26 14:51:08.774372",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def get_mr_items(self):
def add_items(self, items):
refs = {}
for data in items:
if not data.pending_qty:
continue

item_details = get_item_details(data.item_code)
if self.combine_items:
if item_details.bom_no in refs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"fieldname": "warehouse",
"fieldtype": "Link",
"in_list_view": 1,
"label": "For Warehouse",
"label": "FG Warehouse",
"options": "Warehouse"
},
{
Expand Down Expand Up @@ -216,7 +216,7 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2022-03-24 04:54:09.940224",
"modified": "2022-11-25 14:15:40.061514",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan Item",
Expand Down

0 comments on commit 4607590

Please sign in to comment.