brotherton-erpnext/erpnext/patches/v4_2/repost_reserved_qty.py

45 lines
1.1 KiB
Python
Raw Normal View History

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
2015-03-09 11:01:11 +00:00
import frappe
from erpnext.stock.stock_balance import get_reserved_qty, update_bin_qty
2015-03-09 11:01:11 +00:00
def execute():
for doctype in ("Sales Order Item", "Bin"):
frappe.reload_doctype(doctype)
2022-03-28 13:22:46 +00:00
repost_for = frappe.db.sql(
"""
select
distinct item_code, warehouse
from
(
(
select distinct item_code, warehouse
from `tabSales Order Item` where docstatus=1
) UNION (
select distinct item_code, warehouse
from `tabPacked Item` where docstatus=1 and parenttype='Sales Order'
)
) so_item
where
exists(select name from tabItem where name=so_item.item_code and ifnull(is_stock_item, 0)=1)
2022-03-28 13:22:46 +00:00
"""
)
for item_code, warehouse in repost_for:
if not (item_code and warehouse):
continue
2022-03-28 13:22:46 +00:00
update_bin_qty(item_code, warehouse, {"reserved_qty": get_reserved_qty(item_code, warehouse)})
2022-03-28 13:22:46 +00:00
frappe.db.sql(
"""delete from tabBin
where exists(
select name from tabItem where name=tabBin.item_code and ifnull(is_stock_item, 0) = 0
)
2022-03-28 13:22:46 +00:00
"""
)