diff --git a/InvenTree/InvenTree/admin.py b/InvenTree/InvenTree/admin.py index dc377bcfee..1c79d07cc1 100644 --- a/InvenTree/InvenTree/admin.py +++ b/InvenTree/InvenTree/admin.py @@ -1,6 +1,7 @@ """Admin classes.""" from django.contrib import admin +from django.db.models.fields import CharField from django.http.request import HttpRequest from djmoney.contrib.exchange.admin import RateAdmin @@ -84,7 +85,17 @@ class InvenTreeResource(ModelResource): return [f for f in fields if f.column_name not in fields_to_exclude] def before_import_row(self, row, row_number=None, **kwargs): - """Run custom code before importing each row.""" + """Run custom code before importing each row. + + - Convert any null fields to empty strings, for fields which do not support null values + """ + # We can automatically determine which fields might need such a conversion + for field in self.Meta.model._meta.fields: + if isinstance(field, CharField): + if field.blank and not field.null: + if field.name not in self.CONVERT_NULL_FIELDS: + self.CONVERT_NULL_FIELDS.append(field.name) + for field in self.CONVERT_NULL_FIELDS: if field in row and row[field] is None: row[field] = '' diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 4ef031e965..be06bb05c7 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -162,7 +162,9 @@ STATICFILES_I18_TRG = STATICFILES_I18_TRG.joinpath(STATICFILES_I18_PREFIX) # Append directory for compiled react files if debug server is running if DEBUG and 'collectstatic' not in sys.argv: - STATICFILES_DIRS.append(BASE_DIR.joinpath('web', 'static')) + web_dir = BASE_DIR.joinpath('..', 'web', 'static').absolute() + if web_dir.exists(): + STATICFILES_DIRS.append(web_dir) STATFILES_I18_PROCESSORS = ['InvenTree.context.status_codes'] diff --git a/InvenTree/order/admin.py b/InvenTree/order/admin.py index c45e84c0fc..2345e8ca2a 100644 --- a/InvenTree/order/admin.py +++ b/InvenTree/order/admin.py @@ -220,7 +220,7 @@ class SalesOrderLineItemResource(PriceResourceMixin, InvenTreeResource): Ref: https://github.com/inventree/InvenTree/issues/2207 """ if item.sale_price: - return str(item.sale_price) + return item.sale_price.amount return '' diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 56c19ceafe..e224053f7f 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -1538,6 +1538,9 @@ class SalesOrderLineItem(OrderLineItem): def fulfilled_quantity(self): """Return the total stock quantity fulfilled against this line item.""" + if not self.pk: + return 0 + query = self.order.stock_items.filter(part=self.part).aggregate( fulfilled=Coalesce(Sum('quantity'), Decimal(0)) ) @@ -1549,6 +1552,9 @@ class SalesOrderLineItem(OrderLineItem): This is a summation of the quantity of each attached StockItem """ + if not self.pk: + return 0 + query = self.allocations.aggregate( allocated=Coalesce(Sum('quantity'), Decimal(0)) )