Add some awareness of suspend/resume for POS batch

This commit is contained in:
Lance Edgar 2023-10-11 23:11:23 -05:00
parent d66dd5f199
commit 1a15d70568
2 changed files with 35 additions and 8 deletions

View file

@ -53,21 +53,21 @@ class POSBatchView(BatchMasterView):
grid_columns = [
'id',
'terminal_id',
'customer',
'created',
'created_by',
'terminal_id',
'cashier',
'customer',
'rowcount',
'sales_total',
'void',
'status_code',
'executed',
'executed_by',
]
form_fields = [
'id',
'terminal_id',
'cashier',
'customer',
'params',
'rowcount',
@ -121,13 +121,26 @@ class POSBatchView(BatchMasterView):
def configure_grid(self, g):
super().configure_grid(g)
model = self.model
# 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")
# cashier
def join_cashier(q):
return q.outerjoin(model.Employee,
model.Employee.uuid == model.POSBatch.cashier_uuid)\
.outerjoin(model.Person,
model.Person.uuid == model.Employee.person_uuid)
g.set_joiner('cashier', join_cashier)
g.set_sorter('cashier', model.Person.display_name)
# customer
g.set_link('customer')
g.set_joiner('customer', lambda q: q.outerjoin(model.Customer))
g.set_sorter('customer', model.Customer.name)
g.set_link('created')
g.set_link('created_by')
@ -144,19 +157,25 @@ class POSBatchView(BatchMasterView):
def grid_extra_class(self, batch, i):
if batch.void:
return 'warning'
if batch.training_mode:
if (batch.training_mode
or batch.status_code == batch.STATUS_SUSPENDED):
return 'notice'
def configure_form(self, f):
super().configure_form(f)
app = self.get_rattail_app()
# cashier
f.set_renderer('cashier', self.render_employee)
# customer
f.set_renderer('customer', self.render_customer)
f.set_type('sales_total', 'currency')
f.set_type('tender_total', 'currency')
f.set_type('tender_total', 'currency')
if self.viewing:
f.set_renderer('taxes', self.render_taxes)
f.set_renderer('balance', lambda batch, field: app.render_currency(batch.get_balance()))
@ -257,8 +276,8 @@ class POSBatchView(BatchMasterView):
"Make transactions (ring up sales)")
# config.add_tailbone_permission('pos', 'pos.resume',
# "Resume previously-suspended transaction")
# config.add_tailbone_permission('pos', 'pos.suspend',
# "Suspend current transaction")
config.add_tailbone_permission('pos', 'pos.suspend',
"Suspend current transaction")
config.add_tailbone_permission('pos', 'pos.swap_customer',
"Swap customer for current transaction")
config.add_tailbone_permission('pos', 'pos.void_txn',

View file

@ -1010,6 +1010,14 @@ class MasterView(View):
items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
return HTML.tag('ul', c=items)
def render_employee(self, obj, field):
employee = getattr(obj, field)
if not employee:
return ""
text = str(employee)
url = self.request.route_url('employees.view', uuid=employee.uuid)
return tags.link_to(text, url)
def render_customer(self, obj, field):
customer = getattr(obj, field)
if not customer: