Delete product costs for vendor when deleting vendor.

This commit is contained in:
Lance Edgar 2015-10-17 16:45:39 -05:00
parent b119ccff7d
commit be2a1ba862

View file

@ -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):
"""