Add validation when "declaring credit" for receiving batch row
i.e. don't just blindly attempt, when it isn't supported
This commit is contained in:
parent
d60679adfd
commit
18ad664acb
3 changed files with 43 additions and 3 deletions
|
@ -861,6 +861,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
schema = ReceiveRowForm().bind(session=self.Session())
|
||||
form = forms.Form(schema=schema, request=self.request)
|
||||
form.cancel_url = self.get_row_action_url('view', row, mobile=mobile)
|
||||
form.set_widget('mode', forms.widgets.JQuerySelectWidget(values=[(m, m) for m in possible_modes]))
|
||||
form.set_widget('quantity', forms.widgets.CasesUnitsWidget(amount_required=True,
|
||||
one_amount_only=True))
|
||||
|
@ -996,7 +997,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'allow_cases': self.handler.allow_cases(),
|
||||
}
|
||||
|
||||
schema = DeclareCreditForm().bind(session=self.Session())
|
||||
schema = DeclareCreditForm()
|
||||
form = forms.Form(schema=schema, request=self.request)
|
||||
form.set_widget('credit_type', forms.widgets.JQuerySelectWidget(
|
||||
values=[(m, m) for m in possible_credit_types]))
|
||||
|
@ -1011,9 +1012,16 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
kwargs['cases'] = kwargs['quantity']['cases']
|
||||
kwargs['units'] = kwargs['quantity']['units']
|
||||
del kwargs['quantity']
|
||||
self.handler.declare_credit(row, **kwargs)
|
||||
try:
|
||||
result = self.handler.can_declare_credit(row, **kwargs)
|
||||
except Exception as error:
|
||||
self.request.session.flash("Handler says you can't declare that credit: {}".format(error), 'error')
|
||||
else:
|
||||
if result:
|
||||
self.handler.declare_credit(row, **kwargs)
|
||||
return self.redirect(self.get_row_action_url('view', row))
|
||||
|
||||
return self.redirect(self.get_row_action_url('view', row))
|
||||
self.request.session.flash("Handler says you can't declare that credit; not sure why", 'error')
|
||||
|
||||
context['form'] = form
|
||||
context['dform'] = form.make_deform_form()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue