Refactor inventory batch views to use master3
This commit is contained in:
parent
e0650d26cf
commit
34e81dc50a
|
@ -38,12 +38,12 @@ from rattail.gpc import GPC
|
||||||
from rattail.util import pretty_quantity
|
from rattail.util import pretty_quantity
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
import formalchemy as fa
|
|
||||||
import formencode as fe
|
import formencode as fe
|
||||||
|
from webhelpers2.html import HTML, tags
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms
|
||||||
from tailbone.views import MasterView3 as MasterView
|
from tailbone.views import MasterView3 as MasterView
|
||||||
from tailbone.views.batch import BatchMasterView2 as BatchMasterView
|
from tailbone.views.batch import BatchMasterView3 as BatchMasterView
|
||||||
|
|
||||||
|
|
||||||
class InventoryAdjustmentReasonsView(MasterView):
|
class InventoryAdjustmentReasonsView(MasterView):
|
||||||
|
@ -102,6 +102,20 @@ class InventoryBatchView(BatchMasterView):
|
||||||
'executed_by',
|
'executed_by',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
form_fields = [
|
||||||
|
'id',
|
||||||
|
'description',
|
||||||
|
'created',
|
||||||
|
'created_by',
|
||||||
|
'handheld_batches',
|
||||||
|
'mode',
|
||||||
|
'reason_code',
|
||||||
|
'rowcount',
|
||||||
|
'complete',
|
||||||
|
'executed',
|
||||||
|
'executed_by',
|
||||||
|
]
|
||||||
|
|
||||||
model_row_class = model.InventoryBatchRow
|
model_row_class = model.InventoryBatchRow
|
||||||
rows_editable = True
|
rows_editable = True
|
||||||
|
|
||||||
|
@ -142,8 +156,8 @@ class InventoryBatchView(BatchMasterView):
|
||||||
def allow_worksheet(self, batch):
|
def allow_worksheet(self, batch):
|
||||||
return self.mutable_batch(batch)
|
return self.mutable_batch(batch)
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fs):
|
def configure_form(self, f):
|
||||||
super(InventoryBatchView, self)._preconfigure_fieldset(fs)
|
super(InventoryBatchView, self).configure_form(f)
|
||||||
permission_prefix = self.get_permission_prefix()
|
permission_prefix = self.get_permission_prefix()
|
||||||
|
|
||||||
modes = dict(self.enum.INVENTORY_MODE)
|
modes = dict(self.enum.INVENTORY_MODE)
|
||||||
|
@ -156,30 +170,27 @@ class InventoryBatchView(BatchMasterView):
|
||||||
if hasattr(self.enum, 'INVENTORY_MODE_ZERO_ALL'):
|
if hasattr(self.enum, 'INVENTORY_MODE_ZERO_ALL'):
|
||||||
modes.pop(self.enum.INVENTORY_MODE_ZERO_ALL, None)
|
modes.pop(self.enum.INVENTORY_MODE_ZERO_ALL, None)
|
||||||
|
|
||||||
fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(modes),
|
# mode
|
||||||
label="Count Mode", required=True, attrs={'auto-enhance': 'true'})
|
f.set_enum('mode', modes)
|
||||||
# if len(modes) == 1:
|
f.set_label('mode', "Count Mode")
|
||||||
# fs.mode.set(readonly=True)
|
if len(modes) == 1:
|
||||||
|
f.set_readonly('mode')
|
||||||
|
|
||||||
fs.total_cost.set(readonly=True, renderer=forms.renderers.CurrencyFieldRenderer)
|
# total_cost
|
||||||
fs.append(fa.Field('handheld_batches', renderer=forms.renderers.HandheldBatchesFieldRenderer, readonly=True,
|
f.set_readonly('total_cost')
|
||||||
value=lambda b: b._handhelds))
|
f.set_type('total_cost', 'currency')
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
# handheld_batches
|
||||||
fs.configure(
|
f.set_readonly('handheld_batches')
|
||||||
include=[
|
f.set_renderer('handheld_batches', self.render_handheld_batches)
|
||||||
fs.id,
|
|
||||||
fs.description,
|
def render_handheld_batches(self, inventory_batch, field):
|
||||||
fs.created,
|
items = ''
|
||||||
fs.created_by,
|
for handheld in inventory_batch._handhelds:
|
||||||
fs.handheld_batches,
|
text = handheld.handheld.id_str
|
||||||
fs.mode,
|
url = self.request.route_url('batch.handheld.view', uuid=handheld.handheld_uuid)
|
||||||
fs.reason_code,
|
items += HTML.tag('li', c=tags.link_to(text, url))
|
||||||
fs.rowcount,
|
return HTML.tag('ul', c=items)
|
||||||
fs.complete,
|
|
||||||
fs.executed,
|
|
||||||
fs.executed_by,
|
|
||||||
])
|
|
||||||
|
|
||||||
def row_editable(self, row):
|
def row_editable(self, row):
|
||||||
return self.mutable_batch(row.batch)
|
return self.mutable_batch(row.batch)
|
||||||
|
|
Loading…
Reference in a new issue