patch: repost stock due to wrong packing list entries - optimized query using index and subqueries
This commit is contained in:
parent
786444e6bf
commit
df902d1a0c
@ -1,23 +1,45 @@
|
|||||||
|
import webnotes
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
# add index
|
||||||
|
webnotes.conn.commit()
|
||||||
|
webnotes.conn.sql("""drop index item_code_warehouse on `tabDelivery Note Packing Item`""")
|
||||||
|
webnotes.conn.sql("""create index item_code_warehouse
|
||||||
|
on `tabDelivery Note Packing Item` (item_code, warehouse)""")
|
||||||
|
webnotes.conn.begin()
|
||||||
|
|
||||||
|
repost_reserved_qty()
|
||||||
|
cleanup_wrong_sle()
|
||||||
|
|
||||||
def repost_reserved_qty():
|
def repost_reserved_qty():
|
||||||
import webnotes
|
|
||||||
from webnotes.utils import flt
|
from webnotes.utils import flt
|
||||||
bins = webnotes.conn.sql("select item_code, warehouse, name, reserved_qty from `tabBin`")
|
bins = webnotes.conn.sql("select item_code, warehouse, name, reserved_qty from `tabBin`")
|
||||||
|
i = 0
|
||||||
for d in bins:
|
for d in bins:
|
||||||
|
i += 1
|
||||||
|
print i
|
||||||
reserved_qty = webnotes.conn.sql("""
|
reserved_qty = webnotes.conn.sql("""
|
||||||
select sum((dnpi.qty/so_item.qty)*(so_item.qty - ifnull(so_item.delivered_qty, 0)))
|
select sum((dnpi_qty / so_item_qty) * (so_item_qty - so_item_delivered_qty))
|
||||||
|
from (select
|
||||||
from `tabDelivery Note Packing Item` dnpi, `tabSales Order Item` so_item, `tabSales Order` so
|
qty as dnpi_qty,
|
||||||
|
(
|
||||||
where dnpi.item_code = %s
|
select qty from `tabSales Order Item`
|
||||||
and dnpi.warehouse = %s
|
where name = dnpi.parent_detail_docname
|
||||||
and dnpi.parent = so.name
|
) as so_item_qty,
|
||||||
and so_item.parent = so.name
|
(
|
||||||
and dnpi.parenttype = 'Sales Order'
|
select ifnull(delivered_qty, 0) from `tabSales Order Item`
|
||||||
and dnpi.parent_detail_docname = so_item.name
|
where name = dnpi.parent_detail_docname
|
||||||
and dnpi.parent_item = so_item.item_code
|
) as so_item_delivered_qty
|
||||||
and so.docstatus = 1
|
from
|
||||||
and so.status != 'Stopped'
|
(
|
||||||
""", (d[0], d[1]))
|
select qty, parent_detail_docname
|
||||||
|
from `tabDelivery Note Packing Item` dnpi_in
|
||||||
|
where item_code = %s and warehouse = %s
|
||||||
|
and parenttype="Sales Order"
|
||||||
|
and exists (select * from `tabSales Order` so
|
||||||
|
where name = dnpi_in.parent and docstatus = 1 and status != 'Stopped')
|
||||||
|
) dnpi) tab""", (d[0], d[1]))
|
||||||
|
|
||||||
if flt(d[3]) != flt(reserved_qty[0][0]):
|
if flt(d[3]) != flt(reserved_qty[0][0]):
|
||||||
print d[3], reserved_qty[0][0]
|
print d[3], reserved_qty[0][0]
|
||||||
webnotes.conn.sql("""
|
webnotes.conn.sql("""
|
||||||
@ -67,9 +89,4 @@ def repost_bin(item, wh):
|
|||||||
bin = webnotes.conn.sql("select name from `tabBin` \
|
bin = webnotes.conn.sql("select name from `tabBin` \
|
||||||
where item_code = %s and warehouse = %s", (item, wh))
|
where item_code = %s and warehouse = %s", (item, wh))
|
||||||
|
|
||||||
get_obj('Bin', bin[0][0]).update_entries_after(posting_date = '2012-07-01', posting_time = '12:05')
|
get_obj('Bin', bin[0][0]).update_entries_after(posting_date = '2012-07-01', posting_time = '12:05')
|
||||||
|
|
||||||
|
|
||||||
def execute():
|
|
||||||
repost_reserved_qty()
|
|
||||||
cleanup_wrong_sle()
|
|
@ -509,4 +509,8 @@ patch_list = [
|
|||||||
'patch_module': 'patches.july_2012',
|
'patch_module': 'patches.july_2012',
|
||||||
'patch_file': 'project_patch_repeat',
|
'patch_file': 'project_patch_repeat',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'patch_module': 'patches.july_2012',
|
||||||
|
'patch_file': 'repost_stock_due_to_wrong_packing_list',
|
||||||
|
},
|
||||||
]
|
]
|
Loading…
Reference in New Issue
Block a user