From 17e91493eadcd6e80b5f3db963518434f9ff12b0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 13 Sep 2019 15:32:52 +1000 Subject: [PATCH] Bug fix for order-parts form - Check for parts already existing in PO must filter by the purchase order ID in addition to the part ID --- InvenTree/order/models.py | 4 ++-- InvenTree/order/views.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 9408247fd6..306b748a79 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -202,8 +202,8 @@ class PurchaseOrder(Order): raise ValidationError({'supplier': _("Part supplier must match PO supplier")}) if group: - # Check if there is already a matching line item - matches = PurchaseOrderLineItem.objects.filter(part=supplier_part) + # Check if there is already a matching line item (for this PO) + matches = self.lines.filter(part=supplier_part) if matches.count() > 0: line = matches.first() diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 5b7aca5cdc..25d0dddb52 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -5,6 +5,7 @@ Django views for interacting with Order app # -*- coding: utf-8 -*- from __future__ import unicode_literals +from django.db import transaction from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext as _ from django.views.generic import DetailView, ListView @@ -557,6 +558,7 @@ class OrderParts(AjaxView): return self.renderJsonResponse(self.request, data=data) + @transaction.atomic def order_items(self): """ Add the selected items to the purchase orders. """