# -*- coding: utf-8; -*- """ Product views """ from rattail_corepos.config import core_office_url from tailbone.views import products as base class ProductsView(base.ProductsView): """ Product overrides for online demo """ def configure_form(self, f): super(ProductsView, self).configure_form(f) if self.editing: f.fields = [ 'upc', 'brand_uuid', 'description', 'unit_size', 'unit_of_measure', 'size', 'pack_size', 'default_pack', 'case_size', 'weighed', 'department_uuid', 'subdepartment_uuid', 'category_uuid', 'family_uuid', 'report_code_uuid', 'regular_price_amount', 'deposit_link_uuid', 'tax_uuid', 'tax1', 'tax2', 'tax3', 'organic', 'kosher', 'vegan', 'vegetarian', 'gluten_free', 'sugar_free', 'discountable', 'special_order', 'not_for_sale', 'ingredients', 'notes', 'status', 'discontinued', 'deleted', ] def template_kwargs_view(self, **kwargs): """ Supplements the default logic as follows: Adds the URL for viewing the product within CORE Office, or else the reason for lack of such a URL. """ kwargs = super(ProductsView, self).template_kwargs_view(**kwargs) product = kwargs['instance'] # CORE Office URL kwargs['core_office_url'] = None office_url = core_office_url(self.rattail_config) if not office_url: kwargs['core_office_why_no_url'] = "CORE Office URL is not configured!" else: kwargs['core_office_url'] = '{}/item/ItemEditorPage.php?searchupc={}'.format(office_url, product.item_id) return kwargs def includeme(config): config.add_route('products.autocomplete', '/products/autocomplete') config.add_view(base.ProductsAutocomplete, route_name='products.autocomplete', renderer='json', permission='products.list') config.add_route('products.print_labels', '/products/labels') config.add_view(base.print_labels, route_name='products.print_labels', renderer='json', permission='products.print_labels') ProductsView.defaults(config)