From 98ca378302c1b60286d373368c153992698c0283 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 16 Aug 2017 22:26:52 -0500 Subject: [PATCH] Add extra perms for creating inventory batch w/ different modes --- tailbone/views/inventory.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tailbone/views/inventory.py b/tailbone/views/inventory.py index 03ef10ba..365b5af9 100644 --- a/tailbone/views/inventory.py +++ b/tailbone/views/inventory.py @@ -109,8 +109,23 @@ class InventoryBatchView(BatchMasterView): def _preconfigure_fieldset(self, fs): super(InventoryBatchView, self)._preconfigure_fieldset(fs) - fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.INVENTORY_MODE), + permission_prefix = self.get_permission_prefix() + + modes = dict(self.enum.INVENTORY_MODE) + if not self.request.has_perm('{}.create.replace'.format(permission_prefix)): + if hasattr(self.enum, 'INVENTORY_MODE_REPLACE'): + modes.pop(self.enum.INVENTORY_MODE_REPLACE, None) + if hasattr(self.enum, 'INVENTORY_MODE_REPLACE_ADJUST'): + modes.pop(self.enum.INVENTORY_MODE_REPLACE_ADJUST, None) + if not self.request.has_perm('{}.create.zero'.format(permission_prefix)): + 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) + 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)) @@ -319,15 +334,17 @@ class InventoryBatchView(BatchMasterView): @classmethod def defaults(cls, config): - cls._inventory_defaults(config) cls._batch_defaults(config) cls._defaults(config) + cls._inventory_defaults(config) @classmethod def _inventory_defaults(cls, config): model_key = cls.get_model_key() + model_title = cls.get_model_title() route_prefix = cls.get_route_prefix() url_prefix = cls.get_url_prefix() + permission_prefix = cls.get_permission_prefix() row_permission_prefix = cls.get_row_permission_prefix() # mobile - make new row from UPC @@ -335,6 +352,12 @@ class InventoryBatchView(BatchMasterView): config.add_view(cls, attr='mobile_row_from_upc', route_name='mobile.{}.row_from_upc'.format(route_prefix), permission='{}.create'.format(row_permission_prefix)) + # extra perms for creating batches per "mode" + config.add_tailbone_permission(permission_prefix, '{}.create.replace'.format(permission_prefix), + "Create new {} with 'replace' mode".format(model_title)) + config.add_tailbone_permission(permission_prefix, '{}.create.zero'.format(permission_prefix), + "Create new {} with 'zero' mode".format(model_title)) + class ValidBatchRow(forms.validators.ModelValidator): model_class = model.InventoryBatchRow