Merge pull request #1490 from SchrodingersGat/django-3.2

Update to django 3.2
This commit is contained in:
Oliver 2021-04-20 11:25:25 +10:00 committed by GitHub
commit 21708dabaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 12 deletions

View File

@ -52,6 +52,9 @@ def get_setting(environment_var, backup_val, default_value=None):
# Determine if we are running in "test" mode e.g. "manage.py test" # Determine if we are running in "test" mode e.g. "manage.py test"
TESTING = 'test' in sys.argv TESTING = 'test' in sys.argv
# New requirement for django 3.2+
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

View File

@ -807,7 +807,13 @@ class Build(MPTTModel):
allocations = self.allocatedItems(part, output) allocations = self.allocatedItems(part, output)
allocated = allocations.aggregate(q=Coalesce(Sum('quantity'), 0)) allocated = allocations.aggregate(
q=Coalesce(
Sum('quantity'),
0,
output_field=models.DecimalField(),
)
)
return allocated['q'] return allocated['q']

View File

@ -1163,7 +1163,16 @@ class Part(MPTTModel):
Return the total amount of this part allocated to build orders Return the total amount of this part allocated to build orders
""" """
query = self.build_order_allocations().aggregate(total=Coalesce(Sum('quantity'), 0)) query = self.build_order_allocations().aggregate(
total=Coalesce(
Sum(
'quantity',
output_field=models.DecimalField()
),
0,
output_field=models.DecimalField(),
)
)
return query['total'] return query['total']
@ -1179,7 +1188,16 @@ class Part(MPTTModel):
Return the tutal quantity of this part allocated to sales orders Return the tutal quantity of this part allocated to sales orders
""" """
query = self.sales_order_allocations().aggregate(total=Coalesce(Sum('quantity'), 0)) query = self.sales_order_allocations().aggregate(
total=Coalesce(
Sum(
'quantity',
output_field=models.DecimalField(),
),
0,
output_field=models.DecimalField(),
)
)
return query['total'] return query['total']
@ -1189,10 +1207,12 @@ class Part(MPTTModel):
against both build orders and sales orders. against both build orders and sales orders.
""" """
return sum([ return sum(
self.build_order_allocation_count(), [
self.sales_order_allocation_count(), self.build_order_allocation_count(),
]) self.sales_order_allocation_count(),
],
)
def stock_entries(self, include_variants=True, in_stock=None): def stock_entries(self, include_variants=True, in_stock=None):
""" Return all stock entries for this Part. """ Return all stock entries for this Part.

View File

@ -4,6 +4,7 @@ JSON serializers for Part app
import imghdr import imghdr
from decimal import Decimal from decimal import Decimal
from django.db import models
from django.db.models import Q from django.db.models import Q
from django.db.models.functions import Coalesce from django.db.models.functions import Coalesce
from InvenTree.serializers import (InvenTreeAttachmentSerializerField, from InvenTree.serializers import (InvenTreeAttachmentSerializerField,
@ -208,7 +209,8 @@ class PartSerializer(InvenTreeModelSerializer):
queryset = queryset.annotate( queryset = queryset.annotate(
in_stock=Coalesce( in_stock=Coalesce(
SubquerySum('stock_items__quantity', filter=StockItem.IN_STOCK_FILTER), SubquerySum('stock_items__quantity', filter=StockItem.IN_STOCK_FILTER),
Decimal(0) Decimal(0),
output_field=models.DecimalField(),
), ),
) )
@ -227,6 +229,7 @@ class PartSerializer(InvenTreeModelSerializer):
building=Coalesce( building=Coalesce(
SubquerySum('builds__quantity', filter=build_filter), SubquerySum('builds__quantity', filter=build_filter),
Decimal(0), Decimal(0),
output_field=models.DecimalField(),
) )
) )
@ -240,9 +243,11 @@ class PartSerializer(InvenTreeModelSerializer):
ordering=Coalesce( ordering=Coalesce(
SubquerySum('supplier_parts__purchase_order_line_items__quantity', filter=order_filter), SubquerySum('supplier_parts__purchase_order_line_items__quantity', filter=order_filter),
Decimal(0), Decimal(0),
output_field=models.DecimalField(),
) - Coalesce( ) - Coalesce(
SubquerySum('supplier_parts__purchase_order_line_items__received', filter=order_filter), SubquerySum('supplier_parts__purchase_order_line_items__received', filter=order_filter),
Decimal(0), Decimal(0),
output_field=models.DecimalField(),
) )
) )
@ -251,6 +256,7 @@ class PartSerializer(InvenTreeModelSerializer):
suppliers=Coalesce( suppliers=Coalesce(
SubqueryCount('supplier_parts'), SubqueryCount('supplier_parts'),
Decimal(0), Decimal(0),
output_field=models.DecimalField(),
), ),
) )

View File

@ -57,6 +57,7 @@ class RuleSet(models.Model):
'auth_user', 'auth_user',
'auth_permission', 'auth_permission',
'authtoken_token', 'authtoken_token',
'authtoken_tokenproxy',
'users_ruleset', 'users_ruleset',
], ],
'part_category': [ 'part_category': [
@ -199,7 +200,8 @@ class RuleSet(models.Model):
if check_user_role(user, role, permission): if check_user_role(user, role, permission):
return True return True
print("failed permission check for", table, permission) # Print message instead of throwing an error
print("Failed permission check for", table, permission)
return False return False
@staticmethod @staticmethod

View File

@ -1,8 +1,8 @@
invoke>=1.4.0 # Invoke build tool invoke>=1.4.0 # Invoke build tool
wheel>=0.34.2 # Wheel wheel>=0.34.2 # Wheel
Django==3.1.8 # Django package Django==3.2 # Django package
pillow==8.1.1 # Image manipulation pillow==8.1.1 # Image manipulation
djangorestframework==3.11.2 # DRF framework djangorestframework==3.12.4 # DRF framework
django-dbbackup==3.3.0 # Database backup / restore functionality django-dbbackup==3.3.0 # Database backup / restore functionality
django-cors-headers==3.2.0 # CORS headers extension for DRF django-cors-headers==3.2.0 # CORS headers extension for DRF
django-filter==2.4.0 # Extended filtering options django-filter==2.4.0 # Extended filtering options
@ -13,7 +13,7 @@ django-markdownify==0.8.0 # Markdown rendering
coreapi==2.3.0 # API documentation coreapi==2.3.0 # API documentation
pygments==2.7.4 # Syntax highlighting pygments==2.7.4 # Syntax highlighting
tablib==0.13.0 # Import / export data files tablib==0.13.0 # Import / export data files
django-crispy-forms==1.8.1 # Form helpers django-crispy-forms==1.11.2 # Form helpers
django-import-export==2.0.0 # Data import / export for admin interface django-import-export==2.0.0 # Data import / export for admin interface
django-cleanup==5.1.0 # Manage deletion of old / unused uploaded files django-cleanup==5.1.0 # Manage deletion of old / unused uploaded files
flake8==3.8.3 # PEP checking flake8==3.8.3 # PEP checking