Add "declare credit" UI for receiving batch rows
This commit is contained in:
parent
c869516449
commit
5b9e97b4eb
49
tailbone/templates/receiving/declare_credit.mako
Normal file
49
tailbone/templates/receiving/declare_credit.mako
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
## -*- coding: utf-8; -*-
|
||||||
|
<%inherit file="/base.mako" />
|
||||||
|
|
||||||
|
<%def name="title()">Declare Credit for Row #${row.sequence}</%def>
|
||||||
|
|
||||||
|
<%def name="context_menu_items()">
|
||||||
|
% if master.rows_viewable and request.has_perm('{}.view'.format(permission_prefix)):
|
||||||
|
<li>${h.link_to("View this {}".format(row_model_title), row_action_url('view', row))}</li>
|
||||||
|
% endif
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="extra_javascript()">
|
||||||
|
${parent.extra_javascript()}
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function toggleFields(creditType) {
|
||||||
|
if (creditType === undefined) {
|
||||||
|
creditType = $('select[name="credit_type"]').val();
|
||||||
|
}
|
||||||
|
if (creditType == 'expired') {
|
||||||
|
$('.field-wrapper.expiration_date').show();
|
||||||
|
} else {
|
||||||
|
$('.field-wrapper.expiration_date').hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
toggleFields();
|
||||||
|
|
||||||
|
$('select[name="credit_type"]').on('selectmenuchange', function(event, ui) {
|
||||||
|
toggleFields(ui.item.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<div style="display: flex; justify-content: space-between;">
|
||||||
|
|
||||||
|
<div class="form-wrapper">
|
||||||
|
${form.render()|n}
|
||||||
|
</div><!-- form-wrapper -->
|
||||||
|
|
||||||
|
<ul id="context-menu">
|
||||||
|
${self.context_menu_items()}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
|
@ -7,7 +7,10 @@
|
||||||
<div class="object-helper">
|
<div class="object-helper">
|
||||||
<h3>Receiving Tools</h3>
|
<h3>Receiving Tools</h3>
|
||||||
<div class="object-helper-content">
|
<div class="object-helper-content">
|
||||||
|
<div style="white-space: nowrap;">
|
||||||
${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')}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
% endif
|
% endif
|
||||||
|
|
|
@ -953,6 +953,54 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
context['parent_title'] = self.get_instance_title(batch)
|
context['parent_title'] = self.get_instance_title(batch)
|
||||||
return self.render_to_response('receive_row', context, mobile=mobile)
|
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):
|
def transform_unit_row(self):
|
||||||
"""
|
"""
|
||||||
View which transforms the given row, which is assumed to associate with
|
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),
|
config.add_view(cls, attr='mobile_receive_row', route_name='mobile.{}.receive_row'.format(route_prefix),
|
||||||
permission='{}.edit_row'.format(permission_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:
|
if cls.allow_truck_dump:
|
||||||
|
|
||||||
# add TD child batch, from invoice file
|
# add TD child batch, from invoice file
|
||||||
|
@ -1887,6 +1940,22 @@ class ReceiveRowForm(colander.MappingSchema):
|
||||||
quick_receive = colander.SchemaNode(colander.Boolean())
|
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):
|
class MobileReceivingForm(colander.MappingSchema):
|
||||||
|
|
||||||
row = colander.SchemaNode(colander.String(),
|
row = colander.SchemaNode(colander.String(),
|
||||||
|
|
Loading…
Reference in a new issue