diff --git a/tailbone/views/vendors/core.py b/tailbone/views/vendors/core.py index 0f2af425..c87b1e3a 100644 --- a/tailbone/views/vendors/core.py +++ b/tailbone/views/vendors/core.py @@ -29,6 +29,7 @@ from __future__ import unicode_literals from rattail.db import model from rattail.db.model import Vendor +from tailbone.db import Session from tailbone.views import SearchableAlchemyGridView, CrudView, AutocompleteView from tailbone.views.continuum import VersionView, version_defaults from tailbone.forms import AssociationProxyField, PersonFieldRenderer @@ -97,6 +98,14 @@ class VendorCrud(CrudView): ]) return fs + def pre_delete(self, vendor): + + # Remove all product costs. + q = Session.query(model.ProductCost).filter( + model.ProductCost.vendor == vendor) + for cost in q: + Session.delete(cost) + class VendorVersionView(VersionView): """