def execute(): for doctype in ("Sales Order Item", "Bin"): frappe.reload_doctype(doctype) 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) """) for item_code, warehouse in repost_for: update_bin_qty( item_code, warehouse, {"reserved_qty": get_reserved_qty(item_code, warehouse)}) frappe.db.sql("""delete from tabBin where exists( select name from tabItem where name=tabBin.item_code and ifnull(is_stock_item, 0) = 0 ) """)
def execute(): bin_details = frappe.db.sql(""" SELECT item_code, warehouse FROM `tabBin`""",as_dict=1) for entry in bin_details: update_bin_qty(entry.get("item_code"), entry.get("warehouse"), { "indented_qty": get_indented_qty(entry.get("item_code"), entry.get("warehouse")) })
def execute(): for item_code, warehouse in frappe.db.sql( """select distinct production_item, fg_warehouse from `tabWork Order`"""): if frappe.db.exists("Item", item_code) and frappe.db.exists( "Warehouse", warehouse): update_bin_qty( item_code, warehouse, {"planned_qty": get_planned_qty(item_code, warehouse)})
def update_planned_qty(self): update_bin_qty( self.production_item, self.fg_warehouse, { "planned_qty": get_planned_qty(self.production_item, self.fg_warehouse) }) if self.material_request: mr_obj = frappe.get_doc("Material Request", self.material_request) mr_obj.update_requested_qty([self.material_request_item])
def update_requested_qty(self, mr_item_rows=None): """update requested qty (before ordered_qty is updated)""" item_wh_list = [] for d in self.get("items"): if (not mr_item_rows or d.name in mr_item_rows) and [d.item_code, d.warehouse] not in item_wh_list \ and frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 and d.warehouse: item_wh_list.append([d.item_code, d.warehouse]) for item_code, warehouse in item_wh_list: update_bin_qty( item_code, warehouse, {"indented_qty": get_indented_qty(item_code, warehouse)})
def execute(): for doctype in ("Sales Order Item", "Bin"): frappe.reload_doctype(doctype) repost_for = frappe.db.sql("""select distinct item_code, warehouse from `tabSales Order Item` where docstatus=1 and uom != stock_uom and exists(select name from tabItem where name=`tabSales Order Item`.item_code and ifnull(is_stock_item, 0)=1)""") for item_code, warehouse in repost_for: update_bin_qty(item_code, warehouse, { "reserved_qty": get_reserved_qty(item_code, warehouse) })
def update_ordered_qty(self, po_item_rows=None): """update requested qty (before ordered_qty is updated)""" item_wh_list = [] for d in self.get("items"): if (not po_item_rows or d.name in po_item_rows) \ and [d.item_code, d.warehouse] not in item_wh_list \ and frappe.get_cached_value("Item", d.item_code, "is_stock_item") \ and d.warehouse and not d.delivered_by_supplier: item_wh_list.append([d.item_code, d.warehouse]) for item_code, warehouse in item_wh_list: update_bin_qty( item_code, warehouse, {"ordered_qty": get_ordered_qty(item_code, warehouse)})
def execute(): from erpbee.stock.stock_balance import update_bin_qty, get_indented_qty count=0 for item_code, warehouse in frappe.db.sql("""select distinct item_code, warehouse from `tabMaterial Request Item` where docstatus = 1"""): try: count += 1 update_bin_qty(item_code, warehouse, { "indented_qty": get_indented_qty(item_code, warehouse), }) if count % 200 == 0: frappe.db.commit() except: frappe.db.rollback()
def execute(): from erpbee.stock.stock_balance import update_bin_qty, get_indented_qty, get_ordered_qty count = 0 for item_code, warehouse in frappe.db.sql( """select distinct item_code, warehouse from (select item_code, warehouse from tabBin union select item_code, warehouse from `tabStock Ledger Entry`) a"""): try: count += 1 update_bin_qty( item_code, warehouse, { "indented_qty": get_indented_qty(item_code, warehouse), "ordered_qty": get_ordered_qty(item_code, warehouse) }) if count % 200 == 0: frappe.db.commit() except: frappe.db.rollback()