Ability to receive PO lines items individually

This commit is contained in:
Oliver Walters 2019-09-23 19:31:18 +10:00
parent 0d68dbcfa7
commit 8d92960f10
2 changed files with 47 additions and 5 deletions

View File

@ -108,9 +108,7 @@ InvenTree | {{ order }}
<th data-sortable='true'>Received</th> <th data-sortable='true'>Received</th>
{% endif %} {% endif %}
<th>Note</th> <th>Note</th>
{% if order.status == OrderStatus.PENDING %}
<th></th> <th></th>
{% endif %}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -137,18 +135,23 @@ InvenTree | {{ order }}
<td> <td>
{{ line.notes }} {{ line.notes }}
</td> </td>
{% if order.status == OrderStatus.PENDING %}
<td> <td>
<div class='btn-group'> <div class='btn-group'>
{% if order.status == OrderStatus.PENDING %}
<button class='btn btn-default btn-glyph' line='{{ line.id }}' id='edit-line-item-{{ line.id }} title='Edit line item' onclick='editPurchaseOrderLineItem()'> <button class='btn btn-default btn-glyph' line='{{ line.id }}' id='edit-line-item-{{ line.id }} title='Edit line item' onclick='editPurchaseOrderLineItem()'>
<span url="{% url 'po-line-item-edit' line.id %}" line='{{ line.id }}' class='glyphicon glyphicon-edit'></span> <span url="{% url 'po-line-item-edit' line.id %}" line='{{ line.id }}' class='glyphicon glyphicon-edit'></span>
</button> </button>
<button class='btn btn-default btn-glyph' line='{{ line.id }}' id='remove-line-item-{{ line.id }' title='Remove line item' type='button' onclick='removePurchaseOrderLineItem()'> <button class='btn btn-default btn-glyph' line='{{ line.id }}' id='remove-line-item-{{ line.id }' title='Remove line item' type='button' onclick='removePurchaseOrderLineItem()'>
<span url="{% url 'po-line-item-delete' line.id %}" line='{{ line.id }}' class='glyphicon glyphicon-remove'></span> <span url="{% url 'po-line-item-delete' line.id %}" line='{{ line.id }}' class='glyphicon glyphicon-remove'></span>
</button> </button>
{% endif %}
{% if order.status == OrderStatus.PLACED and line.received < line.quantity %}
<button class='btn btn-default btn-glyph line-receive' pk='{{ line.pk }}' title='Receive item(s)'>
<span class='glyphicon glyphicon-check'></span>
</button>
{% endif %}
</div> </div>
</td> </td>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -187,6 +190,20 @@ $("#cancel-order").click(function() {
}); });
}); });
$("#po-lines-table").on('click', ".line-receive", function() {
var button = $(this);
console.log('clicked! ' + button.attr('pk'));
launchModalForm("{% url 'purchase-order-receive' order.id %}", {
reload: true,
data: {
line: button.attr('pk')
}
});
});
$("#receive-order").click(function() { $("#receive-order").click(function() {
launchModalForm("{% url 'purchase-order-receive' order.id %}", { launchModalForm("{% url 'purchase-order-receive' order.id %}", {
reload: true, reload: true,

View File

@ -230,6 +230,31 @@ class PurchaseOrderReceive(AjaxUpdateView):
return ctx return ctx
def get_lines(self):
"""
Extract particular line items from the request,
or default to *all* pending line items if none are provided
"""
lines = None
if 'line' in self.request.GET:
line_id = self.request.GET.get('line')
try:
lines = PurchaseOrderLineItem.objects.filter(pk=line_id)
except (PurchaseOrderLineItem.DoesNotExist, ValueError):
pass
# TODO - Option to pass multiple lines?
# No lines specified - default selection
if lines is None:
lines = self.order.pending_line_items()
return lines
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
""" Respond to a GET request. Determines which parts are outstanding, """ Respond to a GET request. Determines which parts are outstanding,
and presents a list of these parts to the user. and presents a list of these parts to the user.
@ -238,7 +263,7 @@ class PurchaseOrderReceive(AjaxUpdateView):
self.request = request self.request = request
self.order = get_object_or_404(PurchaseOrder, pk=self.kwargs['pk']) self.order = get_object_or_404(PurchaseOrder, pk=self.kwargs['pk'])
self.lines = self.order.pending_line_items() self.lines = self.get_lines()
for line in self.lines: for line in self.lines:
# Pre-fill the remaining quantity # Pre-fill the remaining quantity