mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Import Fix (#6274)
* Fix check for static dir * Fix export price field for SalesOrderLineItem * Automatically detect which non-nullable fields need conversion * Fix bug during import - fulfilled_quantity and allocated_quantity must have a pk - Cannot work before imported!
This commit is contained in:
parent
1d3a23ca4e
commit
89e458bcba
@ -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] = ''
|
||||
|
@ -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']
|
||||
|
||||
|
@ -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 ''
|
||||
|
||||
|
||||
|
@ -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))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user