Prevent deletion of department which still has products
This commit is contained in:
parent
964671fcbf
commit
9b00e829b8
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2018 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -82,6 +82,19 @@ class DepartmentsView(MasterView):
|
||||||
kwargs['employees'] = None
|
kwargs['employees'] = None
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
def before_delete(self, department):
|
||||||
|
"""
|
||||||
|
Check to see if there are any products which belong to the department;
|
||||||
|
if there are then we do not allow delete and redirect the user.
|
||||||
|
"""
|
||||||
|
count = self.Session.query(model.Product)\
|
||||||
|
.filter(model.Product.department == department)\
|
||||||
|
.count()
|
||||||
|
if count:
|
||||||
|
self.request.session.flash("Will not delete department which still has {} products: {}".format(
|
||||||
|
count, department), 'error')
|
||||||
|
raise self.redirect(self.get_action_url('view', department))
|
||||||
|
|
||||||
def list_by_vendor(self):
|
def list_by_vendor(self):
|
||||||
"""
|
"""
|
||||||
View list of departments by vendor
|
View list of departments by vendor
|
||||||
|
|
Loading…
Reference in a new issue