Fixes for unit tests

This commit is contained in:
Oliver 2021-10-05 10:53:11 +11:00
parent 563deb5ffa
commit e7d78db87b
3 changed files with 15 additions and 5 deletions

View File

@ -4,6 +4,7 @@ Part database model definitions
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import decimal
import os import os
import logging import logging
@ -1530,10 +1531,13 @@ class Part(MPTTModel):
for item in self.get_bom_items().all().select_related('sub_part'): for item in self.get_bom_items().all().select_related('sub_part'):
if item.sub_part.pk == self.pk: 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 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: if prices is None:
continue continue

View File

@ -277,7 +277,7 @@ class PartAPITest(InvenTreeAPITestCase):
""" There should be 4 BomItem objects in the database """ """ There should be 4 BomItem objects in the database """
url = reverse('api-bom-list') url = reverse('api-bom-list')
response = self.client.get(url, format='json') 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): def test_get_bom_detail(self):
# Get the detail for a single BomItem # Get the detail for a single BomItem

View File

@ -120,7 +120,13 @@ class BomItemTest(TestCase):
def test_pricing(self): def test_pricing(self):
self.bob.get_price(1) 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 # remove internal price for R_2K2_0805
self.r1.internal_price_breaks.delete() 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))
)