[report] available qty for packing items
This commit is contained in:
parent
510a45bfb4
commit
e26acffcfe
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-01-10 16:34:29",
|
"creation": "2013-06-20 11:53:21",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-01-22 14:57:23",
|
"modified": "2013-06-25 16:43:18",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -11,7 +11,7 @@
|
|||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"document_type": "Master",
|
"document_type": "Master",
|
||||||
"is_submittable": 0,
|
"is_submittable": 0,
|
||||||
"module": "Stock",
|
"module": "Selling",
|
||||||
"name": "__common__"
|
"name": "__common__"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -23,7 +23,6 @@
|
|||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"amend": 0,
|
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"name": "__common__",
|
"name": "__common__",
|
||||||
"parent": "Sales BOM",
|
"parent": "Sales BOM",
|
||||||
@ -74,6 +73,7 @@
|
|||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"amend": 1,
|
||||||
"cancel": 1,
|
"cancel": 1,
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
@ -81,6 +81,7 @@
|
|||||||
"write": 1
|
"write": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"amend": 0,
|
||||||
"cancel": 0,
|
"cancel": 0,
|
||||||
"create": 0,
|
"create": 0,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
@ -88,6 +89,7 @@
|
|||||||
"write": 0
|
"write": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"amend": 0,
|
||||||
"cancel": 1,
|
"cancel": 1,
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-02-22 01:28:03",
|
"creation": "2013-05-23 16:55:51",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-03-07 07:03:30",
|
"modified": "2013-06-26 13:45:41",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"module": "Stock",
|
"module": "Selling",
|
||||||
"name": "__common__"
|
"name": "__common__"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -16,33 +16,33 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import cint
|
from webnotes.utils import flt
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters = {}
|
if not filters: filters = {}
|
||||||
|
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
item_warehouse_quantity_map = get_item_warehouse_quantity_map()
|
iwq_map = get_item_warehouse_quantity_map()
|
||||||
|
item_map = get_item_details()
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for item, warehouse in item_warehouse_quantity_map.items():
|
for sbom, warehouse in iwq_map.items():
|
||||||
item_details = get_item_details(item)[0]
|
|
||||||
total = 0
|
total = 0
|
||||||
total_qty = 0
|
total_qty = 0
|
||||||
|
|
||||||
for wh, item_qty in warehouse.items():
|
for wh, item_qty in warehouse.items():
|
||||||
total += 1
|
total += 1
|
||||||
row = [item, item_details.item_name, item_details.description, \
|
row = [sbom, item_map.get(sbom).item_name, item_map.get(sbom).description,
|
||||||
item_details.stock_uom, wh]
|
item_map.get(sbom).stock_uom, wh]
|
||||||
for quantity in item_qty.items():
|
available_qty = min(item_qty.values())
|
||||||
max_qty = []
|
total_qty += flt(available_qty)
|
||||||
max_qty.append(quantity[1])
|
row += [available_qty]
|
||||||
max_qty = min(max_qty)
|
|
||||||
total_qty += cint(max_qty.qty)
|
if available_qty:
|
||||||
row += [max_qty.qty]
|
|
||||||
data.append(row)
|
|
||||||
if (total == len(warehouse)):
|
|
||||||
row = ["", "", "Total", "", "", total_qty]
|
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
if (total == len(warehouse)):
|
||||||
|
row = ["", "", "Total", "", "", total_qty]
|
||||||
|
data.append(row)
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
@ -52,38 +52,41 @@ def get_columns():
|
|||||||
|
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
def get_sales_bom():
|
def get_sales_bom_items():
|
||||||
return webnotes.conn.sql("""select name from `tabSales BOM`""", as_dict=1)
|
sbom_item_map = {}
|
||||||
|
for sbom in webnotes.conn.sql("""select parent, item_code, qty from `tabSales BOM Item`
|
||||||
|
where docstatus < 2""", as_dict=1):
|
||||||
|
sbom_item_map.setdefault(sbom.parent, {}).setdefault(sbom.item_code, sbom.qty)
|
||||||
|
|
||||||
|
return sbom_item_map
|
||||||
|
|
||||||
def get_sales_bom_items(item):
|
def get_item_details():
|
||||||
return webnotes.conn.sql("""select parent, item_code, qty from `tabSales BOM Item`
|
item_map = {}
|
||||||
where parent=%s""", (item), as_dict=1)
|
for item in webnotes.conn.sql("""select name, item_name, description, stock_uom
|
||||||
|
from `tabItem`""", as_dict=1):
|
||||||
|
item_map.setdefault(item.name, item)
|
||||||
|
|
||||||
|
return item_map
|
||||||
|
|
||||||
def get_item_details(item):
|
def get_item_warehouse_quantity():
|
||||||
return webnotes.conn.sql("""select name, item_name, description, stock_uom
|
iwq_map = {}
|
||||||
from `tabItem` where name=%s""", (item), as_dict=1)
|
bin = webnotes.conn.sql("""select item_code, warehouse, actual_qty from `tabBin`
|
||||||
|
where actual_qty > 0""")
|
||||||
def get_item_warehouse_quantity(item):
|
for item, wh, qty in bin:
|
||||||
return webnotes.conn.sql("""select item_code, warehouse, actual_qty from `tabBin`
|
iwq_map.setdefault(item, {}).setdefault(wh, qty)
|
||||||
where item_code=%s""", (item), as_dict=1)
|
|
||||||
|
return iwq_map
|
||||||
|
|
||||||
def get_item_warehouse_quantity_map():
|
def get_item_warehouse_quantity_map():
|
||||||
iwq_map = {}
|
sbom_map = {}
|
||||||
|
iwq_map = get_item_warehouse_quantity()
|
||||||
|
sbom_item_map = get_sales_bom_items()
|
||||||
|
|
||||||
|
for sbom, sbom_items in sbom_item_map.items():
|
||||||
|
for item, child_qty in sbom_items.items():
|
||||||
|
for wh, qty in iwq_map.get(item, {}).items():
|
||||||
|
avail_qty = flt(qty) / flt(child_qty)
|
||||||
|
sbom_map.setdefault(sbom, {}).setdefault(wh, {}) \
|
||||||
|
.setdefault(item, avail_qty)
|
||||||
|
|
||||||
sales_bom = get_sales_bom()
|
return sbom_map
|
||||||
|
|
||||||
for item in sales_bom:
|
|
||||||
child_item = get_sales_bom_items(item.name)
|
|
||||||
for child in child_item:
|
|
||||||
item_warehouse_quantity = get_item_warehouse_quantity(child.item_code)
|
|
||||||
for iwq in item_warehouse_quantity:
|
|
||||||
iwq_map.setdefault(item.name, {}).setdefault(iwq.warehouse, {}).\
|
|
||||||
setdefault(child.item_code, webnotes._dict({
|
|
||||||
"qty" : 0
|
|
||||||
}))
|
|
||||||
|
|
||||||
q_dict = iwq_map[item.name][iwq.warehouse][child.item_code]
|
|
||||||
|
|
||||||
q_dict.qty = cint(iwq.actual_qty / child.qty)
|
|
||||||
|
|
||||||
return iwq_map
|
|
||||||
Loading…
x
Reference in New Issue
Block a user