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 # Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar # Copyright © 2010-2018 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -33,10 +33,7 @@ from sqlalchemy import orm
from rattail.db import model from rattail.db import model
from rattail.time import localtime from rattail.time import localtime
import formalchemy as fa from tailbone.views import MasterView3 as MasterView
from tailbone import forms
from tailbone.views import MasterView2 as MasterView
from tailbone.util import raw_datetime from tailbone.util import raw_datetime
@ -78,6 +75,21 @@ class CustomerOrderItemsView(MasterView):
'note', '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): def query(self, session):
return session.query(model.CustomerOrderItem)\ return session.query(model.CustomerOrderItem)\
.join(model.CustomerOrder)\ .join(model.CustomerOrder)\
@ -118,36 +130,49 @@ class CustomerOrderItemsView(MasterView):
value = localtime(self.rattail_config, item.order.created, from_utc=True) value = localtime(self.rattail_config, item.order.created, from_utc=True)
return raw_datetime(self.rattail_config, value) return raw_datetime(self.rattail_config, value)
def _preconfigure_fieldset(self, fs): def configure_form(self, f):
fs.order.set(renderer=forms.renderers.CustomerOrderFieldRenderer) super(CustomerOrderItemsView, self).configure_form(f)
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_fieldset(self, fs): # order
fs.configure( f.set_renderer('order', self.render_order)
include=[
fs.person, # product
fs.product, f.set_renderer('product', self.render_product)
fs.product_brand,
fs.product_description, # product uom
fs.product_size, f.set_enum('product_unit_of_measure', self.enum.UNIT_OF_MEASURE)
fs.case_quantity,
fs.cases_ordered, # quantity fields
fs.units_ordered, f.set_type('case_quantity', 'quantity')
fs.unit_price, f.set_type('cases_ordered', 'quantity')
fs.total_price, f.set_type('units_ordered', 'quantity')
fs.paid_amount,
fs.status_code, # 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): def get_row_data(self, item):
return self.Session.query(model.CustomerOrderItemEvent)\ return self.Session.query(model.CustomerOrderItemEvent)\

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar # Copyright © 2010-2018 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -26,13 +26,15 @@ Customer Order Views
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import six
from sqlalchemy import orm from sqlalchemy import orm
from rattail.db import model from rattail.db import model
from tailbone import forms from webhelpers2.html import tags
from tailbone.db import Session from tailbone.db import Session
from tailbone.views import MasterView2 as MasterView from tailbone.views import MasterView as MasterView
class CustomerOrdersView(MasterView): class CustomerOrdersView(MasterView):
@ -53,6 +55,14 @@ class CustomerOrdersView(MasterView):
'status_code', 'status_code',
] ]
form_fields = [
'id',
'customer',
'person',
'created',
'status_code',
]
def query(self, session): def query(self, session):
return session.query(model.CustomerOrder)\ return session.query(model.CustomerOrder)\
.options(orm.joinedload(model.CustomerOrder.customer)) .options(orm.joinedload(model.CustomerOrder.customer))
@ -81,22 +91,29 @@ class CustomerOrdersView(MasterView):
g.set_label('status_code', "Status") g.set_label('status_code', "Status")
g.set_label('id', "ID") g.set_label('id', "ID")
def _preconfigure_fieldset(self, fs): def configure_form(self, f):
fs.customer.set(options=[]) super(CustomerOrdersView, self).configure_form(f)
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_fieldset(self, fs): # id
fs.configure( f.set_readonly('id')
include=[ f.set_label('id', "ID")
fs.id,
fs.customer, # person
fs.person, f.set_renderer('person', self.render_person)
fs.created,
fs.status_code, # 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): def includeme(config):

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar # Copyright © 2010-2018 Lance Edgar
# #
# This file is part of Rattail. # 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 __future__ import unicode_literals, absolute_import
from tailbone.views import MasterView2 as MasterView from tailbone.views import MasterView3 as MasterView
class TablesView(MasterView): class TablesView(MasterView):

View file

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

View file

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