Created 2 reports for stock details
This commit is contained in:
		
							parent
							
								
									9e08ccdf39
								
							
						
					
					
						commit
						3d491f90cc
					
				| @ -0,0 +1,10 @@ | |||||||
|  | frappe.query_reports["BOM Stock Report"] = { | ||||||
|  |     "filters": [ | ||||||
|  |         { | ||||||
|  |             "fieldname":"bom", | ||||||
|  |             "label": __("BOM"), | ||||||
|  |             "fieldtype": "Link", | ||||||
|  |             "options": "BOM" | ||||||
|  |         }, | ||||||
|  |     ] | ||||||
|  | } | ||||||
| @ -0,0 +1,20 @@ | |||||||
|  | { | ||||||
|  |  "add_total_row": 0,  | ||||||
|  |  "apply_user_permissions": 1,  | ||||||
|  |  "creation": "2017-01-10 14:00:50.387244",  | ||||||
|  |  "disabled": 0,  | ||||||
|  |  "docstatus": 0,  | ||||||
|  |  "doctype": "Report",  | ||||||
|  |  "idx": 0,  | ||||||
|  |  "is_standard": "Yes",  | ||||||
|  |  "letter_head": "Standard",  | ||||||
|  |  "modified": "2017-01-10 14:00:54.341088",  | ||||||
|  |  "modified_by": "Administrator",  | ||||||
|  |  "module": "Manufacturing",  | ||||||
|  |  "name": "BOM Stock Report",  | ||||||
|  |  "owner": "Administrator",  | ||||||
|  |  "query": "SELECT \n\tbom_item.item_code as \"Item:Link/Item:200\",\n\tROUND(bom_item.qty,2) as \"Required Qty:Float:100\",\n\tROUND(SUM(ifnull(ledger.actual_qty,0)),2) as \"In Stock Qty:Float:100\",\n\tFLOOR(SUM(ifnull(ledger.actual_qty,0))/bom_item.qty) as \"Enough Parts to Build:Int:100\"\nFROM\n\t`tabBOM Item` AS bom_item \n\tLEFT JOIN `tabStock Ledger Entry` AS ledger\t\n\tON bom_item.item_code = ledger.item_code \nWHERE\n\tbom_item.parent=%(bom)s\n\nGROUP BY bom_item.item_code",  | ||||||
|  |  "ref_doctype": "BOM",  | ||||||
|  |  "report_name": "BOM Stock Report",  | ||||||
|  |  "report_type": "Query Report" | ||||||
|  | } | ||||||
| @ -0,0 +1,6 @@ | |||||||
|  | // Copyright (c) 2016, Velometro Mobility Inc and contributors
 | ||||||
|  | // For license information, please see license.txt
 | ||||||
|  | 
 | ||||||
|  | frappe.query_reports["Production Order Stock Report"] = { | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,19 @@ | |||||||
|  | { | ||||||
|  |  "add_total_row": 0,  | ||||||
|  |  "apply_user_permissions": 1,  | ||||||
|  |  "creation": "2017-01-10 14:01:43.905861",  | ||||||
|  |  "disabled": 0,  | ||||||
|  |  "docstatus": 0,  | ||||||
|  |  "doctype": "Report",  | ||||||
|  |  "idx": 0,  | ||||||
|  |  "is_standard": "Yes",  | ||||||
|  |  "letter_head": "Standard",  | ||||||
|  |  "modified": "2017-01-10 14:01:43.905861",  | ||||||
|  |  "modified_by": "Administrator",  | ||||||
|  |  "module": "Manufacturing",  | ||||||
|  |  "name": "Production Order Stock Report",  | ||||||
|  |  "owner": "Administrator",  | ||||||
|  |  "ref_doctype": "Production Order",  | ||||||
|  |  "report_name": "Production Order Stock Report",  | ||||||
|  |  "report_type": "Script Report" | ||||||
|  | } | ||||||
| @ -0,0 +1,132 @@ | |||||||
|  | # Copyright (c) 2017, Velometro Mobility Inc and contributors | ||||||
|  | # For license information, please see license.txt | ||||||
|  | 
 | ||||||
|  | from __future__ import unicode_literals | ||||||
|  | from frappe.utils import flt, cint | ||||||
|  | import frappe | ||||||
|  | 
 | ||||||
|  | def execute(filters=None): | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	prod_list = get_production_orders() | ||||||
|  | 	 | ||||||
|  | 	data = get_item_list( prod_list) | ||||||
|  | 	 | ||||||
|  | 	columns = get_columns() | ||||||
|  | 	 | ||||||
|  | 	return columns, data | ||||||
|  | 
 | ||||||
|  | 	 | ||||||
|  | def get_item_list(prod_list): | ||||||
|  | 	 | ||||||
|  | 	out = [] | ||||||
|  | 	 | ||||||
|  | 	low_price_data = [] | ||||||
|  | 	low_supplier = [] | ||||||
|  | 	company = frappe.db.get_default("company") | ||||||
|  | 	float_precision = cint(frappe.db.get_default("float_precision")) or 2 | ||||||
|  | 	company_currency = frappe.db.get_default("currency") | ||||||
|  | 	# Get the default supplier of suppliers | ||||||
|  | 	 | ||||||
|  | 		 | ||||||
|  | 	#Add a row for each item/qty | ||||||
|  | 	for root in prod_list: | ||||||
|  | 		bom = frappe.db.get_value("Production Order", root.name,"bom_no") | ||||||
|  | 		desc = frappe.db.get_value("BOM", bom, "description") | ||||||
|  | 		qty = frappe.db.get_value("Production Order", root.name,"qty") | ||||||
|  | 		 | ||||||
|  | 		item_list = frappe.db.sql("""	SELECT  | ||||||
|  | 											bom_item.item_code as item_code, | ||||||
|  | 											SUM(ifnull(ledger.actual_qty,0))/bom_item.qty as build_qty | ||||||
|  | 										FROM | ||||||
|  | 											`tabBOM Item` AS bom_item  | ||||||
|  | 											LEFT JOIN `tabStock Ledger Entry` AS ledger	 | ||||||
|  | 											ON bom_item.item_code = ledger.item_code  | ||||||
|  | 										WHERE | ||||||
|  | 											bom_item.parent=%(bom)s  | ||||||
|  | 										GROUP BY  | ||||||
|  | 											bom_item.item_code""", {"bom": bom}, as_dict=1) | ||||||
|  | 		stock_qty = 0 | ||||||
|  | 		count = 0 | ||||||
|  | 		for item in item_list: | ||||||
|  | 			count = count + 1 | ||||||
|  | 			if item.build_qty >= qty: | ||||||
|  | 				stock_qty = stock_qty + 1 | ||||||
|  | 		if count == stock_qty: | ||||||
|  | 			build = "Y" | ||||||
|  | 		else: | ||||||
|  | 			build = "N" | ||||||
|  | 		 | ||||||
|  | 		row = frappe._dict({ | ||||||
|  | 			"production_order": root.name, | ||||||
|  | 			"status": root.status, | ||||||
|  | 			"req_items": cint(count), | ||||||
|  | 			"instock": stock_qty, | ||||||
|  | 			"description": desc, | ||||||
|  | 			"bom_no": bom, | ||||||
|  | 			"ready_to_build": build | ||||||
|  | 		}) | ||||||
|  | 		 | ||||||
|  | 		out.append(row) | ||||||
|  | 
 | ||||||
|  | 	return out | ||||||
|  | 	 | ||||||
|  | def get_production_orders(): | ||||||
|  | 	 | ||||||
|  | 	out = [] | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	prod_list = frappe.db.sql("""select name, status from `tabProduction Order` as prod where status != "Completed" and docstatus = 1""", {}, as_dict=1) | ||||||
|  | 	prod_list.sort(reverse=False) | ||||||
|  | 	 | ||||||
|  | 	for po in prod_list: | ||||||
|  | 		out.append(po) | ||||||
|  | 
 | ||||||
|  | 	return out | ||||||
|  | 	 | ||||||
|  | def get_columns(): | ||||||
|  | 	columns = [{ | ||||||
|  | 		"fieldname": "production_order", | ||||||
|  | 		"label": "Production Order", | ||||||
|  | 		"fieldtype": "Link", | ||||||
|  | 		"options": "Production Order", | ||||||
|  | 		"width": 120 | ||||||
|  | 	},{ | ||||||
|  | 		"fieldname": "bom_no", | ||||||
|  | 		"label": "BOM", | ||||||
|  | 		"fieldtype": "Link", | ||||||
|  | 		"options": "BOM", | ||||||
|  | 		"width": 150 | ||||||
|  | 	},{ | ||||||
|  | 		"fieldname": "description", | ||||||
|  | 		"label": "Description", | ||||||
|  | 		"fieldtype": "Data", | ||||||
|  | 		"options": "", | ||||||
|  | 		"width": 275 | ||||||
|  | 	},{ | ||||||
|  | 		"fieldname": "status", | ||||||
|  | 		"label": "Status", | ||||||
|  | 		"fieldtype": "Data", | ||||||
|  | 		"options": "", | ||||||
|  | 		"width": 120 | ||||||
|  | 	},{ | ||||||
|  | 		"fieldname": "req_items", | ||||||
|  | 		"label": "# of Required Items", | ||||||
|  | 		"fieldtype": "Data", | ||||||
|  | 		"options": "", | ||||||
|  | 		"width": 150 | ||||||
|  | 	},{ | ||||||
|  | 		"fieldname": "instock", | ||||||
|  | 		"label": "# of In Stock Items", | ||||||
|  | 		"fieldtype": "Data", | ||||||
|  | 		"options": "", | ||||||
|  | 		"width": 150 | ||||||
|  | 	},	{ | ||||||
|  | 		"fieldname": "ready_to_build", | ||||||
|  | 		"label": "Can Start?", | ||||||
|  | 		"fieldtype": "Data", | ||||||
|  | 		"options": "", | ||||||
|  | 		"width": 80 | ||||||
|  | 	}] | ||||||
|  | 
 | ||||||
|  | 	return columns | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user