Add button to confirm all costs for receiving

This commit is contained in:
Lance Edgar 2023-11-01 20:53:11 -05:00
parent 7ab3d2b635
commit 55a115e57a
2 changed files with 156 additions and 47 deletions

View file

@ -36,57 +36,105 @@
% endif % endif
</%def> </%def>
<%def name="render_auto_receive_helper()"> <%def name="render_tools_helper()">
% if master.has_perm('auto_receive') and master.can_auto_receive(batch): % if allow_confirm_all_costs or (master.has_perm('auto_receive') and master.can_auto_receive(batch)):
<div class="object-helper"> <div class="object-helper">
<h3>Tools</h3> <h3>Tools</h3>
<div class="object-helper-content"> <div class="object-helper-content"
<b-button type="is-primary" style="display: flex; flex-direction: column; gap: 1rem;">
@click="autoReceiveShowDialog = true"
icon-pack="fas" % if allow_confirm_all_costs:
icon-left="check"> <b-button type="is-primary"
Auto-Receive All Items icon-pack="fas"
</b-button> icon-left="check"
@click="confirmAllCostsShowDialog = true">
Confirm All Costs
</b-button>
<b-modal has-modal-card
:active.sync="confirmAllCostsShowDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Confirm All Costs</p>
</header>
<section class="modal-card-body">
<p class="block">
You can automatically mark all catalog and invoice
cost amounts as "confirmed" if you wish.
</p>
<p class="block">
Would you like to do this?
</p>
</section>
<footer class="modal-card-foot">
<b-button @click="confirmAllCostsShowDialog = false">
Cancel
</b-button>
${h.form(url(f'{route_prefix}.confirm_all_costs', uuid=batch.uuid), **{'@submit': 'confirmAllCostsSubmitting = true'})}
${h.csrf_token(request)}
<b-button type="is-primary"
native-type="submit"
:disabled="confirmAllCostsSubmitting"
icon-pack="fas"
icon-left="check">
{{ confirmAllCostsSubmitting ? "Working, please wait..." : "Confirm All" }}
</b-button>
${h.end_form()}
</footer>
</div>
</b-modal>
% endif
% if master.has_perm('auto_receive') and master.can_auto_receive(batch):
<b-button type="is-primary"
@click="autoReceiveShowDialog = true"
icon-pack="fas"
icon-left="check">
Auto-Receive All Items
</b-button>
<b-modal has-modal-card
:active.sync="autoReceiveShowDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Auto-Receive All Items</p>
</header>
<section class="modal-card-body">
<p class="block">
You can automatically set the "received" quantity to
match the "shipped" quantity for all items, based on
the invoice.
</p>
<p class="block">
Would you like to do so?
</p>
</section>
<footer class="modal-card-foot">
<b-button @click="autoReceiveShowDialog = false">
Cancel
</b-button>
${h.form(url('{}.auto_receive'.format(route_prefix), uuid=batch.uuid), **{'@submit': 'autoReceiveSubmitting = true'})}
${h.csrf_token(request)}
<b-button type="is-primary"
native-type="submit"
:disabled="autoReceiveSubmitting"
icon-pack="fas"
icon-left="check">
{{ autoReceiveSubmitting ? "Working, please wait..." : "Auto-Receive All Items" }}
</b-button>
${h.end_form()}
</footer>
</div>
</b-modal>
% endif
</div> </div>
</div> </div>
<b-modal has-modal-card
:active.sync="autoReceiveShowDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Auto-Receive All Items</p>
</header>
<section class="modal-card-body">
<p class="block">
You can automatically set the "received" quantity to
match the "shipped" quantity for all items, based on
the invoice.
</p>
<p class="block">
Would you like to do so?
</p>
</section>
<footer class="modal-card-foot">
<b-button @click="autoReceiveShowDialog = false">
Cancel
</b-button>
${h.form(url('{}.auto_receive'.format(route_prefix), uuid=batch.uuid), **{'@submit': 'autoReceiveSubmitting = true'})}
${h.csrf_token(request)}
<b-button type="is-primary"
native-type="submit"
:disabled="autoReceiveSubmitting"
icon-pack="fas"
icon-left="check">
{{ autoReceiveSubmitting ? "Working, please wait..." : "Auto-Receive All Items" }}
</b-button>
${h.end_form()}
</footer>
</div>
</b-modal>
% endif % endif
</%def> </%def>
@ -117,13 +165,20 @@
${self.render_status_breakdown()} ${self.render_status_breakdown()}
${self.render_po_vs_invoice_helper()} ${self.render_po_vs_invoice_helper()}
${self.render_execute_helper()} ${self.render_execute_helper()}
${self.render_auto_receive_helper()} ${self.render_tools_helper()}
</%def> </%def>
<%def name="modify_this_page_vars()"> <%def name="modify_this_page_vars()">
${parent.modify_this_page_vars()} ${parent.modify_this_page_vars()}
<script type="text/javascript"> <script type="text/javascript">
% if allow_confirm_all_costs:
ThisPageData.confirmAllCostsShowDialog = false
ThisPageData.confirmAllCostsSubmitting = false
% endif
ThisPageData.autoReceiveShowDialog = false ThisPageData.autoReceiveShowDialog = false
ThisPageData.autoReceiveSubmitting = false ThisPageData.autoReceiveSubmitting = false

View file

@ -786,6 +786,13 @@ class ReceivingBatchView(PurchasingBatchView):
kwargs['allow_edit_catalog_unit_cost'] = self.allow_edit_catalog_unit_cost(batch) kwargs['allow_edit_catalog_unit_cost'] = self.allow_edit_catalog_unit_cost(batch)
kwargs['allow_edit_invoice_unit_cost'] = self.allow_edit_invoice_unit_cost(batch) kwargs['allow_edit_invoice_unit_cost'] = self.allow_edit_invoice_unit_cost(batch)
if (kwargs['allow_edit_catalog_unit_cost']
and kwargs['allow_edit_invoice_unit_cost']
and not batch.get_param('confirmed_all_costs')):
kwargs['allow_confirm_all_costs'] = True
else:
kwargs['allow_confirm_all_costs'] = False
return kwargs return kwargs
def get_context_credits(self, row): def get_context_credits(self, row):
@ -1910,6 +1917,45 @@ class ReceivingBatchView(PurchasingBatchView):
batch = self.get_instance() batch = self.get_instance()
return self.handler_action(batch, 'auto_receive') return self.handler_action(batch, 'auto_receive')
def confirm_all_costs(self):
"""
View which can "confirm all costs" for the batch.
"""
batch = self.get_instance()
return self.handler_action(batch, 'confirm_all_receiving_costs')
def confirm_all_receiving_costs_thread(self, uuid, user_uuid, progress=None):
app = self.get_rattail_app()
model = self.model
session = app.make_session()
batch = session.get(model.PurchaseBatch, uuid)
# user = session.query(model.User).get(user_uuid)
try:
self.handler.confirm_all_receiving_costs(batch, progress=progress)
# if anything goes wrong, rollback and log the error etc.
except Exception as error:
session.rollback()
log.exception("failed to confirm all costs for batch: %s", batch)
session.close()
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = f"Failed to confirm costs: {simple_error(error)}"
progress.session.save()
else:
session.commit()
session.refresh(batch)
success_url = self.get_action_url('view', batch)
session.close()
if progress:
progress.session.load()
progress.session['complete'] = True
progress.session['success_url'] = success_url
progress.session.save()
def configure_get_simple_settings(self): def configure_get_simple_settings(self):
config = self.rattail_config config = self.rattail_config
return [ return [
@ -2034,6 +2080,14 @@ class ReceivingBatchView(PurchasingBatchView):
config.add_view(cls, attr='transform_unit_row', route_name='{}.transform_unit_row'.format(route_prefix), config.add_view(cls, attr='transform_unit_row', route_name='{}.transform_unit_row'.format(route_prefix),
permission='{}.edit_row'.format(permission_prefix), renderer='json') permission='{}.edit_row'.format(permission_prefix), renderer='json')
# confirm all costs
config.add_route(f'{route_prefix}.confirm_all_costs',
f'{instance_url_prefix}/confirm-all-costs',
request_method='POST')
config.add_view(cls, attr='confirm_all_costs',
route_name=f'{route_prefix}.confirm_all_costs',
permission=f'{permission_prefix}.edit_row')
# auto-receive all items # auto-receive all items
config.add_tailbone_permission(permission_prefix, config.add_tailbone_permission(permission_prefix,
'{}.auto_receive'.format(permission_prefix), '{}.auto_receive'.format(permission_prefix),