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
|
@ -39,6 +39,22 @@
|
||||||
<div style="display: flex; justify-content: space-between;">
|
<div style="display: flex; justify-content: space-between;">
|
||||||
|
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
|
|
||||||
|
<p style="padding: 1em;">
|
||||||
|
Please select the "state" of the product, and enter the appropriate
|
||||||
|
quantity.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="padding: 1em;">
|
||||||
|
Note that this tool will <strong>deduct</strong> from the "received"
|
||||||
|
quantity, and <strong>add</strong> to the corresponding credit quantity.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="padding: 1em;">
|
||||||
|
Please see ${h.link_to("Receive Row", url('{}.receive_row'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid))}
|
||||||
|
if you need to "receive" instead of "convert" the product.
|
||||||
|
</p>
|
||||||
|
|
||||||
${form.render()|n}
|
${form.render()|n}
|
||||||
</div><!-- form-wrapper -->
|
</div><!-- form-wrapper -->
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,22 @@
|
||||||
<div style="display: flex; justify-content: space-between;">
|
<div style="display: flex; justify-content: space-between;">
|
||||||
|
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
|
|
||||||
|
<p style="padding: 1em;">
|
||||||
|
Please select the "state" of the product, and enter the appropriate
|
||||||
|
quantity.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="padding: 1em;">
|
||||||
|
Note that this tool will <strong>add</strong> the corresponding
|
||||||
|
quantities for the row.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="padding: 1em;">
|
||||||
|
Please see ${h.link_to("Declare Credit", url('{}.declare_credit'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid))}
|
||||||
|
if you need to "convert" some already-received amount, into a credit.
|
||||||
|
</p>
|
||||||
|
|
||||||
${form.render()|n}
|
${form.render()|n}
|
||||||
</div><!-- form-wrapper -->
|
</div><!-- form-wrapper -->
|
||||||
|
|
||||||
|
|
|
@ -861,6 +861,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
|
|
||||||
schema = ReceiveRowForm().bind(session=self.Session())
|
schema = ReceiveRowForm().bind(session=self.Session())
|
||||||
form = forms.Form(schema=schema, request=self.request)
|
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('mode', forms.widgets.JQuerySelectWidget(values=[(m, m) for m in possible_modes]))
|
||||||
form.set_widget('quantity', forms.widgets.CasesUnitsWidget(amount_required=True,
|
form.set_widget('quantity', forms.widgets.CasesUnitsWidget(amount_required=True,
|
||||||
one_amount_only=True))
|
one_amount_only=True))
|
||||||
|
@ -996,7 +997,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
'allow_cases': self.handler.allow_cases(),
|
'allow_cases': self.handler.allow_cases(),
|
||||||
}
|
}
|
||||||
|
|
||||||
schema = DeclareCreditForm().bind(session=self.Session())
|
schema = DeclareCreditForm()
|
||||||
form = forms.Form(schema=schema, request=self.request)
|
form = forms.Form(schema=schema, request=self.request)
|
||||||
form.set_widget('credit_type', forms.widgets.JQuerySelectWidget(
|
form.set_widget('credit_type', forms.widgets.JQuerySelectWidget(
|
||||||
values=[(m, m) for m in possible_credit_types]))
|
values=[(m, m) for m in possible_credit_types]))
|
||||||
|
@ -1011,9 +1012,16 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
kwargs['cases'] = kwargs['quantity']['cases']
|
kwargs['cases'] = kwargs['quantity']['cases']
|
||||||
kwargs['units'] = kwargs['quantity']['units']
|
kwargs['units'] = kwargs['quantity']['units']
|
||||||
del kwargs['quantity']
|
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['form'] = form
|
||||||
context['dform'] = form.make_deform_form()
|
context['dform'] = form.make_deform_form()
|
||||||
|
|
Loading…
Reference in a new issue