On deletion of warehouse, delete bin and sle if no qty

This commit is contained in:
Nabin Hait
2011-11-23 12:58:03 +05:30
parent b327803220
commit 816383056f

View File

@@ -88,3 +88,18 @@ class DocType:
if cstr(self.doc.warehouse_type) != cstr(wt and wt[0][0] or ''):
sql("update `tabStock Ledger Entry` set warehouse_type = '%s' where warehouse = '%s'" % (self.doc.warehouse_type, self.doc.name))
msgprint("All Stock Ledger Entries Updated.")
def on_trash(self):
# delete bin
bins = sql("select * from `tabBin` where warehouse = %s", self.doc.name, as_dict=1)
for d in bins:
if d['actual_qty'] or d['reserved_qty'] or d['ordered_qty'] or d['indented_qty'] or d['projected_qty'] or d['planned_qty']:
msgprint("Warehouse: %s can not be deleted as qty exists for item: %s" % (self.doc.name, d['item_code']), raise_exception=1)
else:
sql("delete from `tabBin` where name = %s", d['name'])
# delete cancelled sle
if sql("select name from `tabStock Ledger Entry` where warehouse = %s and ifnull('is_cancelled', '') = 'No'", self.doc.name):
mdgprint("Warehosue can not be deleted as stock ledger entry exists for this warehosue.", raise_exception=1)
else:
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)