mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
On deletion of warehouse, delete bin and sle if no qty
This commit is contained in:
@@ -88,3 +88,18 @@ class DocType:
|
|||||||
if cstr(self.doc.warehouse_type) != cstr(wt and wt[0][0] or ''):
|
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))
|
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.")
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user