From 8f40b5712116b49dfe4b28d58d1e94cb9043638f Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 27 Apr 2021 16:32:43 +0200 Subject: [PATCH] improvements after code-review by @eeintech --- InvenTree/order/models.py | 5 +++-- InvenTree/order/views.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 11d125b789..2e4ceb54e7 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -257,8 +257,9 @@ class PurchaseOrder(Order): # update quantity and price quantity_new = line.quantity + quantity line.quantity = quantity_new - if line.purchase_price: - line.purchase_price = supplier_part.get_price(quantity_new) / quantity_new + supplier_price = supplier_part.get_price(quantity_new) + if line.purchase_price and supplier_price: + line.purchase_price = supplier_price / quantity_new line.save() return diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index fc7f376206..c62a3816d5 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -996,7 +996,14 @@ 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 + + # set supplier-price + if supplier_part: + supplier_price = supplier_part.get_price(quantity) + if supplier_price: + part.purchase_price = supplier_price / quantity + if not hasattr(part, 'purchase_price'): + part.purchase_price = None self.parts.append(part) @@ -1098,7 +1105,7 @@ class OrderParts(AjaxView): continue # get purchase price - purchase_price = item.purchase_price if item.purchase_price else None + purchase_price = item.purchase_price order.add_line_item(supplier_part, quantity, purchase_price=purchase_price)