mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Few more fixes
This commit is contained in:
parent
10eb69caf9
commit
a093118856
@ -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':
|
||||
|
@ -65,7 +65,7 @@
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% for row in rows %}
|
||||
{% with forloop.counter0 as row_index %}
|
||||
{% with forloop.counter as row_index %}
|
||||
<tr>
|
||||
<td style='width: 32px;'>
|
||||
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ row_index }}' style='display: inline; float: left;' title='{% trans "Remove row" %}'>
|
||||
|
@ -28,7 +28,7 @@
|
||||
<th>{% trans "Select Supplier Part" %}</th>
|
||||
<th>{% trans "Quantity" %}</th>
|
||||
{% for col in columns %}
|
||||
{% if col.name != 'Quantity' %}
|
||||
{% if col.guess != 'Quantity' %}
|
||||
<th>
|
||||
<input type='hidden' name='col_name_{{ forloop.counter0 }}' value='{{ col.name }}'/>
|
||||
<input type='hidden' name='col_guess_{{ forloop.counter0 }}' value='{{ col.guess }}'/>
|
||||
@ -43,15 +43,16 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr></tr> {% comment %} Dummy row for javascript del_row method {% endcomment %}
|
||||
{% for row in rows %}
|
||||
<tr {% if row.errors %} style='background: #ffeaea;'{% endif %} part-select='#select_part_{{ row.index }}'>
|
||||
<td>
|
||||
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ forloop.counter0 }}' style='display: inline; float: right;' title='{% trans "Remove row" %}'>
|
||||
<span row_id='{{ forloop.counter }}' class='fas fa-trash-alt icon-red'></span>
|
||||
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ row.index }}' style='display: inline; float: right;' title='{% trans "Remove row" %}'>
|
||||
<span row_id='{{ row.index }}' class='fas fa-trash-alt icon-red'></span>
|
||||
</button>
|
||||
</td>
|
||||
<td>
|
||||
{{ row.index }}
|
||||
{% add row.index 1 %}
|
||||
</td>
|
||||
<td>
|
||||
{% for field in form.visible_fields %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user