Add custom views for misc. tables w/ schema extensions

This commit is contained in:
Lance Edgar 2020-07-06 21:17:41 -05:00
parent d06895e697
commit 9e52a574eb
7 changed files with 297 additions and 42 deletions

View file

@ -0,0 +1,64 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Customer Views
"""
from tailbone.views import customers as base
class CustomerView(base.CustomersView):
"""
Master view for the Customer class.
"""
labels = {
'corepos_account_id': "CORE-POS Account ID",
}
@property
def form_fields(self):
fields = super(CustomerView, self).form_fields
return fields + [
'corepos_account_id',
]
def query(self, session):
query = super(CustomerView, self).query(session)
model = self.rattail_config.get_model()
return query.outerjoin(model.CoreCustomer)
def configure_grid(self, g):
super(CustomerView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.set_filter('corepos_account_id', model.CoreCustomer.corepos_account_id)
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(CustomerView, self).get_version_child_classes() + [
model.CoreCustomer,
]
def includeme(config):
CustomerView.defaults(config)

View file

@ -33,6 +33,32 @@ class DepartmentView(base.DepartmentsView):
"""
Master view for the Department class.
"""
labels = {
'corepos_number': "CORE-POS Number",
}
@property
def form_fields(self):
fields = super(DepartmentView, self).form_fields
return fields + [
'corepos_number',
]
def query(self, session):
query = super(DepartmentView, self).query(session)
model = self.rattail_config.get_model()
return query.outerjoin(model.CoreDepartment)
def configure_grid(self, g):
super(DepartmentView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.set_filter('corepos_number', model.CoreDepartment.corepos_number)
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(DepartmentView, self).get_version_child_classes() + [
model.CoreDepartment,
]
def template_kwargs_view(self, **kwargs):
"""
@ -58,3 +84,7 @@ class DepartmentView(base.DepartmentsView):
office_url, department.number)
return kwargs
def includeme(config):
DepartmentView.defaults(config)

View file

@ -0,0 +1,64 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Member Views
"""
from tailbone.views import members as base
class MemberView(base.MemberView):
"""
Master view for the Member class.
"""
labels = {
'corepos_account_id': "CORE-POS Account ID",
}
@property
def form_fields(self):
fields = super(MemberView, self).form_fields
return fields + [
'corepos_account_id',
]
def query(self, session):
query = super(MemberView, self).query(session)
model = self.rattail_config.get_model()
return query.outerjoin(model.CoreMember)
def configure_grid(self, g):
super(MemberView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.set_filter('corepos_account_id', model.CoreMember.corepos_account_id)
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(MemberView, self).get_version_child_classes() + [
model.CoreMember,
]
def includeme(config):
MemberView.defaults(config)

View file

@ -40,27 +40,28 @@ class PersonView(base.PeopleView):
'corepos_customer_id': "CORE-POS Customer ID",
}
@property
def form_fields(self):
fields = super(PersonView, self).form_fields
return fields + [
'corepos_customer_id',
]
def query(self, session):
query = super(PersonView, self).query(session)
model = self.rattail_config.get_model()
query = query.outerjoin(model.CorePerson)
return query
return query.outerjoin(model.CorePerson)
def configure_grid(self, g):
super(PersonView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.append('corepos_customer_id')
g.set_sorter('corepos_customer_id', model.CorePerson.corepos_customer_id)
g.set_filter('corepos_customer_id', model.CorePerson.corepos_customer_id)
g.set_label('corepos_customer_id', "CORE ID")
g.filters['corepos_customer_id'].label = "CORE-POS Customer ID"
def configure_form(self, f):
super(PersonView, self).configure_form(f)
f.append('corepos_customer_id')
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(PersonView, self).get_version_child_classes() + [
model.CorePerson,
]
def get_context_customers(self, person):
data = super(PersonView, self).get_context_customers(person)
@ -80,3 +81,16 @@ class PersonView(base.PeopleView):
self.rattail_config, member['number'])
return data
def includeme(config):
# autocomplete
config.add_route('people.autocomplete', '/people/autocomplete')
config.add_view(base.PeopleAutocomplete, route_name='people.autocomplete',
renderer='json', permission='people.list')
config.add_route('people.autocomplete.employees', '/people/autocomplete/employees')
config.add_view(base.PeopleEmployeesAutocomplete, route_name='people.autocomplete.employees',
renderer='json', permission='people.list')
PersonView.defaults(config)

View file

@ -33,6 +33,32 @@ class ProductView(base.ProductsView):
"""
Master view for the Product class.
"""
labels = {
'corepos_id': "CORE-POS ID",
}
@property
def form_fields(self):
fields = super(ProductView, self).form_fields
return fields + [
'corepos_id',
]
def query(self, session):
query = super(ProductView, self).query(session)
model = self.rattail_config.get_model()
return query.outerjoin(model.CoreProduct)
def configure_grid(self, g):
super(ProductView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.set_filter('corepos_id', model.CoreProduct.corepos_id)
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(ProductView, self).get_version_child_classes() + [
model.CoreProduct,
]
def template_kwargs_view(self, **kwargs):
"""
@ -54,3 +80,7 @@ class ProductView(base.ProductsView):
office_url, product.item_id)
return kwargs
def includeme(config):
ProductView.defaults(config)

View file

@ -0,0 +1,65 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Subdepartment Views
"""
from rattail_corepos.config import core_office_url
from tailbone.views import subdepartments as base
class SubdepartmentView(base.SubdepartmentsView):
"""
Master view for the Subdepartment class.
"""
labels = {
'corepos_number': "CORE-POS Number",
}
@property
def form_fields(self):
fields = super(SubdepartmentView, self).form_fields
return fields + [
'corepos_number',
]
def query(self, session):
query = super(SubdepartmentView, self).query(session)
model = self.rattail_config.get_model()
return query.outerjoin(model.CoreSubdepartment)
def configure_grid(self, g):
super(SubdepartmentView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.set_filter('corepos_number', model.CoreSubdepartment.corepos_number)
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(SubdepartmentView, self).get_version_child_classes() + [
model.CoreSubdepartment,
]
def includeme(config):
SubdepartmentView.defaults(config)

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -25,7 +25,6 @@ Vendor views
"""
from rattail_corepos.config import core_office_url
from rattail_corepos.corepos.util import get_max_existing_vendor_id
from tailbone.views import vendors as base
@ -41,43 +40,28 @@ class VendorView(base.VendorsView):
'corepos_id': "CORE-POS ID",
}
@property
def form_fields(self):
fields = super(VendorView, self).form_fields
return fields + [
'corepos_id',
]
def query(self, session):
query = super(VendorView, self).query(session)
model = self.rattail_config.get_model()
query = query.outerjoin(model.CoreVendor)
return query
return query.outerjoin(model.CoreVendor)
def configure_grid(self, g):
super(VendorView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.append('corepos_id')
g.set_sorter('corepos_id', model.CoreVendor.corepos_id)
g.set_filter('corepos_id', model.CoreVendor.corepos_id)
def configure_form(self, f):
super(VendorView, self).configure_form(f)
if not self.creating:
f.append('corepos_id')
def objectify(self, form, data=None):
vendor = super(VendorView, self).objectify(form, data)
if self.creating:
# TODO: this seems too much like "business rules" to be here, right?
# must assign "next" CORE ID if creating new vendor
vendor.corepos_id = get_max_existing_vendor_id() + 1
# also, set some default values so that the systems will match
if vendor.special_discount is None:
vendor.special_discount = 0
return vendor
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(VendorView, self).get_version_child_classes() + [
model.CoreVendor,
]
def template_kwargs_view(self, **kwargs):
"""
@ -105,3 +89,7 @@ class VendorView(base.VendorsView):
office_url, vendor.corepos_id)
return kwargs
def includeme(config):
VendorView.defaults(config)