Allow "auto-receive all items" batch feature in production

but require a dedicated permission
This commit is contained in:
Lance Edgar 2021-12-08 20:26:31 -06:00
parent 10e34b83ed
commit be92075abb
2 changed files with 45 additions and 29 deletions

View file

@ -285,12 +285,9 @@
<%def name="object_helpers()">
${parent.object_helpers()}
## TODO: for now this is a truck-dump-only feature? maybe should change that
% if not request.rattail_config.production() and master.handler.allow_truck_dump_receiving():
% if not batch.executed and not batch.complete and request.has_perm('admin'):
% if (batch.is_truck_dump_parent() and batch.truck_dump_children_first) or not batch.is_truck_dump_related():
% if master.has_perm('auto_receive') and master.can_auto_receive(batch):
<div class="object-helper">
<h3>Development Tools</h3>
<h3>Tools</h3>
<div class="object-helper-content">
% if use_buefy:
${h.form(url('{}.auto_receive'.format(route_prefix), uuid=batch.uuid), ref='auto_receive_all_form')}
@ -309,8 +306,6 @@
</div>
</div>
% endif
% endif
% endif
</%def>

View file

@ -1469,6 +1469,24 @@ class ReceivingBatchView(PurchasingBatchView):
if self.rattail_config.getbool('rattail.batch', 'purchase.mobile_images', default=True):
return pod.get_image_url(self.rattail_config, row.upc)
def can_auto_receive(self, batch):
if batch.executed:
return False
if batch.complete:
return False
if batch.is_truck_dump_related():
if not batch.is_truck_dump_parent():
return False
if not batch.truck_dump_children_first():
return False
# only auto-receive once per batch
if batch.get_param('auto_received'):
return False
return True
def auto_receive(self):
"""
View which can "auto-receive" all items in the batch. Meant only as a
@ -1535,6 +1553,7 @@ class ReceivingBatchView(PurchasingBatchView):
url_prefix = cls.get_url_prefix()
instance_url_prefix = cls.get_instance_url_prefix()
model_key = cls.get_model_key()
model_title = cls.get_model_title()
permission_prefix = cls.get_permission_prefix()
# new receiving batch using workflow X
@ -1569,11 +1588,13 @@ class ReceivingBatchView(PurchasingBatchView):
permission='{}.edit_row'.format(permission_prefix), renderer='json')
# auto-receive all items
if not rattail_config.production():
config.add_tailbone_permission(permission_prefix,
'{}.auto_receive'.format(permission_prefix),
"Auto-receive all items for a {}".format(model_title))
config.add_route('{}.auto_receive'.format(route_prefix), '{}/auto-receive'.format(instance_url_prefix),
request_method='POST')
config.add_view(cls, attr='auto_receive', route_name='{}.auto_receive'.format(route_prefix),
permission='admin')
permission='{}.auto_receive'.format(permission_prefix))
@colander.deferred