mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-20 05:46:34 +00:00
Merge branch 'master' of github.com:inventree/InvenTree into part_main_details
This commit is contained in:
@ -159,7 +159,7 @@ class CategoryDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
queryset = PartCategory.objects.all()
|
||||
|
||||
|
||||
class CategoryParameters(generics.ListAPIView):
|
||||
class CategoryParameterList(generics.ListAPIView):
|
||||
""" API endpoint for accessing a list of PartCategoryParameterTemplate objects.
|
||||
|
||||
- GET: Return a list of PartCategoryParameterTemplate objects
|
||||
@ -176,30 +176,27 @@ class CategoryParameters(generics.ListAPIView):
|
||||
- Allow traversing all parent categories
|
||||
"""
|
||||
|
||||
try:
|
||||
cat_id = int(self.kwargs.get('pk', None))
|
||||
except TypeError:
|
||||
cat_id = None
|
||||
fetch_parent = str2bool(self.request.query_params.get('fetch_parent', 'true'))
|
||||
|
||||
queryset = super().get_queryset()
|
||||
|
||||
if isinstance(cat_id, int):
|
||||
params = self.request.query_params
|
||||
|
||||
category = params.get('category', None)
|
||||
|
||||
if category is not None:
|
||||
try:
|
||||
category = PartCategory.objects.get(pk=cat_id)
|
||||
except PartCategory.DoesNotExist:
|
||||
# Return empty queryset
|
||||
return PartCategoryParameterTemplate.objects.none()
|
||||
|
||||
category = PartCategory.objects.get(pk=category)
|
||||
|
||||
category_list = [cat_id]
|
||||
fetch_parent = str2bool(params.get('fetch_parent', True))
|
||||
|
||||
if fetch_parent:
|
||||
parent_categories = category.get_ancestors()
|
||||
for parent in parent_categories:
|
||||
category_list.append(parent.pk)
|
||||
if fetch_parent:
|
||||
parents = category.get_ancestors(include_self=True)
|
||||
queryset = queryset.filter(category__in=[cat.pk for cat in parents])
|
||||
else:
|
||||
queryset = queryset.filter(category=category)
|
||||
|
||||
queryset = queryset.filter(category__in=category_list)
|
||||
except (ValueError, PartCategory.DoesNotExist):
|
||||
pass
|
||||
|
||||
return queryset
|
||||
|
||||
@ -995,8 +992,9 @@ class BomList(generics.ListCreateAPIView):
|
||||
|
||||
# Get values for currencies
|
||||
currencies = queryset.annotate(
|
||||
purchase_price=F('sub_part__stock_items__purchase_price'),
|
||||
purchase_price_currency=F('sub_part__stock_items__purchase_price_currency'),
|
||||
).values('pk', 'sub_part', 'purchase_price_currency')
|
||||
).values('pk', 'sub_part', 'purchase_price', 'purchase_price_currency')
|
||||
|
||||
def convert_price(price, currency, decimal_places=4):
|
||||
""" Convert price field, returns Money field """
|
||||
@ -1032,7 +1030,7 @@ class BomList(generics.ListCreateAPIView):
|
||||
# Find associated currency (select first found)
|
||||
purchase_price_currency = None
|
||||
for currency_item in currencies:
|
||||
if currency_item['pk'] == bom_item.pk and currency_item['sub_part'] == bom_item.sub_part.pk:
|
||||
if currency_item['pk'] == bom_item.pk and currency_item['sub_part'] == bom_item.sub_part.pk and currency_item['purchase_price']:
|
||||
purchase_price_currency = currency_item['purchase_price_currency']
|
||||
break
|
||||
# Convert prices
|
||||
@ -1093,7 +1091,8 @@ part_api_urls = [
|
||||
|
||||
# Base URL for PartCategory API endpoints
|
||||
url(r'^category/', include([
|
||||
url(r'^(?P<pk>\d+)/parameters/?', CategoryParameters.as_view(), name='api-part-category-parameters'),
|
||||
url(r'^parameters/', CategoryParameterList.as_view(), name='api-part-category-parameter-list'),
|
||||
|
||||
url(r'^(?P<pk>\d+)/?', CategoryDetail.as_view(), name='api-part-category-detail'),
|
||||
url(r'^$', CategoryList.as_view(), name='api-part-category-list'),
|
||||
])),
|
||||
|
@ -526,11 +526,14 @@ class CategoryParameterTemplateSerializer(InvenTreeModelSerializer):
|
||||
parameter_template = PartParameterTemplateSerializer(many=False,
|
||||
read_only=True)
|
||||
|
||||
category_detail = CategorySerializer(source='category', many=False, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = PartCategoryParameterTemplate
|
||||
fields = [
|
||||
'pk',
|
||||
'category',
|
||||
'category_detail',
|
||||
'parameter_template',
|
||||
'default_value',
|
||||
]
|
||||
|
@ -416,7 +416,7 @@
|
||||
});
|
||||
|
||||
// Wait for *all* the requests to complete
|
||||
$.when.apply($, requests).then(function() {
|
||||
$.when.apply($, requests).done(function() {
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
@ -832,7 +832,7 @@
|
||||
requests.push(inventreeDelete(url));
|
||||
});
|
||||
|
||||
$.when.apply($, requests).then(function() {
|
||||
$.when.apply($, requests).done(function() {
|
||||
reloadSupplierPartTable();
|
||||
});
|
||||
}
|
||||
|
@ -422,17 +422,16 @@
|
||||
|
||||
{% if roles.part.change %}
|
||||
|
||||
{% settings_value "INVENTREE_DOWNLOAD_FROM_URL" as allow_download %}
|
||||
{% if allow_download %}
|
||||
$("#part-image-url").click(function() {
|
||||
launchModalForm(
|
||||
'{% url "part-image-download" part.id %}',
|
||||
{
|
||||
reload: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
{% endif %}
|
||||
if (global_settings.INVENTREE_DOWNLOAD_FROM_URL) {
|
||||
$("#part-image-url").click(function() {
|
||||
launchModalForm(
|
||||
'{% url "part-image-download" part.id %}',
|
||||
{
|
||||
reload: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
$("#part-image-select").click(function() {
|
||||
launchModalForm("{% url 'part-image-select' part.id %}",
|
||||
|
@ -207,6 +207,24 @@ def settings_value(key, *args, **kwargs):
|
||||
return InvenTreeSetting.get_setting(key)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def user_settings(user, *args, **kwargs):
|
||||
"""
|
||||
Return all USER settings as a key:value dict
|
||||
"""
|
||||
|
||||
return InvenTreeUserSetting.allValues(user=user)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def global_settings(*args, **kwargs):
|
||||
"""
|
||||
Return all GLOBAL InvenTree settings as a key:value dict
|
||||
"""
|
||||
|
||||
return InvenTreeSetting.allValues()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def get_color_theme_css(username):
|
||||
try:
|
||||
@ -226,6 +244,23 @@ def get_color_theme_css(username):
|
||||
return inventree_css_static_url
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def get_available_themes(*args, **kwargs):
|
||||
"""
|
||||
Return the available theme choices
|
||||
"""
|
||||
|
||||
themes = []
|
||||
|
||||
for key, name in ColorTheme.get_color_themes_choices():
|
||||
themes.append({
|
||||
'key': key,
|
||||
'name': name
|
||||
})
|
||||
|
||||
return themes
|
||||
|
||||
|
||||
@register.filter
|
||||
def keyvalue(dict, key):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user