Changeset 9e52a57 in tailbone-corepos


Ignore:
Timestamp:
07/06/20 21:17:41 (6 weeks ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
d08c18c
Parents:
d06895e
Message:

Add custom views for misc. tables w/ schema extensions

Location:
tailbone_corepos/views
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • tailbone_corepos/views/departments.py

    rd06895e r9e52a57  
    3434    Master view for the Department class.
    3535    """
     36    labels = {
     37        'corepos_number': "CORE-POS Number",
     38    }
     39
     40    @property
     41    def form_fields(self):
     42        fields = super(DepartmentView, self).form_fields
     43        return fields + [
     44            'corepos_number',
     45        ]
     46
     47    def query(self, session):
     48        query = super(DepartmentView, self).query(session)
     49        model = self.rattail_config.get_model()
     50        return query.outerjoin(model.CoreDepartment)
     51
     52    def configure_grid(self, g):
     53        super(DepartmentView, self).configure_grid(g)
     54        model = self.rattail_config.get_model()
     55        g.set_filter('corepos_number', model.CoreDepartment.corepos_number)
     56
     57    def get_version_child_classes(self):
     58        model = self.rattail_config.get_model()
     59        return super(DepartmentView, self).get_version_child_classes() + [
     60            model.CoreDepartment,
     61        ]
    3662
    3763    def template_kwargs_view(self, **kwargs):
     
    5985
    6086        return kwargs
     87
     88
     89def includeme(config):
     90    DepartmentView.defaults(config)
  • tailbone_corepos/views/people.py

    rd06895e r9e52a57  
    4141    }
    4242
     43    @property
     44    def form_fields(self):
     45        fields = super(PersonView, self).form_fields
     46        return fields + [
     47            'corepos_customer_id',
     48        ]
     49
    4350    def query(self, session):
    4451        query = super(PersonView, self).query(session)
    4552        model = self.rattail_config.get_model()
    46 
    47         query = query.outerjoin(model.CorePerson)
    48         return query
     53        return query.outerjoin(model.CorePerson)
    4954
    5055    def configure_grid(self, g):
    5156        super(PersonView, self).configure_grid(g)
    5257        model = self.rattail_config.get_model()
     58        g.set_filter('corepos_customer_id', model.CorePerson.corepos_customer_id)
    5359
    54         g.append('corepos_customer_id')
    55         g.set_sorter('corepos_customer_id', model.CorePerson.corepos_customer_id)
    56         g.set_filter('corepos_customer_id', model.CorePerson.corepos_customer_id)
    57         g.set_label('corepos_customer_id', "CORE ID")
    58         g.filters['corepos_customer_id'].label = "CORE-POS Customer ID"
    59 
    60     def configure_form(self, f):
    61         super(PersonView, self).configure_form(f)
    62 
    63         f.append('corepos_customer_id')
     60    def get_version_child_classes(self):
     61        model = self.rattail_config.get_model()
     62        return super(PersonView, self).get_version_child_classes() + [
     63            model.CorePerson,
     64        ]
    6465
    6566    def get_context_customers(self, person):
     
    8182
    8283        return data
     84
     85
     86def includeme(config):
     87
     88    # autocomplete
     89    config.add_route('people.autocomplete', '/people/autocomplete')
     90    config.add_view(base.PeopleAutocomplete, route_name='people.autocomplete',
     91                    renderer='json', permission='people.list')
     92    config.add_route('people.autocomplete.employees', '/people/autocomplete/employees')
     93    config.add_view(base.PeopleEmployeesAutocomplete, route_name='people.autocomplete.employees',
     94                    renderer='json', permission='people.list')
     95
     96    PersonView.defaults(config)
  • tailbone_corepos/views/products.py

    rd06895e r9e52a57  
    3434    Master view for the Product class.
    3535    """
     36    labels = {
     37        'corepos_id': "CORE-POS ID",
     38    }
     39
     40    @property
     41    def form_fields(self):
     42        fields = super(ProductView, self).form_fields
     43        return fields + [
     44            'corepos_id',
     45        ]
     46
     47    def query(self, session):
     48        query = super(ProductView, self).query(session)
     49        model = self.rattail_config.get_model()
     50        return query.outerjoin(model.CoreProduct)
     51
     52    def configure_grid(self, g):
     53        super(ProductView, self).configure_grid(g)
     54        model = self.rattail_config.get_model()
     55        g.set_filter('corepos_id', model.CoreProduct.corepos_id)
     56
     57    def get_version_child_classes(self):
     58        model = self.rattail_config.get_model()
     59        return super(ProductView, self).get_version_child_classes() + [
     60            model.CoreProduct,
     61        ]
    3662
    3763    def template_kwargs_view(self, **kwargs):
     
    5581
    5682        return kwargs
     83
     84
     85def includeme(config):
     86    ProductView.defaults(config)
  • tailbone_corepos/views/vendors.py

    rd06895e r9e52a57  
    33#
    44#  Rattail -- Retail Software Framework
    5 #  Copyright © 2010-2019 Lance Edgar
     5#  Copyright © 2010-2020 Lance Edgar
    66#
    77#  This file is part of Rattail.
     
    2626
    2727from rattail_corepos.config import core_office_url
    28 from rattail_corepos.corepos.util import get_max_existing_vendor_id
    2928
    3029from tailbone.views import vendors as base
     
    4241    }
    4342
     43    @property
     44    def form_fields(self):
     45        fields = super(VendorView, self).form_fields
     46        return fields + [
     47            'corepos_id',
     48        ]
     49
    4450    def query(self, session):
    4551        query = super(VendorView, self).query(session)
    4652        model = self.rattail_config.get_model()
    47 
    48         query = query.outerjoin(model.CoreVendor)
    49 
    50         return query
     53        return query.outerjoin(model.CoreVendor)
    5154
    5255    def configure_grid(self, g):
    5356        super(VendorView, self).configure_grid(g)
    5457        model = self.rattail_config.get_model()
    55 
    56         g.append('corepos_id')
    57         g.set_sorter('corepos_id', model.CoreVendor.corepos_id)
    5858        g.set_filter('corepos_id', model.CoreVendor.corepos_id)
    5959
    60     def configure_form(self, f):
    61         super(VendorView, self).configure_form(f)
    62 
    63         if not self.creating:
    64             f.append('corepos_id')
    65 
    66     def objectify(self, form, data=None):
    67         vendor = super(VendorView, self).objectify(form, data)
    68 
    69         if self.creating:
    70 
    71             # TODO: this seems too much like "business rules" to be here, right?
    72 
    73             # must assign "next" CORE ID if creating new vendor
    74             vendor.corepos_id = get_max_existing_vendor_id() + 1
    75 
    76             # also, set some default values so that the systems will match
    77             if vendor.special_discount is None:
    78                 vendor.special_discount = 0
    79 
    80         return vendor
     60    def get_version_child_classes(self):
     61        model = self.rattail_config.get_model()
     62        return super(VendorView, self).get_version_child_classes() + [
     63            model.CoreVendor,
     64        ]
    8165
    8266    def template_kwargs_view(self, **kwargs):
     
    10690
    10791        return kwargs
     92
     93
     94def includeme(config):
     95    VendorView.defaults(config)
Note: See TracChangeset for help on using the changeset viewer.