From 97e0386eeff00f39fa5da86d46a89a4aa820f21c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 4 May 2021 20:11:46 -0500 Subject: [PATCH] Add views for "like codes" --- tailbone_corepos/menus.py | 5 + tailbone_corepos/views/corepos/__init__.py | 1 + tailbone_corepos/views/corepos/likecodes.py | 128 ++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 tailbone_corepos/views/corepos/likecodes.py diff --git a/tailbone_corepos/menus.py b/tailbone_corepos/menus.py index 7470169..331da69 100644 --- a/tailbone_corepos/menus.py +++ b/tailbone_corepos/menus.py @@ -74,6 +74,11 @@ def make_corepos_menu(request): 'url': url('corepos.product_flags'), 'perm': 'corepos.product_flags.list', }, + { + 'title': "Like Codes", + 'url': url('corepos.like_codes'), + 'perm': 'corepos.like_codes.list', + }, { 'title': "Scale Items", 'url': url('corepos.scale_items'), diff --git a/tailbone_corepos/views/corepos/__init__.py b/tailbone_corepos/views/corepos/__init__.py index 71ef957..d026405 100644 --- a/tailbone_corepos/views/corepos/__init__.py +++ b/tailbone_corepos/views/corepos/__init__.py @@ -37,6 +37,7 @@ def includeme(config): config.include('tailbone_corepos.views.corepos.vendoritems') config.include('tailbone_corepos.views.corepos.origins') config.include('tailbone_corepos.views.corepos.products') + config.include('tailbone_corepos.views.corepos.likecodes') config.include('tailbone_corepos.views.corepos.scaleitems') config.include('tailbone_corepos.views.corepos.members') config.include('tailbone_corepos.views.corepos.customers') diff --git a/tailbone_corepos/views/corepos/likecodes.py b/tailbone_corepos/views/corepos/likecodes.py new file mode 100644 index 0000000..2249179 --- /dev/null +++ b/tailbone_corepos/views/corepos/likecodes.py @@ -0,0 +1,128 @@ +# -*- coding: utf-8; -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2021 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 . +# +################################################################################ +""" +CORE-POS Like Code views +""" + +from corepos.db.office_op import model as corepos + +from .master import CoreOfficeMasterView + + +class LikeCodeView(CoreOfficeMasterView): + """ + Base class for like code views. + """ + model_class = corepos.LikeCode + model_title = "CORE-POS Like Code" + url_prefix = '/core-pos/like-codes' + route_prefix = 'corepos.like_codes' + results_downloadable = True + + has_rows = True + model_row_class = corepos.Product + + labels = { + 'id': "Like Code", + 'preferred_vendor_id': "Preferred Vendor ID", + } + + grid_columns = [ + 'id', + 'description', + 'strict', + 'organic', + 'preferred_vendor_id', + 'multi_vendor', + 'sort_retail', + 'sort_internal', + ] + + form_fields = [ + 'id', + 'description', + 'strict', + 'organic', + 'preferred_vendor_id', + 'multi_vendor', + 'sort_retail', + 'sort_internal', + ] + + row_labels = { + 'upc': "UPC", + } + + row_grid_columns = [ + 'upc', + 'brand', + 'description', + 'size', + 'department', + 'vendor', + 'normal_price', + 'scale', + 'cost', + ] + + def configure_grid(self, g): + super(LikeCodeView, self).configure_grid(g) + + g.remove_filter('likeCode') + g.set_filter('id', corepos.LikeCode.id, + default_active=True, + default_verb='equal') + + g.sorters.pop('likeCode') + g.set_sorter('id', corepos.LikeCode.id) + g.set_sort_defaults('id') + + g.set_link('id') + g.set_link('description') + + def get_row_data(self, likecode): + return self.Session.query(corepos.Product)\ + .join(corepos.ProductLikeCode)\ + .filter(corepos.ProductLikeCode.like_code == likecode) + + def get_parent(self, product): + return product._like_code.like_code + + def get_row_action_url(self, action, product, **kwargs): + route_name = 'corepos.products.{}'.format(action) + return self.request.route_url(route_name, id=product.id) + + def configure_row_grid(self, g): + super(LikeCodeView, self).configure_row_grid(g) + + g.set_type('normal_price', 'currency') + g.set_type('cost', 'currency') + + g.set_sort_defaults('upc') + + g.set_link('upc') + g.set_link('description') + + +def includeme(config): + LikeCodeView.defaults(config)