Improved handling of po items destination

This commit is contained in:
eeintech 2021-07-20 17:15:01 -04:00
parent d9673244d5
commit 8ac3d42fd8
3 changed files with 31 additions and 11 deletions

View File

@ -84,9 +84,9 @@ class ReceivePurchaseOrderForm(HelperForm):
location = TreeNodeChoiceField( location = TreeNodeChoiceField(
queryset=StockLocation.objects.all(), queryset=StockLocation.objects.all(),
required=True, required=False,
label=_("Destination"), label=_("Destination"),
help_text=_("Receive parts to this location"), help_text=_("Set all received parts listed above to this location (if left blank, use \"Destination\" column value in above table)"),
) )
class Meta: class Meta:

View File

@ -12,7 +12,7 @@
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
<label class='control-label'>{% trans "Parts" %}</label> <label class='control-label'>{% trans "Parts" %}</label>
<p class='help-block'>{% trans "Select parts to receive against this order" %}</p> <p class='help-block'>{% trans "Fill out number of parts received, the status and destination" %}</p>
<table class='table table-striped'> <table class='table table-striped'>
<tr> <tr>
@ -55,7 +55,14 @@
</div> </div>
</td> </td>
<td> <td>
{{ line.get_destination }} <div class='control-group'>
<select class='select' name='destination-{{ line.id }}'>
<option value="">----------</option>
{% for location in stock_locations %}
<option value="{{ location.pk }}" {% if location == line.get_destination %}selected="selected"{% endif %}>{{ location }}</option>
{% endfor %}
</select>
</div>
</td> </td>
<td> <td>
<button class='btn btn-default btn-remove' onClick="removeOrderRowFromOrderWizard()" id='del_item_{{ line.id }}' title='{% trans "Remove line" %}' type='button'> <button class='btn btn-default btn-remove' onClick="removeOrderRowFromOrderWizard()" id='del_item_{{ line.id }}' title='{% trans "Remove line" %}' type='button'>
@ -67,6 +74,8 @@
</table> </table>
{% crispy form %} {% crispy form %}
<div id='form-errors'>{{ form_errors }}</div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -491,6 +491,7 @@ class PurchaseOrderReceive(AjaxUpdateView):
ctx = { ctx = {
'order': self.order, 'order': self.order,
'lines': self.lines, 'lines': self.lines,
'stock_locations': StockLocation.objects.all(),
} }
return ctx return ctx
@ -543,6 +544,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'])
errors = False
self.lines = [] self.lines = []
self.destination = None self.destination = None
@ -557,12 +559,6 @@ class PurchaseOrderReceive(AjaxUpdateView):
except (StockLocation.DoesNotExist, ValueError): except (StockLocation.DoesNotExist, ValueError):
pass pass
errors = False
if self.destination is None:
errors = True
msg = _("No destination set")
# Extract information on all submitted line items # Extract information on all submitted line items
for item in request.POST: for item in request.POST:
if item.startswith('line-'): if item.startswith('line-'):
@ -587,6 +583,21 @@ class PurchaseOrderReceive(AjaxUpdateView):
else: else:
line.status_code = StockStatus.OK line.status_code = StockStatus.OK
# Check the destination field
line.destination = None
if self.destination:
# If global destination is set, overwrite line value
line.destination = self.destination
else:
destination_key = f'destination-{pk}'
destination = request.POST.get(destination_key, None)
if destination:
try:
line.destination = StockLocation.objects.get(pk=destination)
except (StockLocation.DoesNotExist, ValueError):
pass
# Check that line matches the order # Check that line matches the order
if not line.order == self.order: if not line.order == self.order:
# TODO - Display a non-field error? # TODO - Display a non-field error?
@ -645,7 +656,7 @@ class PurchaseOrderReceive(AjaxUpdateView):
self.order.receive_line_item( self.order.receive_line_item(
line, line,
self.destination, line.destination,
line.receive_quantity, line.receive_quantity,
self.request.user, self.request.user,
status=line.status_code, status=line.status_code,