Add extra perms for creating inventory batch w/ different modes

This commit is contained in:
Lance Edgar 2017-08-16 22:26:52 -05:00
parent 860f990a2e
commit 98ca378302

View file

@ -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