Coverage for src/sideshow/web/views/batch/neworder.py: 100%
48 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-06 15:04 -0600
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-06 15:04 -0600
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# Sideshow -- Case/Special Order Tracker
5# Copyright © 2024 Lance Edgar
6#
7# This file is part of Sideshow.
8#
9# Sideshow is free software: you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# Sideshow is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with Sideshow. If not, see <http://www.gnu.org/licenses/>.
21#
22################################################################################
23"""
24Views for New Order Batch
25"""
27from wuttaweb.views.batch import BatchMasterView
28from wuttaweb.forms.schema import WuttaMoney
30from sideshow.db.model import NewOrderBatch
31from sideshow.batch.neworder import NewOrderBatchHandler
32from sideshow.web.forms.schema import PendingCustomerRef
35class NewOrderBatchView(BatchMasterView):
36 """
37 Master view for :class:`~sideshow.db.model.batch.neworder.NewOrderBatch`.
39 Route prefix is ``neworder_batches``.
41 Notable URLs provided by this class:
43 * ``/batch/neworder/``
44 * ``/batch/neworder/XXX``
45 * ``/batch/neworder/XXX/delete``
47 The purpose of this class is to expose "raw" batch data, e.g. for
48 troubleshooting purposes by the admin. Ideally it is not very
49 useful.
51 Note that the "create" and "edit" views are not exposed here,
52 since those should be handled by
53 :class:`~sideshow.web.views.orders.OrderView` instead.
54 """
55 model_class = NewOrderBatch
56 model_title = "New Order Batch"
57 model_title_plural = "New Order Batches"
58 route_prefix = 'neworder_batches'
59 url_prefix = '/batch/neworder'
60 creatable = False
61 editable = False
63 labels = {
64 'store_id': "Store ID",
65 'customer_id': "Customer ID",
66 }
68 grid_columns = [
69 'id',
70 'store_id',
71 'customer_id',
72 'customer_name',
73 'phone_number',
74 'email_address',
75 'total_price',
76 'row_count',
77 'created',
78 'created_by',
79 'executed',
80 ]
82 filter_defaults = {
83 'executed': {'active': True, 'verb': 'is_null'},
84 }
86 form_fields = [
87 'id',
88 'store_id',
89 'customer_id',
90 'pending_customer',
91 'customer_name',
92 'phone_number',
93 'email_address',
94 'total_price',
95 'row_count',
96 'status_code',
97 'created',
98 'created_by',
99 'executed',
100 'executed_by',
101 ]
103 row_labels = {
104 'product_scancode': "Scancode",
105 'product_brand': "Brand",
106 'product_description': "Description",
107 'product_size': "Size",
108 'order_uom': "Order UOM",
109 }
111 row_grid_columns = [
112 'sequence',
113 'product_scancode',
114 'product_brand',
115 'product_description',
116 'product_size',
117 'special_order',
118 'order_qty',
119 'order_uom',
120 'case_size',
121 'total_price',
122 'status_code',
123 ]
125 def get_batch_handler(self):
126 """ """
127 # TODO: call self.app.get_batch_handler()
128 return NewOrderBatchHandler(self.config)
130 def configure_grid(self, g):
131 """ """
132 super().configure_grid(g)
134 # total_price
135 g.set_renderer('total_price', 'currency')
137 def configure_form(self, f):
138 """ """
139 super().configure_form(f)
141 # pending_customer
142 f.set_node('pending_customer', PendingCustomerRef(self.request))
144 # total_price
145 f.set_node('total_price', WuttaMoney(self.request))
147 def configure_row_grid(self, g):
148 """ """
149 super().configure_row_grid(g)
150 enum = self.app.enum
152 # TODO
153 # order_uom
154 #g.set_renderer('order_uom', self.grid_render_enum, enum=enum.ORDER_UOM)
156 # total_price
157 g.set_renderer('total_price', 'currency')
159 def get_xref_buttons(self, batch):
160 """
161 Adds "View this Order" button, if batch has been executed and
162 a corresponding :class:`~sideshow.db.model.orders.Order` can
163 be located.
164 """
165 buttons = super().get_xref_buttons(batch)
166 model = self.app.model
167 session = self.Session()
169 if batch.executed and self.request.has_perm('orders.view'):
170 order = session.query(model.Order)\
171 .filter(model.Order.order_id == batch.id)\
172 .first()
173 if order:
174 url = self.request.route_url('orders.view', uuid=order.uuid)
175 buttons.append(
176 self.make_button("View the Order", primary=True, icon_left='eye', url=url))
178 return buttons
181def defaults(config, **kwargs):
182 base = globals()
184 NewOrderBatchView = kwargs.get('NewOrderBatchView', base['NewOrderBatchView'])
185 NewOrderBatchView.defaults(config)
188def includeme(config):
189 defaults(config)