diff --git a/tailbone/views/inventory.py b/tailbone/views/inventory.py index 215322ca..eb88c65a 100644 --- a/tailbone/views/inventory.py +++ b/tailbone/views/inventory.py @@ -38,12 +38,12 @@ from rattail.gpc import GPC from rattail.util import pretty_quantity import colander -import formalchemy as fa import formencode as fe +from webhelpers2.html import HTML, tags from tailbone import forms 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): @@ -102,6 +102,20 @@ class InventoryBatchView(BatchMasterView): 'executed_by', ] + form_fields = [ + 'id', + 'description', + 'created', + 'created_by', + 'handheld_batches', + 'mode', + 'reason_code', + 'rowcount', + 'complete', + 'executed', + 'executed_by', + ] + model_row_class = model.InventoryBatchRow rows_editable = True @@ -142,8 +156,8 @@ class InventoryBatchView(BatchMasterView): def allow_worksheet(self, batch): return self.mutable_batch(batch) - def _preconfigure_fieldset(self, fs): - super(InventoryBatchView, self)._preconfigure_fieldset(fs) + def configure_form(self, f): + super(InventoryBatchView, self).configure_form(f) permission_prefix = self.get_permission_prefix() modes = dict(self.enum.INVENTORY_MODE) @@ -156,30 +170,27 @@ class InventoryBatchView(BatchMasterView): if hasattr(self.enum, 'INVENTORY_MODE_ZERO_ALL'): modes.pop(self.enum.INVENTORY_MODE_ZERO_ALL, None) - fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(modes), - label="Count Mode", required=True, attrs={'auto-enhance': 'true'}) - # if len(modes) == 1: - # fs.mode.set(readonly=True) + # mode + f.set_enum('mode', modes) + f.set_label('mode', "Count Mode") + if len(modes) == 1: + f.set_readonly('mode') - fs.total_cost.set(readonly=True, renderer=forms.renderers.CurrencyFieldRenderer) - fs.append(fa.Field('handheld_batches', renderer=forms.renderers.HandheldBatchesFieldRenderer, readonly=True, - value=lambda b: b._handhelds)) + # total_cost + f.set_readonly('total_cost') + f.set_type('total_cost', 'currency') - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.id, - fs.description, - fs.created, - fs.created_by, - fs.handheld_batches, - fs.mode, - fs.reason_code, - fs.rowcount, - fs.complete, - fs.executed, - fs.executed_by, - ]) + # handheld_batches + f.set_readonly('handheld_batches') + f.set_renderer('handheld_batches', self.render_handheld_batches) + + def render_handheld_batches(self, inventory_batch, field): + items = '' + for handheld in inventory_batch._handhelds: + text = handheld.handheld.id_str + url = self.request.route_url('batch.handheld.view', uuid=handheld.handheld_uuid) + items += HTML.tag('li', c=tags.link_to(text, url)) + return HTML.tag('ul', c=items) def row_editable(self, row): return self.mutable_batch(row.batch)