mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge branch 'inventree:master' into fr-1421-sso
This commit is contained in:
commit
848a72604e
@ -662,6 +662,18 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# 2021-10-08
|
||||||
|
# This setting exists as an interim solution for https://github.com/inventree/InvenTree/issues/2042
|
||||||
|
# The BOM API can be extremely slow when calculating pricing information "on the fly"
|
||||||
|
# A future solution will solve this properly,
|
||||||
|
# but as an interim step we provide a global to enable / disable BOM pricing
|
||||||
|
'PART_SHOW_PRICE_IN_BOM': {
|
||||||
|
'name': _('Show Price in BOM'),
|
||||||
|
'description': _('Include pricing information in BOM tables'),
|
||||||
|
'default': True,
|
||||||
|
'validator': bool,
|
||||||
|
},
|
||||||
|
|
||||||
'PART_SHOW_RELATED': {
|
'PART_SHOW_RELATED': {
|
||||||
'name': _('Show related parts'),
|
'name': _('Show related parts'),
|
||||||
'description': _('Display related parts for a part'),
|
'description': _('Display related parts for a part'),
|
||||||
|
@ -1100,6 +1100,12 @@ class BomList(generics.ListCreateAPIView):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Include or exclude pricing information in the serialized data
|
||||||
|
kwargs['include_pricing'] = str2bool(self.request.GET.get('include_pricing', True))
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Ensure the request context is passed through!
|
# Ensure the request context is passed through!
|
||||||
kwargs['context'] = self.get_serializer_context()
|
kwargs['context'] = self.get_serializer_context()
|
||||||
|
|
||||||
@ -1141,6 +1147,18 @@ class BomList(generics.ListCreateAPIView):
|
|||||||
except (ValueError, Part.DoesNotExist):
|
except (ValueError, Part.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
include_pricing = str2bool(params.get('include_pricing', True))
|
||||||
|
|
||||||
|
if include_pricing:
|
||||||
|
queryset = self.annotate_pricing(queryset)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
def annotate_pricing(self, queryset):
|
||||||
|
"""
|
||||||
|
Add part pricing information to the queryset
|
||||||
|
"""
|
||||||
|
|
||||||
# Annotate with purchase prices
|
# Annotate with purchase prices
|
||||||
queryset = queryset.annotate(
|
queryset = queryset.annotate(
|
||||||
purchase_price_min=Min('sub_part__stock_items__purchase_price'),
|
purchase_price_min=Min('sub_part__stock_items__purchase_price'),
|
||||||
|
@ -419,6 +419,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
part_detail = kwargs.pop('part_detail', False)
|
part_detail = kwargs.pop('part_detail', False)
|
||||||
sub_part_detail = kwargs.pop('sub_part_detail', False)
|
sub_part_detail = kwargs.pop('sub_part_detail', False)
|
||||||
|
include_pricing = kwargs.pop('include_pricing', False)
|
||||||
|
|
||||||
super(BomItemSerializer, self).__init__(*args, **kwargs)
|
super(BomItemSerializer, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@ -428,6 +429,14 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
if sub_part_detail is not True:
|
if sub_part_detail is not True:
|
||||||
self.fields.pop('sub_part_detail')
|
self.fields.pop('sub_part_detail')
|
||||||
|
|
||||||
|
if not include_pricing:
|
||||||
|
# Remove all pricing related fields
|
||||||
|
self.fields.pop('price_range')
|
||||||
|
self.fields.pop('purchase_price_min')
|
||||||
|
self.fields.pop('purchase_price_max')
|
||||||
|
self.fields.pop('purchase_price_avg')
|
||||||
|
self.fields.pop('purchase_price_range')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def setup_eager_loading(queryset):
|
def setup_eager_loading(queryset):
|
||||||
queryset = queryset.prefetch_related('part')
|
queryset = queryset.prefetch_related('part')
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
{% include "InvenTree/settings/setting.html" with key="PART_ALLOW_DUPLICATE_IPN" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_ALLOW_DUPLICATE_IPN" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_ALLOW_EDIT_IPN" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_ALLOW_EDIT_IPN" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_PRICE_IN_FORMS" icon="fa-dollar-sign" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_PRICE_IN_FORMS" icon="fa-dollar-sign" %}
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_PRICE_IN_BOM" icon="fa-dollar-sign" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_RELATED" icon="fa-random" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_RELATED" icon="fa-random" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_CREATE_INITIAL" icon="fa-boxes" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_CREATE_INITIAL" icon="fa-boxes" %}
|
||||||
<tr><td colspan='5'></td></tr>
|
<tr><td colspan='5'></td></tr>
|
||||||
|
@ -148,6 +148,13 @@ function loadBomTable(table, options) {
|
|||||||
ordering: 'name',
|
ordering: 'name',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Do we show part pricing in the BOM table?
|
||||||
|
var show_pricing = global_settings.PART_SHOW_PRICE_IN_BOM;
|
||||||
|
|
||||||
|
if (!show_pricing) {
|
||||||
|
params.include_pricing = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.part_detail) {
|
if (options.part_detail) {
|
||||||
params.part_detail = true;
|
params.part_detail = true;
|
||||||
}
|
}
|
||||||
@ -282,6 +289,7 @@ function loadBomTable(table, options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (show_pricing) {
|
||||||
cols.push({
|
cols.push({
|
||||||
field: 'purchase_price_range',
|
field: 'purchase_price_range',
|
||||||
title: '{% trans "Purchase Price Range" %}',
|
title: '{% trans "Purchase Price Range" %}',
|
||||||
@ -308,6 +316,7 @@ function loadBomTable(table, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
cols.push({
|
cols.push({
|
||||||
field: 'optional',
|
field: 'optional',
|
||||||
|
Loading…
Reference in New Issue
Block a user