improvements after code-review by @eeintech

This commit is contained in:
Matthias 2021-04-27 16:32:43 +02:00
parent f4502aecca
commit 8f40b57121
2 changed files with 12 additions and 4 deletions

View File

@ -257,8 +257,9 @@ class PurchaseOrder(Order):
# update quantity and price # update quantity and price
quantity_new = line.quantity + quantity quantity_new = line.quantity + quantity
line.quantity = quantity_new line.quantity = quantity_new
if line.purchase_price: supplier_price = supplier_part.get_price(quantity_new)
line.purchase_price = supplier_part.get_price(quantity_new) / quantity_new if line.purchase_price and supplier_price:
line.purchase_price = supplier_price / quantity_new
line.save() line.save()
return return

View File

@ -996,7 +996,14 @@ class OrderParts(AjaxView):
part.order_supplier = supplier_part.id if supplier_part else None part.order_supplier = supplier_part.id if supplier_part else None
part.order_quantity = quantity 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) self.parts.append(part)
@ -1098,7 +1105,7 @@ class OrderParts(AjaxView):
continue continue
# get purchase price # 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) order.add_line_item(supplier_part, quantity, purchase_price=purchase_price)