2015-03-09 11:01:11 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2015-03-09 11:01:11 +00:00
|
|
|
import frappe
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2015-08-24 10:46:29 +00:00
|
|
|
from erpnext.stock.stock_balance import get_reserved_qty, update_bin_qty
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2015-03-09 11:01:11 +00:00
|
|
|
|
|
|
|
def execute():
|
2016-04-20 06:23:34 +00:00
|
|
|
for doctype in ("Sales Order Item", "Bin"):
|
|
|
|
frappe.reload_doctype(doctype)
|
2016-01-07 11:17:44 +00:00
|
|
|
|
2015-08-17 10:06:23 +00:00
|
|
|
repost_for = frappe.db.sql("""
|
2016-01-07 11:17:44 +00:00
|
|
|
select
|
|
|
|
distinct item_code, warehouse
|
|
|
|
from
|
2015-08-17 10:06:23 +00:00
|
|
|
(
|
|
|
|
(
|
2016-01-07 11:17:44 +00:00
|
|
|
select distinct item_code, warehouse
|
2015-08-17 10:06:23 +00:00
|
|
|
from `tabSales Order Item` where docstatus=1
|
|
|
|
) UNION (
|
2016-01-07 11:17:44 +00:00
|
|
|
select distinct item_code, warehouse
|
2015-08-17 10:06:23 +00:00
|
|
|
from `tabPacked Item` where docstatus=1 and parenttype='Sales Order'
|
|
|
|
)
|
2015-08-20 09:29:25 +00:00
|
|
|
) so_item
|
|
|
|
where
|
|
|
|
exists(select name from tabItem where name=so_item.item_code and ifnull(is_stock_item, 0)=1)
|
2015-08-17 10:06:23 +00:00
|
|
|
""")
|
2015-08-20 09:29:25 +00:00
|
|
|
|
2015-08-17 10:06:23 +00:00
|
|
|
for item_code, warehouse in repost_for:
|
2022-02-17 13:55:00 +00:00
|
|
|
if not (item_code and warehouse):
|
|
|
|
continue
|
|
|
|
update_bin_qty(item_code, warehouse, {
|
|
|
|
"reserved_qty": get_reserved_qty(item_code, warehouse)
|
|
|
|
})
|
2016-01-07 11:17:44 +00:00
|
|
|
|
|
|
|
frappe.db.sql("""delete from tabBin
|
2015-08-20 09:51:42 +00:00
|
|
|
where exists(
|
|
|
|
select name from tabItem where name=tabBin.item_code and ifnull(is_stock_item, 0) = 0
|
|
|
|
)
|
2016-01-07 11:17:44 +00:00
|
|
|
""")
|