From dd22c0457353b121985b4f8c32d710b7ba01ebe0 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 5 Jan 2018 18:37:16 -0600 Subject: [PATCH] Add view for InventoryAdjustmentReason model --- tailbone/views/inventory.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tailbone/views/inventory.py b/tailbone/views/inventory.py index 80bb5578..d4492bff 100644 --- a/tailbone/views/inventory.py +++ b/tailbone/views/inventory.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2018 Lance Edgar # # This file is part of Rattail. # @@ -36,13 +36,44 @@ from rattail.time import localtime from rattail.gpc import GPC from rattail.util import pretty_quantity +import colander import formalchemy as fa import formencode as fe from tailbone import forms +from tailbone.views import MasterView3 as MasterView from tailbone.views.batch import BatchMasterView2 as BatchMasterView +class InventoryAdjustmentReasonsView(MasterView): + """ + Master view for inventory adjustment reasons. + """ + model_class = model.InventoryAdjustmentReason + route_prefix = 'invadjust_reasons' + url_prefix = '/inventory-adjustment-reasons' + + grid_columns = [ + 'code', + 'description', + ] + + def configure_form(self, f): + super(InventoryAdjustmentReasonsView, self).configure_form(f) + + # code + f.set_validator('code', self.unique_code) + + def unique_code(self, node, value): + query = self.Session.query(model.InventoryAdjustmentReason)\ + .filter(model.InventoryAdjustmentReason.code == value) + if self.editing: + reason = self.get_instance() + query = query.filter(model.InventoryAdjustmentReason.uuid != reason.uuid) + if query.count(): + raise colander.Invalid(node, "Code must be unique") + + class InventoryBatchView(BatchMasterView): """ Master view for inventory batches. @@ -391,4 +422,5 @@ class InventoryForm(forms.Schema): def includeme(config): + InventoryAdjustmentReasonsView.defaults(config) InventoryBatchView.defaults(config)