From aad5e6e2bdccfd210cf42f55b9e1f468548bdb86 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 5 Jul 2013 12:04:48 -0700 Subject: [PATCH] Fixed customer group deletion. Now any customer associations are dropped first, to avoid database integrity errors. --- rattail/pyramid/views/customergroups.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rattail/pyramid/views/customergroups.py b/rattail/pyramid/views/customergroups.py index af3a3bf6..fd7d5f79 100644 --- a/rattail/pyramid/views/customergroups.py +++ b/rattail/pyramid/views/customergroups.py @@ -29,7 +29,8 @@ from edbob.pyramid.views import SearchableAlchemyGridView 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): @@ -84,6 +85,13 @@ class CustomerGroupCrud(CrudView): ]) 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): config.add_route('customer_groups', '/customer-groups')