Add start date support for "future" pricing batch

This commit is contained in:
Lance Edgar 2022-06-14 13:51:00 -05:00
parent cb6499522e
commit 6b466bb90f
3 changed files with 68 additions and 4 deletions

View file

@ -0,0 +1,22 @@
## -*- coding: utf-8; -*-
<%inherit file="/configure.mako" />
<%def name="form_content()">
<h3 class="block is-size-3">Options</h3>
<div class="block" style="padding-left: 2rem;">
<b-field>
<b-checkbox name="rattail.batch.pricing.allow_future"
v-model="simpleSettings['rattail.batch.pricing.allow_future']"
native-value="true"
@input="settingsNeedSaved = true">
Allow "future" pricing
</b-checkbox>
</b-field>
</div>
</%def>
${parent.body()}

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2022 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -52,6 +52,7 @@ class PricingBatchView(BatchMasterView):
bulk_deletable = True bulk_deletable = True
rows_editable = True rows_editable = True
rows_bulk_deletable = True rows_bulk_deletable = True
configurable = True
labels = { labels = {
'min_diff_threshold': "Min $ Diff", 'min_diff_threshold': "Min $ Diff",
@ -62,6 +63,7 @@ class PricingBatchView(BatchMasterView):
grid_columns = [ grid_columns = [
'id', 'id',
'description', 'description',
'start_date',
'created', 'created',
'created_by', 'created_by',
'rowcount', 'rowcount',
@ -75,6 +77,7 @@ class PricingBatchView(BatchMasterView):
'id', 'id',
'input_filename', 'input_filename',
'description', 'description',
'start_date',
'min_diff_threshold', 'min_diff_threshold',
'min_diff_percent', 'min_diff_percent',
'calculate_for_manual', 'calculate_for_manual',
@ -147,8 +150,24 @@ class PricingBatchView(BatchMasterView):
'status_text', 'status_text',
] ]
def allow_future_pricing(self):
return self.batch_handler.allow_future()
def configure_form(self, f): def configure_form(self, f):
super(PricingBatchView, self).configure_form(f) super(PricingBatchView, self).configure_form(f)
app = self.get_rattail_app()
batch = f.model_instance
if self.creating or self.editing:
if self.allow_future_pricing():
f.set_type('start_date', 'date_jquery')
f.set_helptext('start_date', "Only set this for a \"FUTURE\" batch.")
else:
f.remove('start_date')
else: # viewing or deleting
if not self.allow_future_pricing():
if not batch.start_date:
f.remove('start_date')
f.set_type('min_diff_threshold', 'currency') f.set_type('min_diff_threshold', 'currency')
@ -349,6 +368,15 @@ class PricingBatchView(BatchMasterView):
return xlrow return xlrow
def configure_get_simple_settings(self):
return [
# options
{'section': 'rattail.batch',
'option': 'pricing.allow_future',
'type': bool},
]
def includeme(config): def includeme(config):
PricingBatchView.defaults(config) PricingBatchView.defaults(config)

View file

@ -1892,14 +1892,15 @@ class ProductView(MasterView):
return {'product': data} return {'product': data}
def get_supported_batches(self): def get_supported_batches(self):
app = self.get_rattail_app()
pricing = app.get_batch_handler('pricing')
return OrderedDict([ return OrderedDict([
('labels', { ('labels', {
'spec': self.rattail_config.get('rattail.batch', 'labels.handler', 'spec': self.rattail_config.get('rattail.batch', 'labels.handler',
default='rattail.batch.labels:LabelBatchHandler'), default='rattail.batch.labels:LabelBatchHandler'),
}), }),
('pricing', { ('pricing', {
'spec': self.rattail_config.get('rattail.batch', 'pricing.handler', 'spec': pricing.get_spec(),
default='rattail.batch.pricing:PricingBatchHandler'),
}), }),
('delproduct', { ('delproduct', {
'spec': self.rattail_config.get('rattail.batch', 'delproduct.handler', 'spec': self.rattail_config.get('rattail.batch', 'delproduct.handler',
@ -2003,7 +2004,9 @@ class ProductView(MasterView):
""" """
Return params schema for making a pricing batch. Return params schema for making a pricing batch.
""" """
return colander.SchemaNode( app = self.get_rattail_app()
schema = colander.SchemaNode(
colander.Mapping(), colander.Mapping(),
colander.SchemaNode(colander.Decimal(), name='min_diff_threshold', colander.SchemaNode(colander.Decimal(), name='min_diff_threshold',
quant='1.00', missing=colander.null, quant='1.00', missing=colander.null,
@ -2014,6 +2017,17 @@ class ProductView(MasterView):
colander.SchemaNode(colander.Boolean(), name='calculate_for_manual'), colander.SchemaNode(colander.Boolean(), name='calculate_for_manual'),
) )
pricing = app.get_batch_handler('pricing')
if pricing.allow_future():
schema.insert(0, colander.SchemaNode(
colander.Date(),
name='start_date',
missing=colander.null,
title="Start Date (FUTURE only)",
widget=forms.widgets.JQueryDateWidget()))
return schema
def make_batch_params_schema_delproduct(self): def make_batch_params_schema_delproduct(self):
""" """
Return params schema for making a "delete products" batch. Return params schema for making a "delete products" batch.