mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 17:04:47 +00:00
Fixed stock query and corrected with suggestions from rohit
This commit is contained in:
@@ -8,12 +8,12 @@
|
|||||||
"idx": 0,
|
"idx": 0,
|
||||||
"is_standard": "Yes",
|
"is_standard": "Yes",
|
||||||
"letter_head": "Standard",
|
"letter_head": "Standard",
|
||||||
"modified": "2017-01-10 14:00:54.341088",
|
"modified": "2017-02-07 09:10:10.954616",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "BOM Stock Report",
|
"name": "BOM Stock Report",
|
||||||
"owner": "Administrator",
|
"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",
|
"query": "SELECT \n\tbom_item.item_code as \"Item:Link/Item:200\",\n\tbom_item.description as \"Description:Data:300\",\n\tROUND(bom_item.qty * conf_item.conversion_factor,2) as \"Required Qty:Float:100\",\n\tROUND(ledger.actual_qty * conf_ledger.conversion_factor,2) as \"In Stock Qty:Float:100\",\n\tFLOOR((ledger.actual_qty * conf_ledger.conversion_factor)/(bom_item.qty * \t\t \tconf_item.conversion_factor)) as \"Enough Parts to Build:Int:100\"\nFROM\n\t`tabBOM Item` AS bom_item \n\tLEFT JOIN `tabBin` AS ledger\t\n\tON bom_item.item_code = ledger.item_code AND ledger.warehouse = %(warehouse)s\n\tLEFT JOIN `tabUOM Conversion Detail` AS conf_item\n\tON conf_item.parent = bom_item.item_code AND conf_item.uom = bom_item.stock_uom\n\tLEFT JOIN `tabUOM Conversion Detail` AS conf_ledger\n\tON conf_ledger.parent = ledger.item_code AND conf_ledger.uom = ledger.stock_uom\nWHERE\n\tbom_item.parent=%(bom)s\n\nGROUP BY bom_item.item_code",
|
||||||
"ref_doctype": "BOM",
|
"ref_doctype": "BOM",
|
||||||
"report_name": "BOM Stock Report",
|
"report_name": "BOM Stock Report",
|
||||||
"report_type": "Query Report"
|
"report_type": "Query Report"
|
||||||
|
|||||||
@@ -2,5 +2,14 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.query_reports["Production Order Stock Report"] = {
|
frappe.query_reports["Production Order Stock Report"] = {
|
||||||
|
"filters": [
|
||||||
|
{
|
||||||
|
"fieldname":"warehouse",
|
||||||
|
"label": __("Warehouse"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Warehouse",
|
||||||
|
"default": "Stores - VMI"
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,46 +6,41 @@ from frappe.utils import flt, cint
|
|||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
|
|
||||||
|
|
||||||
prod_list = get_production_orders()
|
prod_list = get_production_orders()
|
||||||
|
data = get_item_list( prod_list, filters)
|
||||||
data = get_item_list( prod_list)
|
|
||||||
|
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
def get_item_list(prod_list):
|
|
||||||
|
|
||||||
|
def get_item_list(prod_list, filters):
|
||||||
out = []
|
out = []
|
||||||
|
|
||||||
low_price_data = []
|
low_price_data = []
|
||||||
low_supplier = []
|
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
|
|
||||||
|
|
||||||
|
# Get the default supplier of suppliers
|
||||||
#Add a row for each item/qty
|
#Add a row for each item/qty
|
||||||
for root in prod_list:
|
for root in prod_list:
|
||||||
bom = frappe.db.get_value("Production Order", root.name,"bom_no")
|
bom = frappe.db.get_value("Production Order", root.name,"bom_no")
|
||||||
|
warehouse = frappe.db.get_value("Production Order", root.name,"source_warehouse")
|
||||||
|
warehouse = "Stores - VMI"
|
||||||
desc = frappe.db.get_value("BOM", bom, "description")
|
desc = frappe.db.get_value("BOM", bom, "description")
|
||||||
qty = frappe.db.get_value("Production Order", root.name,"qty")
|
qty = frappe.db.get_value("Production Order", root.name,"qty")
|
||||||
|
|
||||||
item_list = frappe.db.sql(""" SELECT
|
item_list = frappe.db.sql("""SELECT
|
||||||
bom_item.item_code as item_code,
|
bom_item.item_code as item_code,
|
||||||
SUM(ifnull(ledger.actual_qty,0))/bom_item.qty as build_qty
|
SUM(ifnull(ledger.actual_qty * conf_ledger.conversion_factor,0))/(bom_item.qty * conf_item.conversion_factor) as build_qty
|
||||||
FROM
|
FROM
|
||||||
`tabBOM Item` AS bom_item
|
`tabBOM Item` AS bom_item
|
||||||
LEFT JOIN `tabStock Ledger Entry` AS ledger
|
LEFT JOIN `tabBin` AS ledger
|
||||||
ON bom_item.item_code = ledger.item_code
|
ON bom_item.item_code = ledger.item_code AND ledger.warehouse = ifnull(%(warehouse)s,%(filterhouse)s)
|
||||||
WHERE
|
LEFT JOIN `tabUOM Conversion Detail` AS conf_item
|
||||||
bom_item.parent=%(bom)s
|
ON conf_item.parent = bom_item.item_code AND conf_item.uom = bom_item.stock_uom
|
||||||
GROUP BY
|
LEFT JOIN `tabUOM Conversion Detail` AS conf_ledger
|
||||||
bom_item.item_code""", {"bom": bom}, as_dict=1)
|
ON conf_ledger.parent = ledger.item_code AND conf_ledger.uom = ledger.stock_uom
|
||||||
|
WHERE
|
||||||
|
bom_item.parent = %(bom)s
|
||||||
|
GROUP BY
|
||||||
|
bom_item.item_code""", {"bom": bom, "warehouse": warehouse, "filterhouse": filters.warehouse}, as_dict=1)
|
||||||
stock_qty = 0
|
stock_qty = 0
|
||||||
count = 0
|
count = 0
|
||||||
for item in item_list:
|
for item in item_list:
|
||||||
@@ -64,6 +59,7 @@ def get_item_list(prod_list):
|
|||||||
"instock": stock_qty,
|
"instock": stock_qty,
|
||||||
"description": desc,
|
"description": desc,
|
||||||
"bom_no": bom,
|
"bom_no": bom,
|
||||||
|
"qty": qty,
|
||||||
"ready_to_build": build
|
"ready_to_build": build
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -73,14 +69,15 @@ def get_item_list(prod_list):
|
|||||||
|
|
||||||
def get_production_orders():
|
def get_production_orders():
|
||||||
|
|
||||||
out = []
|
#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 = 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)
|
out = frappe.get_all("Production Order", filters={"docstatus": 1, "status": ( "!=","Completed")}, fields=["name","status"], order_by='name')
|
||||||
|
#prod_list.sort(reverse=False)
|
||||||
|
|
||||||
for po in prod_list:
|
#for po in prod_list:
|
||||||
out.append(po)
|
#out.append(po)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@@ -90,43 +87,49 @@ def get_columns():
|
|||||||
"label": "Production Order",
|
"label": "Production Order",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Production Order",
|
"options": "Production Order",
|
||||||
"width": 120
|
"width": 110
|
||||||
},{
|
},{
|
||||||
"fieldname": "bom_no",
|
"fieldname": "bom_no",
|
||||||
"label": "BOM",
|
"label": "BOM",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "BOM",
|
"options": "BOM",
|
||||||
"width": 150
|
"width": 130
|
||||||
},{
|
},{
|
||||||
"fieldname": "description",
|
"fieldname": "description",
|
||||||
"label": "Description",
|
"label": "Description",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"options": "",
|
"options": "",
|
||||||
"width": 275
|
"width": 250
|
||||||
|
},{
|
||||||
|
"fieldname": "qty",
|
||||||
|
"label": "Qty to Build",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"options": "",
|
||||||
|
"width": 110
|
||||||
},{
|
},{
|
||||||
"fieldname": "status",
|
"fieldname": "status",
|
||||||
"label": "Status",
|
"label": "Status",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"options": "",
|
"options": "",
|
||||||
"width": 120
|
"width": 110
|
||||||
},{
|
},{
|
||||||
"fieldname": "req_items",
|
"fieldname": "req_items",
|
||||||
"label": "# of Required Items",
|
"label": "# of Required Items",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"options": "",
|
"options": "",
|
||||||
"width": 150
|
"width": 135
|
||||||
},{
|
},{
|
||||||
"fieldname": "instock",
|
"fieldname": "instock",
|
||||||
"label": "# of In Stock Items",
|
"label": "# of In Stock Items",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"options": "",
|
"options": "",
|
||||||
"width": 150
|
"width": 135
|
||||||
}, {
|
}, {
|
||||||
"fieldname": "ready_to_build",
|
"fieldname": "ready_to_build",
|
||||||
"label": "Can Start?",
|
"label": "Can Start?",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"options": "",
|
"options": "",
|
||||||
"width": 80
|
"width": 75
|
||||||
}]
|
}]
|
||||||
|
|
||||||
return columns
|
return columns
|
||||||
|
|||||||
Reference in New Issue
Block a user