2015-02-09 13:30:29 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-04-10 22:28:02 -05:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2015-02-09 13:30:29 -06:00
|
|
|
# Copyright © 2010-2015 Lance Edgar
|
2012-04-10 22:28:02 -05:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
|
|
|
# more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
2013-09-01 09:27:47 -05:00
|
|
|
Department Views
|
2012-04-10 22:28:02 -05:00
|
|
|
"""
|
|
|
|
|
2015-02-09 13:30:29 -06:00
|
|
|
from __future__ import unicode_literals
|
2012-04-10 22:28:02 -05:00
|
|
|
|
2015-02-09 15:33:16 -06:00
|
|
|
from rattail.db import model
|
2013-06-19 16:21:45 -05:00
|
|
|
from rattail.db.model import Department, Product, ProductCost, Vendor
|
2012-04-10 22:28:02 -05:00
|
|
|
|
2015-02-09 13:30:29 -06:00
|
|
|
from . import SearchableAlchemyGridView, CrudView, AlchemyGridView, AutocompleteView
|
2015-02-09 15:33:16 -06:00
|
|
|
from .continuum import VersionView, version_defaults
|
2015-02-09 13:30:29 -06:00
|
|
|
|
2012-04-10 22:28:02 -05:00
|
|
|
|
2012-08-06 17:05:09 -05:00
|
|
|
class DepartmentsGrid(SearchableAlchemyGridView):
|
|
|
|
|
2013-06-19 16:21:45 -05:00
|
|
|
mapped_class = Department
|
2012-08-16 12:31:24 -05:00
|
|
|
config_prefix = 'departments'
|
2012-08-06 17:05:09 -05:00
|
|
|
sort = 'name'
|
|
|
|
|
|
|
|
def filter_map(self):
|
|
|
|
return self.make_filter_map(ilike=['name'])
|
|
|
|
|
|
|
|
def filter_config(self):
|
|
|
|
return self.make_filter_config(
|
|
|
|
include_filter_name=True,
|
|
|
|
filter_type_name='lk')
|
|
|
|
|
|
|
|
def sort_map(self):
|
|
|
|
return self.make_sort_map('number', 'name')
|
|
|
|
|
|
|
|
def grid(self):
|
|
|
|
g = self.make_grid()
|
|
|
|
g.configure(
|
|
|
|
include=[
|
|
|
|
g.number,
|
|
|
|
g.name,
|
|
|
|
],
|
|
|
|
readonly=True)
|
2012-11-18 10:38:11 -06:00
|
|
|
if self.request.has_perm('departments.read'):
|
2013-07-22 23:32:54 -05:00
|
|
|
g.viewable = True
|
|
|
|
g.view_route_name = 'department.read'
|
2012-11-18 10:38:11 -06:00
|
|
|
if self.request.has_perm('departments.update'):
|
|
|
|
g.editable = True
|
|
|
|
g.edit_route_name = 'department.update'
|
|
|
|
if self.request.has_perm('departments.delete'):
|
|
|
|
g.deletable = True
|
|
|
|
g.delete_route_name = 'department.delete'
|
2012-08-06 17:05:09 -05:00
|
|
|
return g
|
|
|
|
|
|
|
|
|
2012-11-18 10:38:11 -06:00
|
|
|
class DepartmentCrud(CrudView):
|
|
|
|
|
2013-06-19 16:21:45 -05:00
|
|
|
mapped_class = Department
|
2012-11-18 10:38:11 -06:00
|
|
|
home_route = 'departments'
|
|
|
|
|
|
|
|
def fieldset(self, model):
|
|
|
|
fs = self.make_fieldset(model)
|
|
|
|
fs.configure(
|
|
|
|
include=[
|
|
|
|
fs.number,
|
|
|
|
fs.name,
|
|
|
|
])
|
|
|
|
return fs
|
|
|
|
|
|
|
|
|
2015-02-09 15:33:16 -06:00
|
|
|
class DepartmentVersionView(VersionView):
|
|
|
|
"""
|
|
|
|
View which shows version history for a department.
|
|
|
|
"""
|
|
|
|
parent_class = model.Department
|
|
|
|
route_model_view = 'department.read'
|
|
|
|
|
|
|
|
|
2012-08-06 17:05:09 -05:00
|
|
|
class DepartmentsByVendorGrid(AlchemyGridView):
|
|
|
|
|
2013-06-19 16:21:45 -05:00
|
|
|
mapped_class = Department
|
2012-08-16 12:31:24 -05:00
|
|
|
config_prefix = 'departments.by_vendor'
|
2012-08-06 17:05:09 -05:00
|
|
|
checkboxes = True
|
|
|
|
partial_only = True
|
|
|
|
|
|
|
|
def query(self):
|
|
|
|
q = self.make_query()
|
2013-06-19 16:21:45 -05:00
|
|
|
q = q.outerjoin(Product)
|
|
|
|
q = q.join(ProductCost)
|
|
|
|
q = q.join(Vendor)
|
|
|
|
q = q.filter(Vendor.uuid == self.request.params['uuid'])
|
2012-08-06 17:05:09 -05:00
|
|
|
q = q.distinct()
|
2013-06-19 16:21:45 -05:00
|
|
|
q = q.order_by(Department.name)
|
2012-04-10 22:28:02 -05:00
|
|
|
return q
|
|
|
|
|
2012-08-06 17:05:09 -05:00
|
|
|
def grid(self):
|
|
|
|
g = self.make_grid()
|
|
|
|
g.configure(
|
|
|
|
include=[
|
|
|
|
g.name,
|
|
|
|
],
|
|
|
|
readonly=True)
|
|
|
|
return g
|
2012-04-16 00:51:12 -05:00
|
|
|
|
|
|
|
|
2012-10-04 10:40:27 -05:00
|
|
|
class DepartmentsAutocomplete(AutocompleteView):
|
|
|
|
|
2013-06-19 16:21:45 -05:00
|
|
|
mapped_class = Department
|
2012-10-04 10:40:27 -05:00
|
|
|
fieldname = 'name'
|
|
|
|
|
|
|
|
|
2015-02-09 13:30:29 -06:00
|
|
|
def add_routes(config):
|
|
|
|
config.add_route('departments', '/departments')
|
|
|
|
config.add_route('departments.autocomplete', '/departments/autocomplete')
|
|
|
|
config.add_route('departments.by_vendor', '/departments/by-vendor')
|
|
|
|
config.add_route('department.create', '/departments/new')
|
|
|
|
config.add_route('department.read', '/departments/{uuid}')
|
|
|
|
config.add_route('department.update', '/departments/{uuid}/edit')
|
|
|
|
config.add_route('department.delete', '/departments/{uuid}/delete')
|
|
|
|
|
|
|
|
|
2012-04-10 22:28:02 -05:00
|
|
|
def includeme(config):
|
2015-02-09 13:30:29 -06:00
|
|
|
add_routes(config)
|
2012-08-06 17:05:09 -05:00
|
|
|
|
2015-02-09 13:30:29 -06:00
|
|
|
# list
|
|
|
|
config.add_view(DepartmentsGrid, route_name='departments',
|
|
|
|
renderer='/departments/index.mako', permission='departments.list')
|
2012-08-16 12:31:24 -05:00
|
|
|
|
2015-02-09 13:30:29 -06:00
|
|
|
# autocomplete
|
|
|
|
config.add_view(DepartmentsAutocomplete, route_name='departments.autocomplete',
|
|
|
|
renderer='json', permission='departments.list')
|
2012-10-04 10:40:27 -05:00
|
|
|
|
2015-02-09 13:30:29 -06:00
|
|
|
# departments by vendor list
|
|
|
|
config.add_view(DepartmentsByVendorGrid,route_name='departments.by_vendor',
|
2012-08-16 12:31:24 -05:00
|
|
|
permission='departments.list')
|
2012-11-18 10:38:11 -06:00
|
|
|
|
2015-02-09 13:30:29 -06:00
|
|
|
# crud
|
|
|
|
config.add_view(DepartmentCrud, attr='create', route_name='department.create',
|
|
|
|
renderer='/departments/crud.mako', permission='departments.create')
|
|
|
|
config.add_view(DepartmentCrud, attr='read', route_name='department.read',
|
|
|
|
renderer='/departments/crud.mako', permission='departments.read')
|
|
|
|
config.add_view(DepartmentCrud, attr='update', route_name='department.update',
|
|
|
|
renderer='/departments/crud.mako', permission='departments.update')
|
|
|
|
config.add_view(DepartmentCrud, attr='delete', route_name='department.delete',
|
2012-11-18 10:38:11 -06:00
|
|
|
permission='departments.delete')
|
2015-02-09 15:33:16 -06:00
|
|
|
|
|
|
|
version_defaults(config, DepartmentVersionView, 'department')
|