diff --git a/tailbone/templates/receiving/declare_credit.mako b/tailbone/templates/receiving/declare_credit.mako index 23352169..6596ff1b 100644 --- a/tailbone/templates/receiving/declare_credit.mako +++ b/tailbone/templates/receiving/declare_credit.mako @@ -39,6 +39,22 @@
+ +

+ Please select the "state" of the product, and enter the appropriate + quantity. +

+ +

+ Note that this tool will deduct from the "received" + quantity, and add to the corresponding credit quantity. +

+ +

+ 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. +

+ ${form.render()|n}
diff --git a/tailbone/templates/receiving/receive_row.mako b/tailbone/templates/receiving/receive_row.mako index d0f1c31f..188fbe7b 100644 --- a/tailbone/templates/receiving/receive_row.mako +++ b/tailbone/templates/receiving/receive_row.mako @@ -39,6 +39,22 @@
+ +

+ Please select the "state" of the product, and enter the appropriate + quantity. +

+ +

+ Note that this tool will add the corresponding + quantities for the row. +

+ +

+ 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. +

+ ${form.render()|n}
diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index fbe0ddbe..c3789e95 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -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()