Fixed customer group deletion.

Now any customer associations are dropped first, to avoid database integrity
errors.
This commit is contained in:
Lance Edgar 2013-07-05 12:04:48 -07:00
parent a681b4f872
commit aad5e6e2bd

View file

@ -29,7 +29,8 @@
from edbob.pyramid.views import SearchableAlchemyGridView from edbob.pyramid.views import SearchableAlchemyGridView
from rattail.pyramid.views import CrudView from rattail.pyramid.views import CrudView
from rattail.db.model import CustomerGroup from rattail.pyramid import Session
from rattail.db.model import CustomerGroup, CustomerGroupAssignment
class CustomerGroupsGrid(SearchableAlchemyGridView): class CustomerGroupsGrid(SearchableAlchemyGridView):
@ -84,6 +85,13 @@ class CustomerGroupCrud(CrudView):
]) ])
return fs return fs
def pre_delete(self, group):
# First remove customer associations.
q = Session.query(CustomerGroupAssignment)\
.filter(CustomerGroupAssignment.group == group)
for assignment in q:
Session.delete(assignment)
def add_routes(config): def add_routes(config):
config.add_route('customer_groups', '/customer-groups') config.add_route('customer_groups', '/customer-groups')