From 877e2ebff8f459f82f80358b95e1ad3ff82a03e7 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 11 Feb 2016 12:06:31 +0530 Subject: [PATCH] Fixed Production PLanning Tool --- .../production_plan_item.json | 69 ++++++- .../__init__.py | 0 .../production_plan_material_request.json | 113 +++++++++++ .../production_plan_material_request.py | 10 + .../production_plan_sales_order.json | 12 +- .../production_planning_tool.json | 187 ++++++++++++++++-- .../production_planning_tool.py | 143 +++++++++++--- 7 files changed, 481 insertions(+), 53 deletions(-) create mode 100644 erpnext/manufacturing/doctype/production_plan_material_request/__init__.py create mode 100644 erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.json create mode 100644 erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.py diff --git a/erpnext/manufacturing/doctype/production_plan_item/production_plan_item.json b/erpnext/manufacturing/doctype/production_plan_item/production_plan_item.json index 49d31c961c3..6596e234011 100644 --- a/erpnext/manufacturing/doctype/production_plan_item/production_plan_item.json +++ b/erpnext/manufacturing/doctype/production_plan_item/production_plan_item.json @@ -26,6 +26,7 @@ "options": "Item", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "150px", "read_only": 0, "report_hide": 0, @@ -53,6 +54,7 @@ "options": "BOM", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "100px", "read_only": 0, "report_hide": 0, @@ -79,6 +81,7 @@ "oldfieldtype": "Currency", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "100px", "read_only": 0, "report_hide": 0, @@ -105,6 +108,7 @@ "permlevel": 0, "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 1, @@ -121,7 +125,7 @@ "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, - "in_list_view": 1, + "in_list_view": 0, "label": "Sales Order", "length": 0, "no_copy": 0, @@ -130,6 +134,7 @@ "options": "Sales Order", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 1, "report_hide": 0, "reqd": 0, @@ -141,19 +146,45 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "so_pending_qty", + "fieldname": "material_request", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Material Request", + "length": 0, + "no_copy": 0, + "options": "Material Request", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "pending_qty", "fieldtype": "Float", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 1, - "label": "SO Pending Qty", + "label": "Pending Qty", "length": 0, "no_copy": 0, "oldfieldname": "prevdoc_reqd_qty", "oldfieldtype": "Currency", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "100px", "read_only": 1, "report_hide": 0, @@ -180,6 +211,7 @@ "options": "Warehouse", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -205,6 +237,7 @@ "options": "UOM", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "80px", "read_only": 1, "report_hide": 0, @@ -231,6 +264,7 @@ "oldfieldtype": "Text", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "200px", "read_only": 1, "report_hide": 0, @@ -239,6 +273,30 @@ "set_only_once": 0, "unique": 0, "width": "200px" + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "material_request_item", + "fieldtype": "Data", + "hidden": 1, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "material_request_item", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 } ], "hide_heading": 0, @@ -250,12 +308,13 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2015-11-16 06:29:52.572122", + "modified": "2016-02-10 07:08:38.461787", "modified_by": "Administrator", "module": "Manufacturing", "name": "Production Plan Item", "owner": "Administrator", "permissions": [], "read_only": 0, - "read_only_onload": 0 + "read_only_onload": 0, + "sort_order": "ASC" } \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/production_plan_material_request/__init__.py b/erpnext/manufacturing/doctype/production_plan_material_request/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.json b/erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.json new file mode 100644 index 00000000000..0522e7a3473 --- /dev/null +++ b/erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.json @@ -0,0 +1,113 @@ +{ + "allow_copy": 0, + "allow_import": 0, + "allow_rename": 0, + "autoname": "hash", + "creation": "2016-02-10 05:09:11.983251", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "fields": [ + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "material_request", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 1, + "label": "Material Request", + "length": 0, + "no_copy": 0, + "oldfieldname": "prevdoc_docname", + "oldfieldtype": "Data", + "options": "Material Request", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "150px", + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0, + "width": "150px" + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "col_break1", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "material_request_date", + "fieldtype": "Date", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 1, + "label": "Material Request Date", + "length": 0, + "no_copy": 0, + "oldfieldname": "document_date", + "oldfieldtype": "Date", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "120px", + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0, + "width": "120px" + } + ], + "hide_heading": 0, + "hide_toolbar": 0, + "idx": 0, + "in_create": 0, + "in_dialog": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2016-02-10 05:13:07.529068", + "modified_by": "Administrator", + "module": "Manufacturing", + "name": "Production Plan Material Request", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "read_only": 0, + "read_only_onload": 0, + "sort_field": "modified", + "sort_order": "ASC" +} \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.py b/erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.py new file mode 100644 index 00000000000..44786f8388d --- /dev/null +++ b/erpnext/manufacturing/doctype/production_plan_material_request/production_plan_material_request.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class ProductionPlanMaterialRequest(Document): + pass diff --git a/erpnext/manufacturing/doctype/production_plan_sales_order/production_plan_sales_order.json b/erpnext/manufacturing/doctype/production_plan_sales_order/production_plan_sales_order.json index d7fdea5a0ae..bed893f9210 100644 --- a/erpnext/manufacturing/doctype/production_plan_sales_order/production_plan_sales_order.json +++ b/erpnext/manufacturing/doctype/production_plan_sales_order/production_plan_sales_order.json @@ -26,6 +26,7 @@ "options": "Sales Order", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "150px", "read_only": 0, "report_hide": 0, @@ -45,13 +46,14 @@ "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 1, - "label": "SO Date", + "label": "Salse Order Date", "length": 0, "no_copy": 0, "oldfieldname": "document_date", "oldfieldtype": "Date", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "120px", "read_only": 1, "report_hide": 0, @@ -76,6 +78,7 @@ "permlevel": 0, "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -99,6 +102,7 @@ "options": "Customer", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "150px", "read_only": 1, "report_hide": 0, @@ -124,6 +128,7 @@ "options": "Company:company:default_currency", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "print_width": "120px", "read_only": 1, "report_hide": 0, @@ -143,12 +148,13 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2015-11-16 06:29:52.629618", + "modified": "2016-02-10 05:13:30.301297", "modified_by": "Administrator", "module": "Manufacturing", "name": "Production Plan Sales Order", "owner": "Administrator", "permissions": [], "read_only": 0, - "read_only_onload": 0 + "read_only_onload": 0, + "sort_order": "ASC" } \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json index e54b168776f..3f047138fd2 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json @@ -12,17 +12,21 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "description": "Select Sales Orders from which you want to create Production Orders.", - "fieldname": "select_sales_orders", - "fieldtype": "Section Break", + "default": "Sales Order", + "fieldname": "plan_using", + "fieldtype": "Select", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, - "label": "Select Sales Orders", + "label": "Plan Using", + "length": 0, "no_copy": 0, + "options": "Sales Order\nMaterial Request", "permlevel": 0, + "precision": "", "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -34,22 +38,26 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "column_break0", - "fieldtype": "Column Break", + "depends_on": "", + "description": "", + "fieldname": "filters", + "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, + "label": "Filters", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, "search_index": 0, "set_only_once": 0, - "unique": 0, - "width": "50%" + "unique": 0 }, { "allow_on_submit": 0, @@ -61,11 +69,13 @@ "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 1, - "label": "Filter based on item", + "label": "Item", + "length": 0, "no_copy": 0, "options": "Item", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -77,17 +87,20 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "depends_on": "eval: doc.plan_using == \"Sales Order\"", "fieldname": "customer", "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 1, - "label": "Filter based on customer", + "label": "Customer", + "length": 0, "no_copy": 0, "options": "Customer", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -99,6 +112,33 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "depends_on": "eval: doc.plan_using == \"Material Request\"", + "fieldname": "warehouse", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Warehouse", + "length": 0, + "no_copy": 0, + "options": "Warehouse", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "depends_on": "eval: doc.plan_using == \"Sales Order\"", "fieldname": "company", "fieldtype": "Link", "hidden": 0, @@ -106,13 +146,15 @@ "in_filter": 0, "in_list_view": 1, "label": "Company", + "length": 0, "no_copy": 0, "options": "Company", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, - "reqd": 1, + "reqd": 0, "search_index": 0, "set_only_once": 0, "unique": 0 @@ -127,9 +169,11 @@ "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -149,9 +193,11 @@ "in_filter": 0, "in_list_view": 0, "label": "From Date", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -170,9 +216,11 @@ "in_filter": 0, "in_list_view": 0, "label": "To Date", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -184,16 +232,19 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "depends_on": "eval: doc.plan_using == \"Sales Order\"", "fieldname": "section_break1", "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, + "length": 0, "no_copy": 0, - "options": "Simple", + "options": "", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -213,10 +264,12 @@ "in_filter": 0, "in_list_view": 0, "label": "Get Sales Orders", + "length": 0, "no_copy": 0, "options": "get_open_sales_orders", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -235,10 +288,87 @@ "in_filter": 0, "in_list_view": 0, "label": "Sales Orders", + "length": 0, "no_copy": 0, "options": "Production Plan Sales Order", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "depends_on": "eval: doc.plan_using == \"Material Request\"", + "fieldname": "section_break_16", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "description": "Pull Material Request of type Manufacture based on the above criteria", + "fieldname": "get_material_request", + "fieldtype": "Button", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Get Material Request", + "length": 0, + "no_copy": 0, + "options": "get_pending_material_requests", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "material_requests", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Material Requests", + "length": 0, + "no_copy": 0, + "options": "Production Plan Material Request", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -257,9 +387,11 @@ "in_filter": 0, "in_list_view": 0, "label": "Select Items", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -271,17 +403,19 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "get_items_from_so", + "fieldname": "get_items", "fieldtype": "Button", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, - "label": "Get Items From Sales Orders", + "label": "Get Items", + "length": 0, "no_copy": 0, - "options": "get_items_from_so", + "options": "get_items", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -302,9 +436,11 @@ "in_filter": 0, "in_list_view": 0, "label": "Use Multi-Level BOM", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -323,10 +459,12 @@ "in_filter": 0, "in_list_view": 0, "label": "Items", + "length": 0, "no_copy": 0, "options": "Production Plan Item", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -346,9 +484,11 @@ "in_filter": 0, "in_list_view": 0, "label": "Production Orders", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -368,10 +508,12 @@ "in_filter": 0, "in_list_view": 0, "label": "Create Production Orders", + "length": 0, "no_copy": 0, "options": "raise_production_order", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -383,6 +525,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "depends_on": "", "fieldname": "sb5", "fieldtype": "Section Break", "hidden": 0, @@ -390,9 +533,11 @@ "in_filter": 0, "in_list_view": 0, "label": "Material Requirement", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -411,10 +556,12 @@ "in_filter": 0, "in_list_view": 0, "label": "Material Request For Warehouse", + "length": 0, "no_copy": 0, "options": "Warehouse", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -434,10 +581,12 @@ "in_filter": 0, "in_list_view": 0, "label": "Create Material Requests", + "length": 0, "no_copy": 0, "options": "", "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -457,9 +606,11 @@ "in_filter": 0, "in_list_view": 0, "label": "Download Materials Required", + "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, + "print_hide_if_no_value": 0, "read_only": 0, "report_hide": 0, "reqd": 0, @@ -477,7 +628,8 @@ "is_submittable": 0, "issingle": 1, "istable": 0, - "modified": "2015-06-05 11:44:31.629114", + "max_attachments": 0, + "modified": "2016-02-10 07:28:50.298538", "modified_by": "Administrator", "module": "Manufacturing", "name": "Production Planning Tool", @@ -505,5 +657,6 @@ } ], "read_only": 1, - "read_only_onload": 0 + "read_only_onload": 0, + "sort_order": "ASC" } \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index 67eab40ddce..4be22e40807 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -33,6 +33,9 @@ class ProductionPlanningTool(Document): def clear_so_table(self): self.set('sales_orders', []) + def clear_mr_table(self): + self.set('material_requests', []) + def clear_item_table(self): self.set('items', []) @@ -88,19 +91,59 @@ class ProductionPlanningTool(Document): pp_so.sales_order_date = cstr(r['transaction_date']) pp_so.customer = cstr(r['customer']) pp_so.grand_total = flt(r['base_grand_total']) + + def get_pending_material_requests(self): + """ Pull Material Requests that are pending based on criteria selected""" + mr_filter = item_filter = "" + if self.from_date: + mr_filter += " and mr.transaction_date >= %(from_date)s" + if self.to_date: + mr_filter += " and mr.transaction_date <= %(to_date)s" + if self.warehouse: + mr_filter += " and mr_item.warehouse = %(warehouse)s" + + if self.fg_item: + item_filter += " and item.name = %(item)s" - def get_items_from_so(self): - """ Pull items from Sales Order, only proction item - and subcontracted item will be pulled from Packing item - and add items in the table - """ - items = self.get_items() - self.add_items(items) + pending_mr = frappe.db.sql(""" + select distinct mr.name, mr.transaction_date + from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item + where mr_item.parent = mr.name + and mr.material_request_type = "Manufacture" + and mr.docstatus = 1 + and mr_item.qty > mr_item.ordered_qty {0} + and (exists (select name from `tabItem` item where item.name=mr_item.item_code + and (item.is_pro_applicable = 1 or item.is_sub_contracted_item = 1 {1}))) + """.format(mr_filter, item_filter), { + "from_date": self.from_date, + "to_date": self.to_date, + "warehouse": self.warehouse, + "item": self.fg_item + }, as_dict=1) + + self.add_mr_in_table(pending_mr) + + def add_mr_in_table(self, pending_mr): + """ Add Material Requests in the table""" + self.clear_mr_table() + + mr_list = [d.material_request for d in self.get('material_requests')] + for r in pending_mr: + if cstr(r['name']) not in mr_list: + mr = self.append('material_requests', {}) + mr.material_request = r['name'] + mr.material_request_date = cstr(r['transaction_date']) def get_items(self): + if self.plan_using == "Sales Order": + self.get_so_items() + elif self.plan_using == "Material Request": + self.get_mr_items() + + def get_so_items(self): so_list = filter(None, [d.sales_order for d in self.get('sales_orders')]) if not so_list: - msgprint(_("Please enter sales order in the above table")) + msgprint(_("Please enter Sales Orders in the above table")) return [] item_condition = "" @@ -131,24 +174,49 @@ class ProductionPlanningTool(Document): or item.is_sub_contracted_item = 1)) %s""" % \ (", ".join(["%s"] * len(so_list)), item_condition), tuple(so_list), as_dict=1) - return items + packed_items + self.add_items(items + packed_items) + + def get_mr_items(self): + mr_list = filter(None, [d.material_request for d in self.get('material_requests')]) + if not mr_list: + msgprint(_("Please enter Material Requests in the above table")) + return [] + item_condition = "" + if self.fg_item: + item_condition = ' and mr_item.item_code = "' + self.fg_item + '"' + + items = frappe.db.sql("""select distinct parent, name, item_code, warehouse, + (qty - ordered_qty) as pending_qty + from `tabMaterial Request Item` mr_item + where parent in (%s) and docstatus = 1 and qty > ordered_qty + and exists (select * from `tabItem` item where item.name=mr_item.item_code + and (item.is_pro_applicable = 1 + or item.is_sub_contracted_item = 1)) %s""" % \ + (", ".join(["%s"] * len(mr_list)), item_condition), tuple(mr_list), as_dict=1) + + self.add_items(items) + def add_items(self, items): self.clear_item_table() - for p in items: item_details = get_item_details(p['item_code']) pi = self.append('items', {}) - pi.sales_order = p['parent'] pi.warehouse = p['warehouse'] pi.item_code = p['item_code'] pi.description = item_details and item_details.description or '' pi.stock_uom = item_details and item_details.stock_uom or '' pi.bom_no = item_details and item_details.bom_no or '' - pi.so_pending_qty = flt(p['pending_qty']) pi.planned_qty = flt(p['pending_qty']) - + pi.pending_qty = flt(p['pending_qty']) + + if self.plan_using == "Sales Order": + pi.sales_order = p['parent'] + elif self.plan_using == "Material Request": + pi.material_request = p['parent'] + pi.material_request_item = p['name'] + def validate_data(self): self.validate_company() for d in self.get('items'): @@ -181,21 +249,38 @@ class ProductionPlanningTool(Document): item_dict, bom_dict = {}, {} for d in self.get("items"): if d.bom_no: - bom_dict.setdefault(d.bom_no, []).append([d.sales_order, flt(d.planned_qty)]) - if frappe.db.get_value("Item", d.item_code, "is_pro_applicable"): - item_dict[(d.item_code, d.sales_order, d.warehouse)] = { - "production_item" : d.item_code, - "sales_order" : d.sales_order, - "qty" : flt(item_dict.get((d.item_code, d.sales_order, d.warehouse), - {}).get("qty")) + flt(d.planned_qty), - "bom_no" : d.bom_no, - "description" : d.description, - "stock_uom" : d.stock_uom, - "company" : self.company, - "wip_warehouse" : "", - "fg_warehouse" : d.warehouse, - "status" : "Draft", - } + if self.plan_using == "Sales Order": + bom_dict.setdefault(d.bom_no, []).append([d.sales_order, flt(d.planned_qty)]) + if frappe.db.get_value("Item", d.item_code, "is_pro_applicable"): + item_dict[(d.item_code, d.sales_order, d.warehouse)] = { + "production_item" : d.item_code, + "sales_order" : d.sales_order, + "qty" : flt(item_dict.get((d.item_code, d.sales_order, d.warehouse), + {}).get("qty")) + flt(d.planned_qty), + "bom_no" : d.bom_no, + "description" : d.description, + "stock_uom" : d.stock_uom, + "company" : self.company, + "wip_warehouse" : "", + "fg_warehouse" : d.warehouse, + "status" : "Draft", + } + elif self.plan_using == "Material Request": + bom_dict.setdefault(d.bom_no, []).append([d.material_request_item, flt(d.planned_qty)]) + if frappe.db.get_value("Item", d.item_code, "is_pro_applicable"): + item_dict[(d.item_code, d.material_request_item, d.warehouse)] = { + "production_item" : d.item_code, + "material_request" : d.material_request, + "material_request_item" : d.material_request_item, + "qty" : d.planned_qty, + "bom_no" : d.bom_no, + "description" : d.description, + "stock_uom" : d.stock_uom, + "company" : self.company, + "wip_warehouse" : "", + "fg_warehouse" : d.warehouse, + "status" : "Draft", + } return bom_dict, item_dict def create_production_order(self, items): @@ -329,6 +414,8 @@ class ProductionPlanningTool(Document): for item_details in so_item_qty: if requested_qty: sales_order = item_details[4] or "No Sales Order" + if self.plan_using == "Material Request": + sales_order = "No Sales Order" if requested_qty <= item_details[0]: adjusted_qty = requested_qty else: