Changeset 5b9e97b in tailbone


Ignore:
Timestamp:
03/13/19 19:15:53 (6 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
b67414b
Parents:
c8695164
Message:

Add "declare credit" UI for receiving batch rows

Location:
tailbone
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • tailbone/templates/receiving/view_row.mako

    rc8695164 r5b9e97b  
    88        <h3>Receiving Tools</h3>
    99        <div class="object-helper-content">
    10           ${h.link_to("Receive Product", url('{}.receive_row'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid), class_='button autodisable')}
     10          <div style="white-space: nowrap;">
     11            ${h.link_to("Receive Product", url('{}.receive_row'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid), class_='button autodisable')}
     12            ${h.link_to("Declare Credit", url('{}.declare_credit'.format(route_prefix), uuid=batch.uuid, row_uuid=row.uuid), class_='button autodisable')}
     13          </div>
    1114        </div>
    1215      </div>
  • tailbone/views/purchasing/receiving.py

    rc8695164 r5b9e97b  
    954954        return self.render_to_response('receive_row', context, mobile=mobile)
    955955
     956    def declare_credit(self):
     957        """
     958        View for declaring a credit, i.e. converting some "received" or similar
     959        quantity, to a credit of some sort.
     960        """
     961        row = self.get_row_instance()
     962        batch = row.batch
     963        possible_credit_types = [
     964            'damaged',
     965            'expired',
     966        ]
     967        context = {
     968            'row': row,
     969            'batch': batch,
     970            'parent_instance': batch,
     971            'instance': row,
     972            'instance_title': self.get_row_instance_title(row),
     973            'parent_model_title': self.get_model_title(),
     974            'product_image_url': self.get_row_image_url(row),
     975            'allow_expired': self.handler.allow_expired_credits(),
     976            'allow_cases': self.handler.allow_cases(),
     977        }
     978
     979        schema = DeclareCreditForm().bind(session=self.Session())
     980        form = forms.Form(schema=schema, request=self.request)
     981        form.set_widget('credit_type', forms.widgets.JQuerySelectWidget(
     982            values=[(m, m) for m in possible_credit_types]))
     983        form.set_widget('quantity', forms.widgets.CasesUnitsWidget(
     984            amount_required=True, one_amount_only=True))
     985        form.set_type('expiration_date', 'date_jquery')
     986
     987        if form.validate(newstyle=True):
     988
     989            # handler takes care of the row receiving logic for us
     990            kwargs = dict(form.validated)
     991            kwargs['cases'] = kwargs['quantity']['cases']
     992            kwargs['units'] = kwargs['quantity']['units']
     993            del kwargs['quantity']
     994            self.handler.declare_credit(row, **kwargs)
     995
     996            return self.redirect(self.get_row_action_url('view', row))
     997
     998        context['form'] = form
     999        context['dform'] = form.make_deform_form()
     1000        context['parent_url'] = self.get_action_url('view', batch)
     1001        context['parent_title'] = self.get_instance_title(batch)
     1002        return self.render_to_response('declare_credit', context)
     1003
    9561004    def transform_unit_row(self):
    9571005        """
     
    17911839                        permission='{}.edit_row'.format(permission_prefix))
    17921840
     1841        # declare credit for row
     1842        config.add_route('{}.declare_credit'.format(route_prefix), '{}/{{uuid}}/rows/{{row_uuid}}/declare-credit'.format(url_prefix))
     1843        config.add_view(cls, attr='declare_credit', route_name='{}.declare_credit'.format(route_prefix),
     1844                        permission='{}.edit_row'.format(permission_prefix))
     1845
    17931846        if cls.allow_truck_dump:
    17941847
     
    18881941
    18891942
     1943class DeclareCreditForm(colander.MappingSchema):
     1944
     1945    credit_type = colander.SchemaNode(colander.String(),
     1946                                      validator=colander.OneOf([
     1947                                          'damaged',
     1948                                          'expired',
     1949                                          # 'mispick',
     1950                                      ]))
     1951
     1952    quantity = forms.types.ProductQuantity()
     1953
     1954    expiration_date = colander.SchemaNode(colander.Date(),
     1955                                          widget=dfwidget.TextInputWidget(),
     1956                                          missing=colander.null)
     1957
     1958
    18901959class MobileReceivingForm(colander.MappingSchema):
    18911960
Note: See TracChangeset for help on using the changeset viewer.