Fix some things about editing House Coupons

which isn't to say that's fully supported yet, anyway...
This commit is contained in:
Lance Edgar 2019-07-09 23:42:09 -05:00
parent 2e238ed723
commit feec4d9703
3 changed files with 35 additions and 3 deletions

View file

@ -61,6 +61,7 @@ requires = [
'rattail', # 0.9.88
'rattail-corepos', # 0.1.0
'six', # 1.12.0
'Tailbone', # 0.8.50
]

View file

@ -24,9 +24,13 @@
CORE POS coupon views
"""
import six
from corepos.db import model as corepos
from corepos import enum as corepos_enum
from rattail.time import localtime
from .master import CoreOfficeMasterView
@ -76,23 +80,50 @@ class HouseCouponView(CoreOfficeMasterView):
g.set_enum('discount_type', corepos_enum.HOUSE_COUPON_DISCOUNT_TYPE)
g.set_renderer('start_date', self.render_local_date)
g.set_renderer('end_date', self.render_local_date)
g.set_joiner('department', lambda q: q.outerjoin(corepos.Department))
g.set_filter('department', corepos.Department.dept_name, label="Department Name")
g.set_sorter('department', corepos.Department.dept_name)
g.set_sort_defaults('coupon_id', 'desc')
g.set_link('coupon_id')
g.set_link('description')
def render_local_date(self, coupon, field):
value = getattr(coupon, field)
if not value:
return ""
value = localtime(self.rattail_config, value)
return six.text_type(value.date())
def configure_form(self, f):
super(HouseCouponView, self).configure_form(f)
if self.creating:
f.remove('coupon_id')
else:
f.set_readonly('coupon_id')
f.set_enum('member_only', corepos_enum.HOUSE_COUPON_MEMBER_ONLY)
f.set_renderer('department', self.render_corepos_department)
f.set_enum('discount_type', corepos_enum.HOUSE_COUPON_DISCOUNT_TYPE)
if self.creating or self.editing:
f.set_readonly('department') # TODO: show dropdown for this
f.set_enum('min_type', corepos_enum.HOUSE_COUPON_MINIMUM_TYPE)
f.set_readonly('department') # TODO: show dropdown for this
f.set_renderer('start_date', self.render_local_date)
f.set_readonly('start_date') # TODO
f.set_type('start_date', 'date_jquery')
f.set_renderer('end_date', self.render_local_date)
f.set_readonly('end_date') # TODO
f.set_type('end_date', 'date_jquery')
def includeme(config):

View file

@ -83,7 +83,7 @@ class CoreOfficeMasterView(MasterView):
"""
dbkey = self.get_current_engine_dbkey()
if dbkey != 'default' and default in ExtraCoreOfficeSessions:
if dbkey != 'default' and dbkey in ExtraCoreOfficeSessions:
return ExtraCoreOfficeSessions[dbkey]
return CoreOfficeSession