Fixed formatting of code and repositioned checkboxes in PPT.

This commit is contained in:
Ben Cornwell-Mott 2016-08-17 05:42:25 -07:00
parent e977fc5dee
commit 06bfecea73
3 changed files with 172 additions and 116 deletions

View File

@ -469,86 +469,6 @@
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"default": "1",
"depends_on": "",
"description": "If checked, all the children of each production item will be included in the Material Requests.",
"fieldname": "use_multi_level_bom",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"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,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"description": "If checked, only Purchase material requests for final raw materials will be included in the Material Requests. Otherwise, Material Requests for parent items will be created",
"fieldname": "only_raw_materials",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Only Obtain Raw Materials",
"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,
"depends_on": "use_multi_level_bom",
"description": "If checked, raw materials for items that are sub-contracted will be included in the Material Requests",
"fieldname": "include_subcontracted",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Include sub-contracted raw materials",
"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
},
@ -753,6 +673,110 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_2",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 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,
"default": "1",
"depends_on": "",
"description": "If checked, all the children of each production item will be included in the Material Requests.",
"fieldname": "use_multi_level_bom",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"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,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"description": "If checked, only Purchase material requests for final raw materials will be included in the Material Requests. Otherwise, Material Requests for parent items will be created",
"fieldname": "only_raw_materials",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Only Obtain Raw Materials",
"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,
"depends_on": "use_multi_level_bom",
"description": "If checked, raw materials for items that are sub-contracted will be included in the Material Requests",
"fieldname": "include_subcontracted",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Include sub-contracted raw materials",
"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,
@ -766,7 +790,7 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2016-07-27 19:37:49.608457",
"modified": "2016-08-17 05:35:34.331954",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Planning Tool",

View File

@ -332,7 +332,8 @@ class ProductionPlanningTool(Document):
else:
# Get all raw materials considering SA items as raw materials,
# so no childs of SA items
bom_wise_item_details = self.get_subitems(bom_wise_item_details, bom,1, self.use_multi_level_bom,self.only_raw_materials, self.include_subcontracted)
bom_wise_item_details = self.get_subitems(bom_wise_item_details, bom,1, \
self.use_multi_level_bom,self.only_raw_materials, self.include_subcontracted)
for item, item_details in bom_wise_item_details.items():
for so_qty in so_wise_qty:
@ -343,21 +344,26 @@ class ProductionPlanningTool(Document):
def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs):
for d in frappe.db.sql("""select bom_item.item_code, default_material_request_type,
ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty,
item.is_sub_contracted_item as is_sub_contracted, item.default_bom as default_bom
from `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
where bom.name = bom_item.parent and bom.name = %(bom)s and bom_item.docstatus < 2
and bom_item.item_code = item.name
and item.is_stock_item = 1
group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1):
if (d.default_material_request_type == "Purchase" and not (d.is_sub_contracted and only_raw and include_sublevel)) or (d.default_material_request_type == "Manufacture" and not only_raw):
if d.item_code in bom_wise_item_details:
bom_wise_item_details[d.item_code].qty = bom_wise_item_details[d.item_code].qty + d.qty
else:
bom_wise_item_details[d.item_code] = d
if include_sublevel:
if (d.default_material_request_type == "Purchase" and d.is_sub_contracted and supply_subs) or (d.default_material_request_type == "Manufacture"):
child_details = self.get_subitems(bom_wise_item_details,d.default_bom,d.qty, include_sublevel, only_raw, supply_subs)
ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty,
item.is_sub_contracted_item as is_sub_contracted, item.default_bom as default_bom
from `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
where bom.name = bom_item.parent and bom.name = %(bom)s and bom_item.docstatus < 2
and bom_item.item_code = item.name
and item.is_stock_item = 1
group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1):
if (d.default_material_request_type == "Purchase" and not (d.is_sub_contracted \
and only_raw and include_sublevel)) or (d.default_material_request_type == \
"Manufacture" and not only_raw):
if d.item_code in bom_wise_item_details:
bom_wise_item_details[d.item_code].qty = bom_wise_item_details[d.item_code].qty\
+ d.qty
else:
bom_wise_item_details[d.item_code] = d
if include_sublevel:
if (d.default_material_request_type == "Purchase" and d.is_sub_contracted \
and supply_subs) or (d.default_material_request_type == "Manufacture"):
child_details = self.get_subitems(bom_wise_item_details,d.default_bom, \
d.qty, include_sublevel, only_raw, supply_subs)
return bom_wise_item_details
def make_items_dict(self, item_list):

View File

@ -17,58 +17,84 @@ test_dependencies = ["Item","BOM"]
class TestEvent(unittest.TestCase):
def test_materials_requests_all_raw_multi_level(self):
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D","_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A","_Test PPT Item SC B","_Test PPT Item Master"]
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",
"_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",
"_Test PPT Item SC B","_Test PPT Item Master"]
quantities = [14,9,36,1,0,0,0,0,0,0]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase","Purchase","Manufacture"]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",
"Purchase","Manufacture"]
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=1, include_subcontracted=1)
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=1, \
include_subcontracted=1)
def test_materials_requests_multi_no_subcontracted(self):
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D","_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A","_Test PPT Item SC B","_Test PPT Item Master"]
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",
"_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",
"_Test PPT Item SC B","_Test PPT Item Master"]
quantities = [14,5,20,0,0,0,0,0,0,0]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase","Purchase","Manufacture"]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",
"Purchase","Manufacture"]
# This one should fail for now
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=1, include_subcontracted=0)
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=1, \
include_subcontracted=0)
def test_materials_requests_manufacture_and_sub_multi_level(self):
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D","_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A","_Test PPT Item SC B","_Test PPT Item Master"]
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",
"_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",
"_Test PPT Item SC B","_Test PPT Item Master"]
quantities = [14,9,36,1,2,5,2,1,4,0]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase","Purchase","Manufacture"]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",
"Purchase","Manufacture"]
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=0, include_subcontracted=1)
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=0, \
include_subcontracted=1)
def test_materials_requests_manufacture_multi_level(self):
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D","_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A","_Test PPT Item SC B","_Test PPT Item Master"]
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",
"_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",
"_Test PPT Item SC B","_Test PPT Item Master"]
quantities = [14,5,20,0,2,5,2,1,4,0]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase","Purchase","Manufacture"]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",
"Purchase","Manufacture"]
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=0, include_subcontracted=0)
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=1, only_raw_materials=0, \
include_subcontracted=0)
def test_materials_requests_single_level_purch_only(self):
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D","_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A","_Test PPT Item SC B","_Test PPT Item Master"]
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",
"_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",
"_Test PPT Item SC B","_Test PPT Item Master"]
quantities = [2,0,0,0,0,0,0,1,0,0]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase","Purchase","Manufacture"]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",
"Purchase","Manufacture"]
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=0, only_raw_materials=1, include_subcontracted=0)
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=0, only_raw_materials=1, \
include_subcontracted=0)
def test_materials_requests_single_level(self):
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D","_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A","_Test PPT Item SC B","_Test PPT Item Master"]
items = ["_Test PPT Item Raw A","_Test PPT Item Raw B","_Test PPT Item Raw C","_Test PPT Item Raw D",
"_Test PPT Item Sub A","_Test PPT Item Sub B","_Test PPT Item Sub C","_Test PPT Item SC A",
"_Test PPT Item SC B","_Test PPT Item Master"]
quantities = [2,0,0,0,2,1,0,1,0,0]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase","Purchase","Manufacture"]
types = ["Purchase","Purchase","Purchase","Purchase","Manufacture","Manufacture","Manufacture","Purchase",
"Purchase","Manufacture"]
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=0, only_raw_materials=0, include_subcontracted=0)
self.runtest_materials_requests(items, quantities, types, use_multi_level_bom=0, only_raw_materials=0, \
include_subcontracted=0)
def runtest_materials_requests(self, items, quantities, types,use_multi_level_bom, only_raw_materials, include_subcontracted):
clear_material_requests()
create_test_records()
ppt = run_production_planning_tool(use_multi_level_bom=use_multi_level_bom, only_raw_materials=only_raw_materials, include_subcontracted=include_subcontracted, item_code = "_Test PPT Item Master",bom_no = "BOM-_Test PPT Item Master-001", planned_qty = 1, planned_start_date = "5/5/2029", warehouse = "_Test Warehouse - _TC", company = "_Test Company")
ppt = run_production_planning_tool(use_multi_level_bom=use_multi_level_bom, only_raw_materials=only_raw_materials,
include_subcontracted=include_subcontracted, item_code = "_Test PPT Item Master",bom_no = "BOM-_Test PPT Item Master-001",
planned_qty = 1, planned_start_date = "5/5/2029", warehouse = "_Test Warehouse - _TC", company = "_Test Company")
create_material_requests(ppt)
for item, qty, type in zip(items, quantities, types):