From feec4d970319919e97bf635dc863214c6e01fe41 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 9 Jul 2019 23:42:09 -0500 Subject: [PATCH] Fix some things about editing House Coupons which isn't to say that's fully supported yet, anyway... --- setup.py | 1 + tailbone_corepos/views/corepos/coupons.py | 35 +++++++++++++++++++++-- tailbone_corepos/views/corepos/master.py | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 1567998..225681a 100644 --- a/setup.py +++ b/setup.py @@ -61,6 +61,7 @@ requires = [ 'rattail', # 0.9.88 'rattail-corepos', # 0.1.0 + 'six', # 1.12.0 'Tailbone', # 0.8.50 ] diff --git a/tailbone_corepos/views/corepos/coupons.py b/tailbone_corepos/views/corepos/coupons.py index 2a6ce67..e37cb9a 100644 --- a/tailbone_corepos/views/corepos/coupons.py +++ b/tailbone_corepos/views/corepos/coupons.py @@ -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): diff --git a/tailbone_corepos/views/corepos/master.py b/tailbone_corepos/views/corepos/master.py index 81dd4c8..283c925 100644 --- a/tailbone_corepos/views/corepos/master.py +++ b/tailbone_corepos/views/corepos/master.py @@ -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