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.
This commit is contained in:
Matt Brown 2022-06-06 20:57:21 +12:00 committed by GitHub
parent e85d9aca52
commit 7b4d0605b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 9 deletions

View File

@ -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

View File

@ -75,7 +75,7 @@
{% endif %}
{% endif %}
{% if part.has_complete_bom_pricing == False %}
{% if not part.has_complete_bom_pricing %}
<tr>
<td colspan='3'>
<span class='warning-msg'><em>{% trans 'Note: BOM pricing is incomplete for this part' %}</em></span>

View File

@ -83,7 +83,7 @@
{% endif %}
{% endif %}
{% if part.has_complete_bom_pricing == False %}
{% if not part.has_complete_bom_pricing %}
<tr>
<td colspan='4'>
<span class='warning-msg'><em>{% trans 'Note: BOM pricing is incomplete for this part' %}</em></span>