Add button to confirm all costs for receiving
This commit is contained in:
parent
7ab3d2b635
commit
55a115e57a
2 changed files with 156 additions and 47 deletions
tailbone/views/purchasing
|
@ -786,6 +786,13 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
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)
|
||||
|
||||
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
|
||||
|
||||
def get_context_credits(self, row):
|
||||
|
@ -1910,6 +1917,45 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
batch = self.get_instance()
|
||||
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):
|
||||
config = self.rattail_config
|
||||
return [
|
||||
|
@ -2034,6 +2080,14 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
config.add_view(cls, attr='transform_unit_row', route_name='{}.transform_unit_row'.format(route_prefix),
|
||||
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
|
||||
config.add_tailbone_permission(permission_prefix,
|
||||
'{}.auto_receive'.format(permission_prefix),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue