Fixed customer group deletion.
Now any customer associations are dropped first, to avoid database integrity errors.
This commit is contained in:
parent
a681b4f872
commit
aad5e6e2bd
|
@ -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')
|
||||||
|
|
Loading…
Reference in a new issue