Let inventory batch handler decide which count modes are available

This commit is contained in:
Lance Edgar 2020-03-29 13:37:50 -05:00
parent 6a58f5f5d3
commit dc4531f545

View file

@ -37,7 +37,7 @@ from rattail.db import model, api
from rattail.db.util import make_full_description
from rattail.time import localtime
from rattail.gpc import GPC
from rattail.util import pretty_quantity
from rattail.util import pretty_quantity, OrderedDict
import colander
from deform import widget as dfwidget
@ -176,18 +176,15 @@ class InventoryBatchView(BatchMasterView):
def get_available_modes(self):
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.handler.allow_zero_all or 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)
if not self.handler.allow_variance or not self.request.has_perm('{}.create.variance'.format(permission_prefix)):
if hasattr(self.enum, 'INVENTORY_MODE_VARIANCE'):
modes.pop(self.enum.INVENTORY_MODE_VARIANCE, None)
if self.request.is_root:
modes = self.handler.get_count_modes()
else:
modes = self.handler.get_allowed_count_modes(
self.Session(), self.request.user,
permission_prefix=permission_prefix)
modes = OrderedDict([(mode['code'], mode['label'])
for mode in modes])
return modes
def configure_form(self, f):