From 1ac9a8e82ed92e72455f4f6c761faeb4c121f210 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Mon, 15 Jul 2019 14:08:47 +0530 Subject: [PATCH] fix(bin): update requested qty in bin (#18297) --- erpnext/patches.txt | 3 ++- ...t_requested_qty_for_non_stock_uom_items.py | 21 +++++++++++++++++++ erpnext/stock/stock_balance.py | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v10_0/repost_requested_qty_for_non_stock_uom_items.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index a29378547e..f5666dfc60 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -505,6 +505,7 @@ erpnext.patches.v10_0.update_hub_connector_domain erpnext.patches.v10_0.set_student_party_type erpnext.patches.v10_0.update_project_in_sle erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract +erpnext.patches.v10_0.repost_requested_qty_for_non_stock_uom_items erpnext.patches.v11_0.merge_land_unit_with_location erpnext.patches.v11_0.add_index_on_nestedset_doctypes erpnext.patches.v11_0.remove_modules_setup_page @@ -619,4 +620,4 @@ erpnext.patches.v12_0.delete_priority_property_setter execute:frappe.delete_doc("DocType", "Project Task") erpnext.patches.v11_1.update_default_supplier_in_item_defaults erpnext.patches.v12_0.update_due_date_in_gle -erpnext.patches.v12_0.add_default_buying_selling_terms_in_company +erpnext.patches.v12_0.add_default_buying_selling_terms_in_company \ No newline at end of file diff --git a/erpnext/patches/v10_0/repost_requested_qty_for_non_stock_uom_items.py b/erpnext/patches/v10_0/repost_requested_qty_for_non_stock_uom_items.py new file mode 100644 index 0000000000..4fe4e97cf5 --- /dev/null +++ b/erpnext/patches/v10_0/repost_requested_qty_for_non_stock_uom_items.py @@ -0,0 +1,21 @@ +# Copyright (c) 2019, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + from erpnext.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 and stock_uom<>uom"""): + 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() diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index 4d07a0e857..d68f97917f 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -110,7 +110,7 @@ def get_reserved_qty(item_code, warehouse): return flt(reserved_qty[0][0]) if reserved_qty else 0 def get_indented_qty(item_code, warehouse): - indented_qty = frappe.db.sql("""select sum(mr_item.qty - mr_item.ordered_qty) + indented_qty = frappe.db.sql("""select sum((mr_item.qty - mr_item.ordered_qty) * mr_item.conversion_factor) from `tabMaterial Request Item` mr_item, `tabMaterial Request` mr where mr_item.item_code=%s and mr_item.warehouse=%s and mr_item.qty > mr_item.ordered_qty and mr_item.parent=mr.name