Add ability to merge subdepartments
This commit is contained in:
parent
0b5a644de1
commit
9ea98bb27b
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2016 Lance Edgar
|
# Copyright © 2010-2017 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -406,6 +406,8 @@ class MasterView(View):
|
||||||
def get_merge_fields(self):
|
def get_merge_fields(self):
|
||||||
if hasattr(self, 'merge_fields'):
|
if hasattr(self, 'merge_fields'):
|
||||||
return 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):
|
def get_merge_coalesce_fields(self):
|
||||||
if hasattr(self, 'merge_coalesce_fields'):
|
if hasattr(self, 'merge_coalesce_fields'):
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2015 Lance Edgar
|
# Copyright © 2010-2017 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,10 +24,11 @@
|
||||||
Subdepartment Views
|
Subdepartment Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
|
from tailbone.db import Session
|
||||||
from tailbone.views import MasterView
|
from tailbone.views import MasterView
|
||||||
from tailbone.views.continuum import VersionView, version_defaults
|
from tailbone.views.continuum import VersionView, version_defaults
|
||||||
|
|
||||||
|
@ -37,6 +38,16 @@ class SubdepartmentsView(MasterView):
|
||||||
Master view for the Subdepartment class.
|
Master view for the Subdepartment class.
|
||||||
"""
|
"""
|
||||||
model_class = model.Subdepartment
|
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):
|
def configure_grid(self, g):
|
||||||
g.filters['name'].default_active = True
|
g.filters['name'].default_active = True
|
||||||
|
@ -59,6 +70,23 @@ class SubdepartmentsView(MasterView):
|
||||||
])
|
])
|
||||||
return fs
|
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):
|
class SubdepartmentVersionView(VersionView):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue