From e7d78db87be6546d5a96f07de51261a32f376ba2 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 5 Oct 2021 10:53:11 +1100 Subject: [PATCH] Fixes for unit tests --- InvenTree/part/models.py | 8 ++++++-- InvenTree/part/test_api.py | 2 +- InvenTree/part/test_bom_item.py | 10 ++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 18a53f5a79..8c43a623a0 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -4,6 +4,7 @@ Part database model definitions # -*- coding: utf-8 -*- from __future__ import unicode_literals +import decimal import os import logging @@ -1530,10 +1531,13 @@ class Part(MPTTModel): for item in self.get_bom_items().all().select_related('sub_part'): if item.sub_part.pk == self.pk: - print("Warning: Item contains itself in BOM") + logger.warning(f"WARNING: BomItem ID {item.pk} contains itself in BOM") continue - prices = item.sub_part.get_price_range(quantity * item.quantity, internal=internal, purchase=purchase) + q = decimal.Decimal(quantity) + i = decimal.Decimal(item.quantity) + + prices = item.sub_part.get_price_range(q * i, internal=internal, purchase=purchase) if prices is None: continue diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index 660b573e33..ac9d6bdf45 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -277,7 +277,7 @@ class PartAPITest(InvenTreeAPITestCase): """ There should be 4 BomItem objects in the database """ url = reverse('api-bom-list') response = self.client.get(url, format='json') - self.assertEqual(len(response.data), 4) + self.assertEqual(len(response.data), 5) def test_get_bom_detail(self): # Get the detail for a single BomItem diff --git a/InvenTree/part/test_bom_item.py b/InvenTree/part/test_bom_item.py index 66897b28fc..be9740d128 100644 --- a/InvenTree/part/test_bom_item.py +++ b/InvenTree/part/test_bom_item.py @@ -120,7 +120,13 @@ class BomItemTest(TestCase): def test_pricing(self): self.bob.get_price(1) - self.assertEqual(self.bob.get_bom_price_range(1, internal=True), (Decimal(84.5), Decimal(89.5))) + self.assertEqual( + self.bob.get_bom_price_range(1, internal=True), + (Decimal(29.5), Decimal(89.5)) + ) # remove internal price for R_2K2_0805 self.r1.internal_price_breaks.delete() - self.assertEqual(self.bob.get_bom_price_range(1, internal=True), (Decimal(82.5), Decimal(87.5))) + self.assertEqual( + self.bob.get_bom_price_range(1, internal=True), + (Decimal(27.5), Decimal(87.5)) + )