[fix][patch] Delete duplicate bins

This commit is contained in:
Nabin Hait
2015-10-12 16:46:29 +05:30
parent bc5ecfff06
commit b7e46c4ed9
4 changed files with 45 additions and 9 deletions

View File

@@ -0,0 +1,20 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.stock.stock_balance import repost_stock
def execute():
bins = frappe.db.sql("""select item_code, warehouse, count(*) from `tabBin`
group by item_code, warehouse having count(*) > 1""", as_dict=True)
for d in bins:
try:
frappe.db.sql("delete from tabBin where item_code=%s and warehouse=%s", (d.item_code, d.warehouse))
repost_stock(d.item_code, d.warehouse, allow_zero_rate=True, only_actual=False, only_bin=True)
frappe.db.commit()
except:
frappe.db.rollback()