Add customnizations for Vendor views, per CORE integration

This commit is contained in:
Lance Edgar 2020-03-04 19:05:26 -06:00
parent 1dcb22a865
commit 86c9155f0d

View file

@ -0,0 +1,58 @@
# -*- coding: utf-8; -*-
"""
Vendor views
"""
from rattail_corepos.corepos.util import get_max_existing_vendor_id
from tailbone.views import vendors as base
class VendorView(base.VendorsView):
"""
Expose some extra fields etc. per CORE-POS integration.
Please note that this does include a bit of "business logic" which assumes
that you keep CORE and Rattail in sync! Use at your own risk.
"""
labels = {
'corepos_id': "CORE-POS ID",
}
def query(self, session):
query = super(VendorView, self).query(session)
model = self.rattail_config.get_model()
query = query.outerjoin(model.CoreVendor)
return query
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