From be2a1ba862d4f990a334173c28c270863bbf4da7 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 17 Oct 2015 16:45:39 -0500 Subject: [PATCH] Delete product costs for vendor when deleting vendor. --- tailbone/views/vendors/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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): """