[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

@@ -9,7 +9,7 @@ from erpnext.stock.utils import update_bin
from erpnext.stock.stock_ledger import update_entries_after
from erpnext.accounts.utils import get_fiscal_year
def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False):
def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False, only_bin=False):
"""
Repost everything!
"""
@@ -24,7 +24,7 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False)
union
select item_code, warehouse from `tabStock Ledger Entry`) a"""):
try:
repost_stock(d[0], d[1], allow_zero_rate, only_actual)
repost_stock(d[0], d[1], allow_zero_rate, only_actual, only_bin)
frappe.db.commit()
except:
frappe.db.rollback()
@@ -33,22 +33,37 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False)
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)
frappe.db.auto_commit_on_many_writes = 0
def repost_stock(item_code, warehouse, allow_zero_rate=False, only_actual=False):
repost_actual_qty(item_code, warehouse, allow_zero_rate)
def repost_stock(item_code, warehouse, allow_zero_rate=False, only_actual=False, only_bin=False):
if not only_bin:
repost_actual_qty(item_code, warehouse, allow_zero_rate, only_bin)
if item_code and warehouse and not only_actual:
update_bin_qty(item_code, warehouse, {
qty_dict = {
"reserved_qty": get_reserved_qty(item_code, warehouse),
"indented_qty": get_indented_qty(item_code, warehouse),
"ordered_qty": get_ordered_qty(item_code, warehouse),
"planned_qty": get_planned_qty(item_code, warehouse)
})
}
if only_bin:
qty_dict.update({
"actual_qty": get_balance_qty_from_sle(item_code, warehouse)
})
update_bin_qty(item_code, warehouse, qty_dict)
def repost_actual_qty(item_code, warehouse, allow_zero_rate=False):
try:
update_entries_after({ "item_code": item_code, "warehouse": warehouse }, allow_zero_rate)
except:
pass
def get_balance_qty_from_sle(item_code, warehouse):
balance_qty = frappe.db.sql("""select qty_after_transaction from `tabStock Ledger Entry`
where item_code=%s and warehouse=%s and is_cancelled='No'
order by posting_date desc, posting_time desc, name desc
limit 1""", (item_code, warehouse))
return flt(balance_qty[0][0]) if balance_qty else 0.0
def get_reserved_qty(item_code, warehouse):
reserved_qty = frappe.db.sql("""