mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +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 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from decimal import Decimal, InvalidOperation
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
@ -117,6 +119,21 @@ class MatchItem(forms.Form):
|
|||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
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
|
# Setup FileManager
|
||||||
file_manager.setup()
|
file_manager.setup()
|
||||||
|
|
||||||
@ -143,7 +160,7 @@ class MatchItem(forms.Form):
|
|||||||
'type': 'number',
|
'type': 'number',
|
||||||
'min': '0',
|
'min': '0',
|
||||||
'step': 'any',
|
'step': 'any',
|
||||||
'value': row['quantity'],
|
'value': clean(row['quantity']),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
# else:
|
# else:
|
||||||
@ -187,7 +204,7 @@ class MatchItem(forms.Form):
|
|||||||
decimal_places=5,
|
decimal_places=5,
|
||||||
max_digits=19,
|
max_digits=19,
|
||||||
required=False,
|
required=False,
|
||||||
default_amount=value,
|
default_amount=clean(value),
|
||||||
)
|
)
|
||||||
# else:
|
# else:
|
||||||
# self.fields[field_name] = forms.TextInput()
|
# self.fields[field_name] = forms.TextInput()
|
||||||
|
@ -205,8 +205,7 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
stored_data = self.storage.get_step_data(self.steps.current)
|
stored_data = self.storage.get_step_data(self.steps.current)
|
||||||
if stored_data:
|
if stored_data:
|
||||||
self.get_form_table_data(stored_data)
|
self.get_form_table_data(stored_data)
|
||||||
else:
|
elif self.steps.current == 'items':
|
||||||
if form.is_valid() or self.steps.current == 'items':
|
|
||||||
# Set form table data
|
# Set form table data
|
||||||
self.set_form_table_data(form=form)
|
self.set_form_table_data(form=form)
|
||||||
|
|
||||||
@ -357,15 +356,11 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
# Re-construct the row data
|
# Re-construct the row data
|
||||||
self.rows = []
|
self.rows = []
|
||||||
|
|
||||||
# if self.column_names:
|
|
||||||
# rows_shown = []
|
|
||||||
|
|
||||||
# Update the row data
|
# Update the row data
|
||||||
for row_idx in sorted(self.row_data.keys()):
|
for row_idx, row_key in enumerate(sorted(self.row_data.keys())):
|
||||||
row_data = self.row_data[row_idx]
|
row_data = self.row_data[row_key]
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
# show_data = []
|
|
||||||
|
|
||||||
for idx, item in row_data.items():
|
for idx, item in row_data.items():
|
||||||
column_data = {
|
column_data = {
|
||||||
@ -379,8 +374,6 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
'column': column_data,
|
'column': column_data,
|
||||||
}
|
}
|
||||||
data.append(cell_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 = {
|
row = {
|
||||||
'index': row_idx,
|
'index': row_idx,
|
||||||
@ -389,14 +382,6 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
}
|
}
|
||||||
self.rows.append(row)
|
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
|
# In the item selection step: update row data to contain fields
|
||||||
if form and self.steps.current == 'items':
|
if form and self.steps.current == 'items':
|
||||||
# Update row data
|
# Update row data
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% for row in rows %}
|
{% for row in rows %}
|
||||||
{% with forloop.counter0 as row_index %}
|
{% with forloop.counter as row_index %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style='width: 32px;'>
|
<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" %}'>
|
<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 "Select Supplier Part" %}</th>
|
||||||
<th>{% trans "Quantity" %}</th>
|
<th>{% trans "Quantity" %}</th>
|
||||||
{% for col in columns %}
|
{% for col in columns %}
|
||||||
{% if col.name != 'Quantity' %}
|
{% if col.guess != 'Quantity' %}
|
||||||
<th>
|
<th>
|
||||||
<input type='hidden' name='col_name_{{ forloop.counter0 }}' value='{{ col.name }}'/>
|
<input type='hidden' name='col_name_{{ forloop.counter0 }}' value='{{ col.name }}'/>
|
||||||
<input type='hidden' name='col_guess_{{ forloop.counter0 }}' value='{{ col.guess }}'/>
|
<input type='hidden' name='col_guess_{{ forloop.counter0 }}' value='{{ col.guess }}'/>
|
||||||
@ -43,15 +43,16 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr></tr> {% comment %} Dummy row for javascript del_row method {% endcomment %}
|
||||||
{% for row in rows %}
|
{% for row in rows %}
|
||||||
<tr {% if row.errors %} style='background: #ffeaea;'{% endif %} part-select='#select_part_{{ row.index }}'>
|
<tr {% if row.errors %} style='background: #ffeaea;'{% endif %} part-select='#select_part_{{ row.index }}'>
|
||||||
<td>
|
<td>
|
||||||
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ forloop.counter0 }}' style='display: inline; float: right;' title='{% trans "Remove row" %}'>
|
<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='{{ forloop.counter }}' class='fas fa-trash-alt icon-red'></span>
|
<span row_id='{{ row.index }}' class='fas fa-trash-alt icon-red'></span>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ row.index }}
|
{% add row.index 1 %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% for field in form.visible_fields %}
|
{% for field in form.visible_fields %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user