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,31 +285,26 @@
<%def name="object_helpers()"> <%def name="object_helpers()">
${parent.object_helpers()} ${parent.object_helpers()}
## TODO: for now this is a truck-dump-only feature? maybe should change that % if master.has_perm('auto_receive') and master.can_auto_receive(batch):
% if not request.rattail_config.production() and master.handler.allow_truck_dump_receiving(): <div class="object-helper">
% if not batch.executed and not batch.complete and request.has_perm('admin'): <h3>Tools</h3>
% if (batch.is_truck_dump_parent() and batch.truck_dump_children_first) or not batch.is_truck_dump_related(): <div class="object-helper-content">
<div class="object-helper"> % if use_buefy:
<h3>Development Tools</h3> ${h.form(url('{}.auto_receive'.format(route_prefix), uuid=batch.uuid), ref='auto_receive_all_form')}
<div class="object-helper-content"> ${h.csrf_token(request)}
% if use_buefy: <once-button type="is-primary"
${h.form(url('{}.auto_receive'.format(route_prefix), uuid=batch.uuid), ref='auto_receive_all_form')} @click="$refs.auto_receive_all_form.submit()"
${h.csrf_token(request)} text="Auto-Receive All Items">
<once-button type="is-primary" </once-button>
@click="$refs.auto_receive_all_form.submit()" ${h.end_form()}
text="Auto-Receive All Items"> % else:
</once-button> ${h.form(url('{}.auto_receive'.format(route_prefix), uuid=batch.uuid), class_='autodisable')}
${h.end_form()} ${h.csrf_token(request)}
% else: ${h.submit('submit', "Auto-Receive All Items")}
${h.form(url('{}.auto_receive'.format(route_prefix), uuid=batch.uuid), class_='autodisable')} ${h.end_form()}
${h.csrf_token(request)}
${h.submit('submit', "Auto-Receive All Items")}
${h.end_form()}
% endif
</div>
</div>
% endif % endif
% endif </div>
</div>
% endif % endif
</%def> </%def>

View file

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