mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 04:25:42 +00:00
Few more fixes
This commit is contained in:
@ -5,6 +5,8 @@ Django forms for interacting with common objects
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from decimal import Decimal, InvalidOperation
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
@ -117,6 +119,21 @@ class MatchItem(forms.Form):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def clean(number):
|
||||
""" Clean-up decimal value """
|
||||
|
||||
# Check if empty
|
||||
if not number:
|
||||
return number
|
||||
|
||||
# Check if decimal type
|
||||
try:
|
||||
clean_number = Decimal(number)
|
||||
except InvalidOperation:
|
||||
clean_number = number
|
||||
|
||||
return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize()
|
||||
|
||||
# Setup FileManager
|
||||
file_manager.setup()
|
||||
|
||||
@ -143,7 +160,7 @@ class MatchItem(forms.Form):
|
||||
'type': 'number',
|
||||
'min': '0',
|
||||
'step': 'any',
|
||||
'value': row['quantity'],
|
||||
'value': clean(row['quantity']),
|
||||
})
|
||||
)
|
||||
# else:
|
||||
@ -187,7 +204,7 @@ class MatchItem(forms.Form):
|
||||
decimal_places=5,
|
||||
max_digits=19,
|
||||
required=False,
|
||||
default_amount=value,
|
||||
default_amount=clean(value),
|
||||
)
|
||||
# else:
|
||||
# self.fields[field_name] = forms.TextInput()
|
||||
|
@ -205,10 +205,9 @@ class FileManagementFormView(MultiStepFormView):
|
||||
stored_data = self.storage.get_step_data(self.steps.current)
|
||||
if stored_data:
|
||||
self.get_form_table_data(stored_data)
|
||||
else:
|
||||
if form.is_valid() or self.steps.current == 'items':
|
||||
# Set form table data
|
||||
self.set_form_table_data(form=form)
|
||||
elif self.steps.current == 'items':
|
||||
# Set form table data
|
||||
self.set_form_table_data(form=form)
|
||||
|
||||
# Update context
|
||||
context.update({'rows': self.rows})
|
||||
@ -357,15 +356,11 @@ class FileManagementFormView(MultiStepFormView):
|
||||
# Re-construct the row data
|
||||
self.rows = []
|
||||
|
||||
# if self.column_names:
|
||||
# rows_shown = []
|
||||
|
||||
# Update the row data
|
||||
for row_idx in sorted(self.row_data.keys()):
|
||||
row_data = self.row_data[row_idx]
|
||||
for row_idx, row_key in enumerate(sorted(self.row_data.keys())):
|
||||
row_data = self.row_data[row_key]
|
||||
|
||||
data = []
|
||||
# show_data = []
|
||||
|
||||
for idx, item in row_data.items():
|
||||
column_data = {
|
||||
@ -379,8 +374,6 @@ class FileManagementFormView(MultiStepFormView):
|
||||
'column': column_data,
|
||||
}
|
||||
data.append(cell_data)
|
||||
# if not self.column_names or column_data.get('name', '') in self.column_names:
|
||||
# show_data.append(cell_data)
|
||||
|
||||
row = {
|
||||
'index': row_idx,
|
||||
@ -388,14 +381,6 @@ class FileManagementFormView(MultiStepFormView):
|
||||
'errors': {},
|
||||
}
|
||||
self.rows.append(row)
|
||||
|
||||
# if self.column_names:
|
||||
# current_row = row
|
||||
# current_row['data'] = show_data
|
||||
# rows_shown.append(current_row)
|
||||
|
||||
# if self.column_names and self.get_step_index() == 3:
|
||||
# self.rows = rows_shown
|
||||
|
||||
# In the item selection step: update row data to contain fields
|
||||
if form and self.steps.current == 'items':
|
||||
|
Reference in New Issue
Block a user