diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index fe336e2aba..884adefe2f 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -223,7 +223,7 @@ class PurchaseOrder(Order): return reverse('po-detail', kwargs={'pk': self.id}) @transaction.atomic - def add_line_item(self, supplier_part, quantity, group=True, reference=''): + def add_line_item(self, supplier_part, quantity, group=True, reference='', purchase_price=None): """ Add a new line item to this purchase order. This function will check that: @@ -254,7 +254,11 @@ class PurchaseOrder(Order): if matches.count() > 0: line = matches.first() - line.quantity += quantity + # update quantity and price + quantity_new = line.quantity + quantity + line.quantity = quantity_new + if purchase_price: + line.purchase_price = supplier_part.get_price(quantity_new) / quantity_new line.save() return @@ -263,7 +267,9 @@ class PurchaseOrder(Order): order=self, part=supplier_part, quantity=quantity, - reference=reference) + reference=reference, + purchase_price=purchase_price, + ) line.save() diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index f9ec52254f..fc7f376206 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -996,6 +996,7 @@ class OrderParts(AjaxView): part.order_supplier = supplier_part.id if supplier_part else None part.order_quantity = quantity + part.purchase_price = supplier_part.get_price(quantity) / quantity if supplier_part else None self.parts.append(part) @@ -1096,7 +1097,10 @@ class OrderParts(AjaxView): sp=item.order_supplier)) continue - order.add_line_item(supplier_part, quantity) + # get purchase price + purchase_price = item.purchase_price if item.purchase_price else None + + order.add_line_item(supplier_part, quantity, purchase_price=purchase_price) class POLineItemCreate(AjaxCreateView):