diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 12bf2b75..0dfab6eb 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2016 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -406,6 +406,8 @@ class MasterView(View): def get_merge_fields(self): if hasattr(self, 'merge_fields'): return self.merge_fields + mapper = orm.class_mapper(self.get_model_class()) + return mapper.columns.keys() def get_merge_coalesce_fields(self): if hasattr(self, 'merge_coalesce_fields'): diff --git a/tailbone/views/subdepartments.py b/tailbone/views/subdepartments.py index d5e4f6a1..df7692a4 100644 --- a/tailbone/views/subdepartments.py +++ b/tailbone/views/subdepartments.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -24,10 +24,11 @@ Subdepartment Views """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import from rattail.db import model +from tailbone.db import Session from tailbone.views import MasterView from tailbone.views.continuum import VersionView, version_defaults @@ -37,6 +38,16 @@ class SubdepartmentsView(MasterView): Master view for the Subdepartment class. """ model_class = model.Subdepartment + mergeable = True + merge_additive_fields = [ + 'product_count', + ] + merge_fields = merge_additive_fields + [ + 'uuid', + 'number', + 'name', + 'department_number', + ] def configure_grid(self, g): g.filters['name'].default_active = True @@ -59,6 +70,23 @@ class SubdepartmentsView(MasterView): ]) return fs + def get_merge_data(self, subdept): + return { + 'uuid': subdept.uuid, + 'number': subdept.number, + 'name': subdept.name, + 'department_number': subdept.department.number if subdept.department else None, + 'product_count': len(subdept.products), + } + + def merge_objects(self, removing, keeping): + + # merge products + for product in removing.products: + product.subdepartment = keeping + + Session.delete(removing) + class SubdepartmentVersionView(VersionView): """