From 7b4d0605b8edb31c63895ae9bd902d0e7121b0d0 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Mon, 6 Jun 2022 20:57:21 +1200 Subject: [PATCH] Fix has_complete_bom_pricing logic errors (#3140) * Fix has_complete_bom_pricing logic errors There are two logic errors in this property method that have been present since c6fd228. 1) The get_setting method needs to be called on the InventTreeSetting class in common.models, not on the module itself. 2) You cannot call a property method directly passing an argument in Python, so the call to has_pricing_info is invalid and always fails. Given that has_complete_bom_pricing is/was the only user of that property anyway, fix this by just internalising the logic from that property in the method directly. * style nit: use implicit checking for bools has_complete_bom_pricing is a boolean property, the preferred pythonic style for if comparisons of this type is not to complete directly to == False, etc and rely on the implicit truthiness of the type. --- InvenTree/part/models.py | 9 ++------- InvenTree/part/templates/part/part_pricing.html | 2 +- InvenTree/part/templates/part/prices.html | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index ebe9f882d6..c900ffd1e7 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1529,17 +1529,12 @@ class Part(MetadataMixin, MPTTModel): """Return the number of supplier parts available for this part.""" return self.supplier_parts.count() - @property - def has_pricing_info(self, internal=False): - """Return true if there is pricing information for this part.""" - return self.get_price_range(internal=internal) is not None - @property def has_complete_bom_pricing(self): """Return true if there is pricing information for each item in the BOM.""" - use_internal = common.models.get_setting('PART_BOM_USE_INTERNAL_PRICE', False) + use_internal = common.models.InvenTreeSetting.get_setting('PART_BOM_USE_INTERNAL_PRICE', False) for item in self.get_bom_items().all().select_related('sub_part'): - if not item.sub_part.has_pricing_info(use_internal): + if item.sub_part.get_price_range(internal=use_internal) is None: return False return True diff --git a/InvenTree/part/templates/part/part_pricing.html b/InvenTree/part/templates/part/part_pricing.html index 9ec80882af..f61df368d4 100644 --- a/InvenTree/part/templates/part/part_pricing.html +++ b/InvenTree/part/templates/part/part_pricing.html @@ -75,7 +75,7 @@ {% endif %} {% endif %} - {% if part.has_complete_bom_pricing == False %} + {% if not part.has_complete_bom_pricing %} {% trans 'Note: BOM pricing is incomplete for this part' %} diff --git a/InvenTree/part/templates/part/prices.html b/InvenTree/part/templates/part/prices.html index 6deaa3d51c..13761f4ca1 100644 --- a/InvenTree/part/templates/part/prices.html +++ b/InvenTree/part/templates/part/prices.html @@ -83,7 +83,7 @@ {% endif %} {% endif %} - {% if part.has_complete_bom_pricing == False %} + {% if not part.has_complete_bom_pricing %} {% trans 'Note: BOM pricing is incomplete for this part' %}