From 668191b2e9631c0c26ea1e74114004465a790be5 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 21 Nov 2016 19:36:57 -0600 Subject: [PATCH] Add support for pricing batches --- tailbone/views/__init__.py | 4 +- tailbone/views/batch/__init__.py | 33 +++++++ tailbone/views/{batch.py => batch/core.py} | 0 tailbone/views/batch/pricing.py | 102 +++++++++++++++++++++ tailbone/views/products.py | 19 +++- 5 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 tailbone/views/batch/__init__.py rename tailbone/views/{batch.py => batch/core.py} (100%) create mode 100644 tailbone/views/batch/pricing.py diff --git a/tailbone/views/__init__.py b/tailbone/views/__init__.py index a716abca..3e04f114 100644 --- a/tailbone/views/__init__.py +++ b/tailbone/views/__init__.py @@ -57,7 +57,6 @@ def includeme(config): config.include('tailbone.views.common') config.include('tailbone.views.auth') - config.include('tailbone.views.batches') config.include('tailbone.views.bouncer') config.include('tailbone.views.brands') config.include('tailbone.views.categories') @@ -87,3 +86,6 @@ def includeme(config): config.include('tailbone.views.taxes') config.include('tailbone.views.users') config.include('tailbone.views.vendors') + + config.include('tailbone.views.batches') + config.include('tailbone.views.batch.pricing') diff --git a/tailbone/views/batch/__init__.py b/tailbone/views/batch/__init__.py new file mode 100644 index 00000000..e9d5b708 --- /dev/null +++ b/tailbone/views/batch/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2016 Lance Edgar +# +# This file is part of Rattail. +# +# Rattail is free software: you can redistribute it and/or modify it under the +# terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +# more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Rattail. If not, see . +# +################################################################################ +""" +Views for batches +""" + +from __future__ import unicode_literals, absolute_import + +from .core import BatchMasterView, FileBatchMasterView + +# TODO: deprecate / remove this +from .core import (BaseGrid, BatchGrid, FileBatchGrid, BaseCrud, BatchCrud, FileBatchCrud, + StatusRenderer, BatchRowGrid, ProductBatchRowGrid, BatchRowCrud, defaults) diff --git a/tailbone/views/batch.py b/tailbone/views/batch/core.py similarity index 100% rename from tailbone/views/batch.py rename to tailbone/views/batch/core.py diff --git a/tailbone/views/batch/pricing.py b/tailbone/views/batch/pricing.py new file mode 100644 index 00000000..666aa07f --- /dev/null +++ b/tailbone/views/batch/pricing.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2016 Lance Edgar +# +# This file is part of Rattail. +# +# Rattail is free software: you can redistribute it and/or modify it under the +# terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +# more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Rattail. If not, see . +# +################################################################################ +""" +Views for pricing batches +""" + +from __future__ import unicode_literals, absolute_import + +from rattail.db import model + +from tailbone import forms +from tailbone.views.batch import BatchMasterView + + +class PricingBatchView(BatchMasterView): + """ + Master view for pricing batches. + """ + model_class = model.PricingBatch + model_row_class = model.PricingBatchRow + default_handler_spec = 'rattail.batch.pricing:PricingBatchHandler' + model_title_plural = "Pricing Batches" + route_prefix = 'batch.pricing' + url_prefix = '/batches/pricing' + creatable = False + editable = False + rows_editable = True + + def configure_fieldset(self, fs): + fs.configure( + include=[ + fs.id, + fs.created, + fs.created_by, + fs.executed, + fs.executed_by, + ]) + + def _preconfigure_row_grid(self, g): + super(PricingBatchView, self)._preconfigure_row_grid(g) + g.upc.set(label="UPC") + g.brand_name.set(label="Brand") + g.regular_unit_cost.set(label="Reg. Cost") + g.discounted_unit_cost.set(label="Disc. Cost") + g.old_price.set(renderer=forms.renderers.CurrencyFieldRenderer) + g.new_price.set(renderer=forms.renderers.CurrencyFieldRenderer) + g.price_margin.set(label="Margin") + g.price_markup.set(label="Markup") + g.price_diff.set(label="Diff", renderer=forms.renderers.CurrencyFieldRenderer) + + def configure_row_grid(self, g): + g.configure( + include=[ + g.sequence, + g.upc, + g.brand_name, + g.description, + g.size, + g.discounted_unit_cost, + g.old_price, + g.new_price, + g.price_margin, + g.status_code, + ], + readonly=True) + + def row_grid_row_attrs(self, row, i): + attrs = {} + if row.status_code in (row.STATUS_PRICE_INCREASE, + row.STATUS_PRICE_DECREASE): + attrs['class_'] = 'notice' + return attrs + + def _preconfigure_row_fieldset(self, fs): + super(PricingBatchView, self)._preconfigure_row_fieldset(fs) + fs.old_price.set(renderer=forms.renderers.CurrencyFieldRenderer) + fs.new_price.set(renderer=forms.renderers.CurrencyFieldRenderer) + fs.price_diff.set(renderer=forms.renderers.CurrencyFieldRenderer) + + +def includeme(config): + PricingBatchView.defaults(config) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index f9a1206a..eb5255d6 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -336,6 +336,12 @@ class ProductsView(MasterView): 'instance_title': self.get_instance_title(instance), 'form': form}) + def get_supported_batches(self): + return { + 'labels': 'rattail.batch.labels:LabelBatchHandler', + 'pricing': 'rattail.batch.pricing:PricingBatchHandler', + } + def make_batch(self): """ View for making a new batch from current product grid query. @@ -348,10 +354,7 @@ class ProductsView(MasterView): return self.make_batch_legacy(providers) # okay then, new-style it is - # TODO: make this more configurable surely..? - supported = { - 'labels': 'rattail.batch.labels:LabelBatchHandler', - } + supported = self.get_supported_batches() if self.request.method == 'POST': batch_key = self.request.POST.get('batch_type') @@ -394,10 +397,16 @@ class ProductsView(MasterView): progress.session.load() progress.session['complete'] = True - progress.session['success_url'] = self.request.route_url('labels.batch.view', uuid=batch.uuid) + progress.session['success_url'] = self.get_batch_view_url(batch) progress.session['success_msg'] = 'Batch has been created: {}'.format(batch) progress.session.save() + def get_batch_view_url(self, batch): + if batch.batch_key == 'labels': + return self.request.route_url('labels.batch.view', uuid=batch.uuid) + if batch.batch_key == 'pricing': + return self.request.route_url('batch.pricing.view', uuid=batch.uuid) + def make_batch_legacy(self, providers): if self.request.method == 'POST': provider_key = self.request.POST.get('provider')