tailbone/tailbone/views/batch/pos.py

201 lines
5.2 KiB
Python
Raw Normal View History

2023-09-23 11:14:43 -05:00
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 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 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Views for POS batches
"""
from rattail.db.model import POSBatch, POSBatchRow
from tailbone.views.batch import BatchMasterView
class POSBatchView(BatchMasterView):
"""
Master view for POS batches
"""
model_class = POSBatch
model_row_class = POSBatchRow
default_handler_spec = 'rattail.batch.pos:POSBatchHandler'
route_prefix = 'batch.pos'
url_prefix = '/batch/pos'
creatable = False
cloneable = True
labels = {
'terminal_id': "Terminal ID",
}
2023-09-23 11:14:43 -05:00
grid_columns = [
'id',
'terminal_id',
2023-09-23 20:01:29 -05:00
'customer',
2023-09-23 11:14:43 -05:00
'created',
'created_by',
'rowcount',
'sales_total',
'void',
'status_code',
'executed',
'executed_by',
]
form_fields = [
'id',
'terminal_id',
2023-09-23 20:01:29 -05:00
'customer',
2023-09-23 11:14:43 -05:00
'params',
'rowcount',
'sales_total',
'tax1_total',
'tax2_total',
'tender_total',
'balance',
'void',
'training_mode',
2023-09-23 11:14:43 -05:00
'status_code',
'created',
'created_by',
'executed',
'executed_by',
]
row_grid_columns = [
'sequence',
'row_type',
'item_entry',
2023-09-23 11:14:43 -05:00
'description',
'reg_price',
'txn_price',
'quantity',
'sales_total',
'tender_total',
2023-09-23 11:14:43 -05:00
'status_code',
]
row_form_fields = [
'sequence',
'row_type',
'item_entry',
'product',
'description',
'reg_price',
'txn_price',
'quantity',
'sales_total',
'tax1_total',
'tax2_total',
'tender_total',
2023-09-30 21:08:01 -05:00
'void',
2023-09-23 11:14:43 -05:00
'status_code',
'timestamp',
'user',
2023-09-23 11:14:43 -05:00
]
def configure_grid(self, g):
super().configure_grid(g)
# terminal_id
g.set_label('terminal_id', "Terminal")
if 'terminal_id' in g.filters:
g.filters['terminal_id'].label = self.labels.get('terminal_id', "Terminal ID")
2023-09-23 20:01:29 -05:00
g.set_link('customer')
2023-09-23 11:14:43 -05:00
g.set_link('created')
g.set_link('created_by')
2023-09-23 20:01:29 -05:00
g.set_type('sales_total', 'currency')
g.set_type('tax1_total', 'currency')
g.set_type('tax2_total', 'currency')
g.set_type('tender_total', 'currency')
# executed
# nb. default view should show "all recent" batches regardless
# of execution (i think..)
if 'executed' in g.filters:
g.filters['executed'].default_active = False
2023-09-23 20:01:29 -05:00
2023-09-23 11:14:43 -05:00
def grid_extra_class(self, batch, i):
if batch.void:
return 'warning'
if batch.training_mode:
return 'notice'
2023-09-23 11:14:43 -05:00
def configure_form(self, f):
super().configure_form(f)
app = self.get_rattail_app()
2023-09-23 11:14:43 -05:00
2023-09-23 20:01:29 -05:00
f.set_renderer('customer', self.render_customer)
2023-09-23 11:14:43 -05:00
f.set_type('sales_total', 'currency')
f.set_type('tax1_total', 'currency')
f.set_type('tax2_total', 'currency')
f.set_type('tender_total', 'currency')
f.set_type('tender_total', 'currency')
f.set_renderer('balance', lambda batch, field: app.render_currency(batch.get_balance()))
2023-09-23 11:14:43 -05:00
def configure_row_grid(self, g):
super().configure_row_grid(g)
2023-10-01 17:31:33 -05:00
g.set_enum('row_type', self.enum.POS_ROW_TYPE)
2023-09-23 11:14:43 -05:00
g.set_type('quantity', 'quantity')
g.set_type('reg_price', 'currency')
g.set_type('txn_price', 'currency')
g.set_type('sales_total', 'currency')
g.set_type('tender_total', 'currency')
2023-09-23 11:14:43 -05:00
g.set_link('product')
g.set_link('description')
2023-09-30 21:08:01 -05:00
def row_grid_extra_class(self, row, i):
if row.void:
return 'warning'
2023-09-23 11:14:43 -05:00
def configure_row_form(self, f):
super().configure_row_form(f)
2023-10-05 19:59:57 -05:00
f.set_enum('row_type', self.enum.POS_ROW_TYPE)
2023-10-01 17:31:33 -05:00
f.set_renderer('product', self.render_product)
2023-09-23 11:14:43 -05:00
f.set_type('quantity', 'quantity')
f.set_type('reg_price', 'currency')
f.set_type('txn_price', 'currency')
f.set_type('sales_total', 'currency')
f.set_type('tender_total', 'currency')
f.set_renderer('user', self.render_user)
2023-09-23 11:14:43 -05:00
def defaults(config, **kwargs):
base = globals()
POSBatchView = kwargs.get('POSBatchView', base['POSBatchView'])
POSBatchView.defaults(config)
def includeme(config):
defaults(config)