Add support for pricing batches
This commit is contained in:
parent
fdd0b6ec3b
commit
668191b2e9
|
@ -57,7 +57,6 @@ def includeme(config):
|
||||||
config.include('tailbone.views.common')
|
config.include('tailbone.views.common')
|
||||||
|
|
||||||
config.include('tailbone.views.auth')
|
config.include('tailbone.views.auth')
|
||||||
config.include('tailbone.views.batches')
|
|
||||||
config.include('tailbone.views.bouncer')
|
config.include('tailbone.views.bouncer')
|
||||||
config.include('tailbone.views.brands')
|
config.include('tailbone.views.brands')
|
||||||
config.include('tailbone.views.categories')
|
config.include('tailbone.views.categories')
|
||||||
|
@ -87,3 +86,6 @@ def includeme(config):
|
||||||
config.include('tailbone.views.taxes')
|
config.include('tailbone.views.taxes')
|
||||||
config.include('tailbone.views.users')
|
config.include('tailbone.views.users')
|
||||||
config.include('tailbone.views.vendors')
|
config.include('tailbone.views.vendors')
|
||||||
|
|
||||||
|
config.include('tailbone.views.batches')
|
||||||
|
config.include('tailbone.views.batch.pricing')
|
||||||
|
|
33
tailbone/views/batch/__init__.py
Normal file
33
tailbone/views/batch/__init__.py
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
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)
|
102
tailbone/views/batch/pricing.py
Normal file
102
tailbone/views/batch/pricing.py
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
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)
|
|
@ -336,6 +336,12 @@ class ProductsView(MasterView):
|
||||||
'instance_title': self.get_instance_title(instance),
|
'instance_title': self.get_instance_title(instance),
|
||||||
'form': form})
|
'form': form})
|
||||||
|
|
||||||
|
def get_supported_batches(self):
|
||||||
|
return {
|
||||||
|
'labels': 'rattail.batch.labels:LabelBatchHandler',
|
||||||
|
'pricing': 'rattail.batch.pricing:PricingBatchHandler',
|
||||||
|
}
|
||||||
|
|
||||||
def make_batch(self):
|
def make_batch(self):
|
||||||
"""
|
"""
|
||||||
View for making a new batch from current product grid query.
|
View for making a new batch from current product grid query.
|
||||||
|
@ -348,10 +354,7 @@ class ProductsView(MasterView):
|
||||||
return self.make_batch_legacy(providers)
|
return self.make_batch_legacy(providers)
|
||||||
|
|
||||||
# okay then, new-style it is
|
# okay then, new-style it is
|
||||||
# TODO: make this more configurable surely..?
|
supported = self.get_supported_batches()
|
||||||
supported = {
|
|
||||||
'labels': 'rattail.batch.labels:LabelBatchHandler',
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
batch_key = self.request.POST.get('batch_type')
|
batch_key = self.request.POST.get('batch_type')
|
||||||
|
@ -394,10 +397,16 @@ class ProductsView(MasterView):
|
||||||
|
|
||||||
progress.session.load()
|
progress.session.load()
|
||||||
progress.session['complete'] = True
|
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['success_msg'] = 'Batch has been created: {}'.format(batch)
|
||||||
progress.session.save()
|
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):
|
def make_batch_legacy(self, providers):
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
provider_key = self.request.POST.get('provider')
|
provider_key = self.request.POST.get('provider')
|
||||||
|
|
Loading…
Reference in a new issue