From 5b9e97b4ebc3a0a0fed6fa0f6b5be121b5c8093f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 13 Mar 2019 19:15:53 -0500 Subject: [PATCH] Add "declare credit" UI for receiving batch rows --- .../templates/receiving/declare_credit.mako | 49 +++++++++++++ tailbone/templates/receiving/view_row.mako | 5 +- tailbone/views/purchasing/receiving.py | 69 +++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tailbone/templates/receiving/declare_credit.mako diff --git a/tailbone/templates/receiving/declare_credit.mako b/tailbone/templates/receiving/declare_credit.mako new file mode 100644 index 00000000..23352169 --- /dev/null +++ b/tailbone/templates/receiving/declare_credit.mako @@ -0,0 +1,49 @@ +## -*- coding: utf-8; -*- +<%inherit file="/base.mako" /> + +<%def name="title()">Declare Credit for Row #${row.sequence} + +<%def name="context_menu_items()"> + % if master.rows_viewable and request.has_perm('{}.view'.format(permission_prefix)): +
  • ${h.link_to("View this {}".format(row_model_title), row_action_url('view', row))}
  • + % endif + + +<%def name="extra_javascript()"> + ${parent.extra_javascript()} + + + +
    + +
    + ${form.render()|n} +
    + + + +
    diff --git a/tailbone/templates/receiving/view_row.mako b/tailbone/templates/receiving/view_row.mako index aabdb932..9ba6a0bb 100644 --- a/tailbone/templates/receiving/view_row.mako +++ b/tailbone/templates/receiving/view_row.mako @@ -7,7 +7,10 @@

    Receiving Tools

    - ${h.link_to("Receive Product", url('{}.receive_row'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid), class_='button autodisable')} +
    + ${h.link_to("Receive Product", url('{}.receive_row'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid), class_='button autodisable')} + ${h.link_to("Declare Credit", url('{}.declare_credit'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid), class_='button autodisable')} +
    % endif diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 42a3821c..ab76d112 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -953,6 +953,54 @@ class ReceivingBatchView(PurchasingBatchView): context['parent_title'] = self.get_instance_title(batch) return self.render_to_response('receive_row', context, mobile=mobile) + def declare_credit(self): + """ + View for declaring a credit, i.e. converting some "received" or similar + quantity, to a credit of some sort. + """ + row = self.get_row_instance() + batch = row.batch + possible_credit_types = [ + 'damaged', + 'expired', + ] + context = { + 'row': row, + 'batch': batch, + 'parent_instance': batch, + 'instance': row, + 'instance_title': self.get_row_instance_title(row), + 'parent_model_title': self.get_model_title(), + 'product_image_url': self.get_row_image_url(row), + 'allow_expired': self.handler.allow_expired_credits(), + 'allow_cases': self.handler.allow_cases(), + } + + schema = DeclareCreditForm().bind(session=self.Session()) + 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])) + form.set_widget('quantity', forms.widgets.CasesUnitsWidget( + amount_required=True, one_amount_only=True)) + form.set_type('expiration_date', 'date_jquery') + + if form.validate(newstyle=True): + + # handler takes care of the row receiving logic for us + kwargs = dict(form.validated) + kwargs['cases'] = kwargs['quantity']['cases'] + kwargs['units'] = kwargs['quantity']['units'] + del kwargs['quantity'] + self.handler.declare_credit(row, **kwargs) + + return self.redirect(self.get_row_action_url('view', row)) + + context['form'] = form + context['dform'] = form.make_deform_form() + context['parent_url'] = self.get_action_url('view', batch) + context['parent_title'] = self.get_instance_title(batch) + return self.render_to_response('declare_credit', context) + def transform_unit_row(self): """ View which transforms the given row, which is assumed to associate with @@ -1790,6 +1838,11 @@ class ReceivingBatchView(PurchasingBatchView): config.add_view(cls, attr='mobile_receive_row', route_name='mobile.{}.receive_row'.format(route_prefix), permission='{}.edit_row'.format(permission_prefix)) + # declare credit for row + config.add_route('{}.declare_credit'.format(route_prefix), '{}/{{uuid}}/rows/{{row_uuid}}/declare-credit'.format(url_prefix)) + config.add_view(cls, attr='declare_credit', route_name='{}.declare_credit'.format(route_prefix), + permission='{}.edit_row'.format(permission_prefix)) + if cls.allow_truck_dump: # add TD child batch, from invoice file @@ -1887,6 +1940,22 @@ class ReceiveRowForm(colander.MappingSchema): quick_receive = colander.SchemaNode(colander.Boolean()) +class DeclareCreditForm(colander.MappingSchema): + + credit_type = colander.SchemaNode(colander.String(), + validator=colander.OneOf([ + 'damaged', + 'expired', + # 'mispick', + ])) + + quantity = forms.types.ProductQuantity() + + expiration_date = colander.SchemaNode(colander.Date(), + widget=dfwidget.TextInputWidget(), + missing=colander.null) + + class MobileReceivingForm(colander.MappingSchema): row = colander.SchemaNode(colander.String(),