Refactor several more straggler views to use master3

This commit is contained in:
Lance Edgar 2018-01-08 20:41:31 -06:00
parent 3097f46aa1
commit ce0195bd51
10 changed files with 187 additions and 148 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -33,10 +33,7 @@ from sqlalchemy import orm
from rattail.db import model
from rattail.time import localtime
import formalchemy as fa
from tailbone import forms
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
from tailbone.util import raw_datetime
@ -78,6 +75,21 @@ class CustomerOrderItemsView(MasterView):
'note',
]
form_fields = [
'person',
'product',
'product_brand',
'product_description',
'product_size',
'case_quantity',
'cases_ordered',
'units_ordered',
'unit_price',
'total_price',
'paid_amount',
'status_code',
]
def query(self, session):
return session.query(model.CustomerOrderItem)\
.join(model.CustomerOrder)\
@ -118,36 +130,49 @@ class CustomerOrderItemsView(MasterView):
value = localtime(self.rattail_config, item.order.created, from_utc=True)
return raw_datetime(self.rattail_config, value)
def _preconfigure_fieldset(self, fs):
fs.order.set(renderer=forms.renderers.CustomerOrderFieldRenderer)
fs.product.set(renderer=forms.renderers.ProductFieldRenderer)
fs.product_unit_of_measure.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.UNIT_OF_MEASURE))
fs.case_quantity.set(renderer=forms.renderers.QuantityFieldRenderer)
fs.cases_ordered.set(renderer=forms.renderers.QuantityFieldRenderer)
fs.units_ordered.set(renderer=forms.renderers.QuantityFieldRenderer)
fs.unit_price.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.total_price.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.paid_amount.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.status_code.set(label="Status")
fs.append(fa.Field('person', value=lambda i: i.order.person,
renderer=forms.renderers.PersonFieldRenderer))
def configure_form(self, f):
super(CustomerOrderItemsView, self).configure_form(f)
def configure_fieldset(self, fs):
fs.configure(
include=[
fs.person,
fs.product,
fs.product_brand,
fs.product_description,
fs.product_size,
fs.case_quantity,
fs.cases_ordered,
fs.units_ordered,
fs.unit_price,
fs.total_price,
fs.paid_amount,
fs.status_code,
])
# order
f.set_renderer('order', self.render_order)
# product
f.set_renderer('product', self.render_product)
# product uom
f.set_enum('product_unit_of_measure', self.enum.UNIT_OF_MEASURE)
# quantity fields
f.set_type('case_quantity', 'quantity')
f.set_type('cases_ordered', 'quantity')
f.set_type('units_ordered', 'quantity')
# currency fields
f.set_type('unit_price', 'currency')
f.set_type('total_price', 'currency')
f.set_type('paid_amount', 'currency')
# person
f.set_renderer('person', self.render_person)
# label overrides
f.set_label('status_code', "Status")
def render_order(self, item, field):
order = item.order
if not order:
return ""
text = six.text_type(order)
url = self.request.route_url('custorders.view', uuid=order.uuid)
return tags.link_to(text, url)
def render_product(self, order, field):
product = order.product
if not product:
return ""
text = six.text_type(product)
url = self.request.route_url('products.view', uuid=product.uuid)
return tags.link_to(text, url)
def get_row_data(self, item):
return self.Session.query(model.CustomerOrderItemEvent)\

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -26,13 +26,15 @@ Customer Order Views
from __future__ import unicode_literals, absolute_import
import six
from sqlalchemy import orm
from rattail.db import model
from tailbone import forms
from webhelpers2.html import tags
from tailbone.db import Session
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView as MasterView
class CustomerOrdersView(MasterView):
@ -53,6 +55,14 @@ class CustomerOrdersView(MasterView):
'status_code',
]
form_fields = [
'id',
'customer',
'person',
'created',
'status_code',
]
def query(self, session):
return session.query(model.CustomerOrder)\
.options(orm.joinedload(model.CustomerOrder.customer))
@ -81,22 +91,29 @@ class CustomerOrdersView(MasterView):
g.set_label('status_code', "Status")
g.set_label('id', "ID")
def _preconfigure_fieldset(self, fs):
fs.customer.set(options=[])
fs.id.set(label="ID", readonly=True)
fs.person.set(renderer=forms.renderers.PersonFieldRenderer)
fs.created.set(readonly=True)
fs.status_code.set(label="Status")
def configure_form(self, f):
super(CustomerOrdersView, self).configure_form(f)
def configure_fieldset(self, fs):
fs.configure(
include=[
fs.id,
fs.customer,
fs.person,
fs.created,
fs.status_code,
])
# id
f.set_readonly('id')
f.set_label('id', "ID")
# person
f.set_renderer('person', self.render_person)
# created
f.set_readonly('created')
# label overrides
f.set_label('status_code', "Status")
def render_person(self, order, field):
person = order.person
if not person:
return ""
text = six.text_type(person)
url = self.request.route_url('people.view', uuid=person.uuid)
return tags.link_to(text, url)
def includeme(config):

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -29,7 +29,7 @@ from __future__ import unicode_literals, absolute_import
from rattail.db import model
from tailbone import forms
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
class DepositLinksView(MasterView):
@ -46,6 +46,12 @@ class DepositLinksView(MasterView):
'amount',
]
form_fields = [
'code',
'description',
'amount',
]
def configure_grid(self, g):
super(DepositLinksView, self).configure_grid(g)
g.filters['description'].default_active = True
@ -55,14 +61,6 @@ class DepositLinksView(MasterView):
g.set_link('code')
g.set_link('description')
def configure_fieldset(self, fs):
fs.configure(
include=[
fs.code,
fs.description,
fs.amount,
])
def includeme(config):
DepositLinksView.defaults(config)

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -28,7 +28,7 @@ from __future__ import unicode_literals, absolute_import
from rattail.db import model
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
class FamiliesView(MasterView):
@ -46,19 +46,17 @@ class FamiliesView(MasterView):
'name',
]
form_fields = [
'code',
'name',
]
def configure_grid(self, g):
super(FamiliesView, self).configure_grid(g)
g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains'
g.set_sort_defaults('code')
def configure_fieldset(self, fs):
fs.configure(
include=[
fs.code,
fs.name,
])
return fs
def includeme(config):
FamiliesView.defaults(config)

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -30,9 +30,8 @@ from rattail.db import model
from pyramid.httpexceptions import HTTPFound
from tailbone import forms
from tailbone.db import Session
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
class ProfilesView(MasterView):
@ -51,6 +50,16 @@ class ProfilesView(MasterView):
'visible',
]
form_fields = [
'ordinal',
'code',
'description',
'printer_spec',
'formatter_spec',
'format',
'visible',
]
def configure_grid(self, g):
super(ProfilesView, self).configure_grid(g)
g.set_sort_defaults('ordinal')
@ -58,20 +67,11 @@ class ProfilesView(MasterView):
g.set_link('code')
g.set_link('description')
def configure_fieldset(self, fs):
fs.printer_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer)
fs.formatter_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer)
fs.format.set(renderer=forms.renderers.CodeTextAreaFieldRenderer)
fs.configure(
include=[
fs.ordinal,
fs.code,
fs.description,
fs.printer_spec,
fs.formatter_spec,
fs.format,
fs.visible,
])
def configure_form(self, f):
super(ProfilesView, self).configure_form(f)
# format
f.set_type('format', 'codeblock')
def after_create(self, profile):
self.after_edit(profile)

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -30,8 +30,8 @@ from rattail.db import model
from webhelpers2.html import tags
from tailbone import forms, grids
from tailbone.views import MasterView2 as MasterView
from tailbone import grids
from tailbone.views import MasterView3 as MasterView
class PurchaseCreditView(MasterView):

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -28,7 +28,7 @@ from __future__ import unicode_literals, absolute_import
from rattail.db import model
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
class ReportCodesView(MasterView):
@ -44,6 +44,11 @@ class ReportCodesView(MasterView):
'name',
]
form_fields = [
'code',
'name',
]
def configure_grid(self, g):
super(ReportCodesView, self).configure_grid(g)
g.filters['name'].default_active = True
@ -52,14 +57,6 @@ class ReportCodesView(MasterView):
g.set_link('code')
g.set_link('name')
def configure_fieldset(self, fs):
fs.configure(
include=[
fs.code,
fs.name,
])
return fs
def includeme(config):
ReportCodesView.defaults(config)

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -26,7 +26,7 @@ Views with info about the underlying Rattail tables
from __future__ import unicode_literals, absolute_import
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
class TablesView(MasterView):

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -28,7 +28,7 @@ from __future__ import unicode_literals, absolute_import
from rattail.db import model
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
class TaxesView(MasterView):
@ -46,6 +46,12 @@ class TaxesView(MasterView):
'rate',
]
form_fields = [
'code',
'description',
'rate',
]
def configure_grid(self, g):
super(TaxesView, self).configure_grid(g)
g.filters['description'].default_active = True
@ -54,14 +60,6 @@ class TaxesView(MasterView):
g.set_link('code')
g.set_link('description')
def configure_fieldset(self, fs):
fs.configure(
include=[
fs.code,
fs.description,
fs.rate,
])
def includeme(config):
TaxesView.defaults(config)

View file

@ -32,7 +32,7 @@ from rattail.time import localtime
from tailbone import forms
from tailbone.db import TrainwreckSession
from tailbone.views import MasterView2 as MasterView
from tailbone.views import MasterView3 as MasterView
class TransactionView(MasterView):
@ -77,6 +77,27 @@ class TransactionView(MasterView):
'void',
]
form_fields = [
'system',
'system_id',
'terminal_id',
'receipt_number',
'start_time',
'end_time',
'upload_time',
'cashier_id',
'cashier_name',
'customer_id',
'customer_name',
'shopper_id',
'shopper_name',
'subtotal',
'discounted_subtotal',
'tax',
'total',
'void',
]
def configure_grid(self, g):
super(TransactionView, self).configure_grid(g)
g.filters['receipt_number'].default_active = True
@ -98,39 +119,24 @@ class TransactionView(MasterView):
g.set_link('customer_name')
g.set_link('total')
def _preconfigure_fieldset(self, fs):
fs.system.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TRAINWRECK_SYSTEM))
fs.system_id.set(label="System ID")
fs.terminal_id.set(label="Terminal")
fs.cashier_id.set(label="Cashier ID")
fs.customer_id.set(label="Customer ID")
fs.shopper_id.set(label="Shopper ID")
fs.subtotal.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.discounted_subtotal.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.tax.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.total.set(renderer=forms.renderers.CurrencyFieldRenderer)
def configure_form(self, f):
super(TransactionView, self).configure_form(f)
def configure_fieldset(self, fs):
fs.configure(include=[
fs.system,
fs.system_id,
fs.terminal_id,
fs.receipt_number,
fs.start_time,
fs.end_time,
fs.upload_time,
fs.cashier_id,
fs.cashier_name,
fs.customer_id,
fs.customer_name,
fs.shopper_id,
fs.shopper_name,
fs.subtotal,
fs.discounted_subtotal,
fs.tax,
fs.total,
fs.void,
])
# system
f.set_enum('system', self.enum.TRAINWRECK_SYSTEM)
# currency fields
f.set_type('subtotal', 'currency')
f.set_type('discounted_subtotal', 'currency')
f.set_type('tax', 'currency')
f.set_type('total', 'currency')
# label overrides
f.set_label('system_id', "System ID")
f.set_label('terminal_id', "Terminal")
f.set_label('cashier_id', "Cashier ID")
f.set_label('customer_id', "Customer ID")
f.set_label('shopper_id', "Shopper ID")
def get_row_data(self, transaction):
return self.Session.query(self.model_row_class)\