Add support for system-unique ID in batch views etc.

This commit is contained in:
Lance Edgar 2016-08-17 16:50:00 -05:00
parent 343f9bde1b
commit cf1b9acfb1
3 changed files with 27 additions and 2 deletions

View file

@ -49,3 +49,5 @@ from .products import (ProductFieldRenderer, GPCFieldRenderer,
from .stores import StoreFieldRenderer
from .vendors import VendorFieldRenderer
from .batch import BatchIDFieldRenderer

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2015 Lance Edgar
# Copyright © 2010-2016 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,16 +24,28 @@
Batch Field Renderers
"""
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import
import os
import stat
import random
import formalchemy as fa
from formalchemy.ext import fsblob
from formalchemy.fields import FileFieldRenderer as Base
class BatchIDFieldRenderer(fa.FieldRenderer):
"""
Renderer for batch ID fields.
"""
def render_readonly(self, **kwargs):
batch_id = self.raw_value
if batch_id:
return '{:08d}'.format(batch_id)
return ''
# TODO: make this inherit from `tailbone.forms.renderers.files.FileFieldRenderer`
class FileFieldRenderer(fsblob.FileFieldRenderer):
"""

View file

@ -126,6 +126,9 @@ class BatchMasterView(MasterView):
'rows_grid': grid.render_complete(allow_save_defaults=False),
})
def get_instance_title(self, batch):
return batch.id_str or unicode(batch)
def _preconfigure_grid(self, g):
"""
Apply some commonly-useful pre-configuration to the main batch grid.
@ -144,6 +147,7 @@ class BatchMasterView(MasterView):
g.default_sortkey = 'created'
g.default_sortdir = 'desc'
g.id.set(label="ID", renderer=forms.renderers.BatchIDFieldRenderer)
g.created_by.set(label="Created by", renderer=forms.renderers.UserFieldRenderer)
g.cognized_by.set(renderer=forms.renderers.UserFieldRenderer)
g.executed_by.set(label="Executed by", renderer=forms.renderers.UserFieldRenderer)
@ -155,6 +159,7 @@ class BatchMasterView(MasterView):
"""
g.configure(
include=[
g.id,
g.created,
g.created_by,
g.executed,
@ -167,6 +172,8 @@ class BatchMasterView(MasterView):
Apply some commonly-useful pre-configuration to the main batch
fieldset.
"""
fs.id.set(label="ID", readonly=True, renderer=forms.renderers.BatchIDFieldRenderer)
fs.created.set(readonly=True)
fs.created_by.set(label="Created by", renderer=forms.renderers.UserFieldRenderer,
readonly=True)
@ -193,6 +200,7 @@ class BatchMasterView(MasterView):
if batch.executed:
fs.configure(
include=[
fs.id,
fs.created,
fs.created_by,
fs.executed,
@ -201,6 +209,7 @@ class BatchMasterView(MasterView):
else:
fs.configure(
include=[
fs.id,
fs.created,
fs.created_by,
])
@ -832,6 +841,7 @@ class FileBatchMasterView(BatchMasterView):
if batch.executed:
fs.configure(
include=[
fs.id,
fs.created,
fs.created_by,
fs.filename,
@ -841,6 +851,7 @@ class FileBatchMasterView(BatchMasterView):
else:
fs.configure(
include=[
fs.id,
fs.created,
fs.created_by,
fs.filename,