2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 03:30:54 +00:00

Bug fix for purchase order pricing (#4373)

* Account for pack size when calculating purchase_price for received line items

* Clearer display of "unit pricing" when part has units

* Add data migration to fix historical pricing bugs

* Remove debug statement
This commit is contained in:
Oliver
2023-02-20 17:22:47 +11:00
committed by GitHub
parent 9964687cf3
commit 95ecd0cd32
5 changed files with 113 additions and 4 deletions

View File

@ -501,6 +501,11 @@ class PurchaseOrder(Order):
# Take the 'pack_size' of the SupplierPart into account
pack_quantity = Decimal(quantity) * Decimal(line.part.pack_size)
if line.purchase_price:
unit_purchase_price = line.purchase_price / line.part.pack_size
else:
unit_purchase_price = None
# Determine if we should individually serialize the items, or not
if type(serials) is list and len(serials) > 0:
serialize = True
@ -519,7 +524,7 @@ class PurchaseOrder(Order):
status=status,
batch=batch_code,
serial=sn,
purchase_price=line.purchase_price,
purchase_price=unit_purchase_price,
barcode_hash=barcode_hash
)

View File

@ -8,12 +8,14 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.test import TestCase
from djmoney.money import Money
import common.models
import order.tasks
from company.models import Company, SupplierPart
from InvenTree.status_codes import PurchaseOrderStatus
from part.models import Part
from stock.models import StockLocation
from stock.models import StockItem, StockLocation
from users.models import Owner
from .models import PurchaseOrder, PurchaseOrderLineItem
@ -255,7 +257,8 @@ class OrderTest(TestCase):
line_1 = PurchaseOrderLineItem.objects.create(
order=po,
part=sp_1,
quantity=3
quantity=3,
purchase_price=Money(1000, 'USD'), # "Unit price" should be $100USD
)
# 13 x 0.1 = 1.3
@ -263,6 +266,7 @@ class OrderTest(TestCase):
order=po,
part=sp_2,
quantity=13,
purchase_price=Money(10, 'USD'), # "Unit price" should be $100USD
)
po.place_order()
@ -299,6 +303,23 @@ class OrderTest(TestCase):
round(in_stock + Decimal(10.5), 1)
)
# Check that the unit purchase price value has been updated correctly
si = StockItem.objects.filter(supplier_part=sp_1)
self.assertEqual(si.count(), 1)
# Ensure that received quantity and unit purchase price data are correct
si = si.first()
self.assertEqual(si.quantity, 10)
self.assertEqual(si.purchase_price, Money(100, 'USD'))
si = StockItem.objects.filter(supplier_part=sp_2)
self.assertEqual(si.count(), 1)
# Ensure that received quantity and unit purchase price data are correct
si = si.first()
self.assertEqual(si.quantity, 0.5)
self.assertEqual(si.purchase_price, Money(100, 'USD'))
def test_overdue_notification(self):
"""Test overdue purchase order notification