2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Match parts view is now populated correctly

This commit is contained in:
eeintech 2021-05-05 15:28:04 -04:00
parent 2cd1df691b
commit 40e8ed9e5b
3 changed files with 47 additions and 33 deletions

View File

@ -72,7 +72,7 @@
{% for item in row.data %} {% for item in row.data %}
<td> <td>
<input type='hidden' name='row_{{ row_index }}_col_{{ forloop.counter0 }}' value='{{ item }}'/> <input type='hidden' name='row_{{ row_index }}_col_{{ forloop.counter0 }}' value='{{ item }}'/>
{{ item }} {{ item.cell }}
</td> </td>
{% endfor %} {% endfor %}
</tr> </tr>

View File

@ -66,22 +66,11 @@
</td> </td>
{% for item in row.data %} {% for item in row.data %}
<td> <td>
{% if item.column.guess == 'Part' %} {% if item.column.guess == 'Quantity' %}
<i>{{ item.cell }}</i>
{% if row.errors.part %}
<p class='help-inline'>{{ row.errors.part }}</p>
{% endif %}
{% elif item.column.guess == 'Quantity' %}
<input name='quantity_{{ row.index }}' class='numberinput' type='number' min='1' step='any' value='{% decimal row.quantity %}'/> <input name='quantity_{{ row.index }}' class='numberinput' type='number' min='1' step='any' value='{% decimal row.quantity %}'/>
{% if row.errors.quantity %} {% if row.errors.quantity %}
<p class='help-inline'>{{ row.errors.quantity }}</p> <p class='help-inline'>{{ row.errors.quantity }}</p>
{% endif %} {% endif %}
{% elif item.column.guess == 'Reference' %}
<input name='reference_{{ row.index }}' value='{{ row.reference }}'/>
{% elif item.column.guess == 'Note' %}
<input name='notes_{{ row.index }}' value='{{ row.notes }}'/>
{% elif item.column.guess == 'Overage' %}
<input name='overage_{{ row.index }}' value='{{ row.overage }}'/>
{% else %} {% else %}
{{ item.cell }} {{ item.cell }}
{% endif %} {% endif %}

View File

@ -23,7 +23,7 @@ from .models import SalesOrder, SalesOrderLineItem, SalesOrderAttachment
from .models import SalesOrderAllocation from .models import SalesOrderAllocation
from .admin import POLineItemResource from .admin import POLineItemResource
from build.models import Build from build.models import Build
from company.models import Company, ManufacturerPart, SupplierPart from company.models import Company, SupplierPart # ManufacturerPart
from stock.models import StockItem, StockLocation from stock.models import StockItem, StockLocation
from part.models import Part from part.models import Part
@ -592,6 +592,7 @@ class PurchaseOrderUpload(MultiStepFormView):
rows = None rows = None
columns = None columns = None
missing_columns = None missing_columns = None
allowed_parts = None
def get_context_data(self, form, **kwargs): def get_context_data(self, form, **kwargs):
context = super().get_context_data(form=form, **kwargs) context = super().get_context_data(form=form, **kwargs)
@ -605,8 +606,22 @@ class PurchaseOrderUpload(MultiStepFormView):
# print(f'{self.headers}') # print(f'{self.headers}')
if self.columns: if self.columns:
context.update({'columns': self.columns}) context.update({'columns': self.columns})
print(f'{self.columns}') # print(f'{self.columns}')
if self.rows: if self.rows:
for row in self.rows:
row_data = row['data']
data = []
for idx, item in enumerate(row_data):
data.append({
'cell': item,
'idx': idx,
'column': self.columns[idx]
})
row['data'] = data
context.update({'rows': self.rows}) context.update({'rows': self.rows})
# print(f'{self.rows}') # print(f'{self.rows}')
if self.missing_columns: if self.missing_columns:
@ -764,11 +779,11 @@ class PurchaseOrderUpload(MultiStepFormView):
""" """
# Fields prefixed with "Part_" can be used to do "smart matching" against Part objects in the database # Fields prefixed with "Part_" can be used to do "smart matching" against Part objects in the database
s_idx = self.getColumnIndex('Supplier_SKU')
m_idx = self.getColumnIndex('Manufacturer_MPN')
q_idx = self.getColumnIndex('Quantity') q_idx = self.getColumnIndex('Quantity')
p_idx = self.getColumnIndex('Unit_Price') s_idx = self.getColumnIndex('Supplier_SKU')
e_idx = self.getColumnIndex('Extended_Price') # m_idx = self.getColumnIndex('Manufacturer_MPN')
# p_idx = self.getColumnIndex('Unit_Price')
# e_idx = self.getColumnIndex('Extended_Price')
for row in self.rows: for row in self.rows:
@ -779,7 +794,7 @@ class PurchaseOrderUpload(MultiStepFormView):
exact_match_part = None exact_match_part = None
# A list of potential Part matches # A list of potential Part matches
part_options = SupplierPart.objects.all() part_options = self.allowed_parts
# Check if there is a column corresponding to "quantity" # Check if there is a column corresponding to "quantity"
if q_idx >= 0: if q_idx >= 0:
@ -797,23 +812,23 @@ class PurchaseOrderUpload(MultiStepFormView):
# Check if there is a column corresponding to "Supplier SKU" # Check if there is a column corresponding to "Supplier SKU"
if s_idx >= 0: if s_idx >= 0:
row['part_sku'] = row['data'][s_idx] sku = row['data'][s_idx]
try: try:
# Attempt SupplierPart lookup based on SKU value # Attempt SupplierPart lookup based on SKU value
exact_match_part = SupplierPart.objects.get(SKU=row['part_sku']) exact_match_part = SupplierPart.objects.get(SKU__contains=sku)
except (ValueError, SupplierPart.DoesNotExist): except (ValueError, SupplierPart.DoesNotExist, SupplierPart.MultipleObjectsReturned):
exact_match_part = None exact_match_part = None
# Check if there is a column corresponding to "Manufacturer MPN" # Check if there is a column corresponding to "Manufacturer MPN"
if m_idx >= 0: # if m_idx >= 0:
row['part_mpn'] = row['data'][m_idx] # row['part_mpn'] = row['data'][m_idx]
# try: # try:
# # Attempt ManufacturerPart lookup based on MPN value # # Attempt ManufacturerPart lookup based on MPN value
# exact_match_part = ManufacturerPart.objects.get(MPN=row['part_mpn']) # exact_match_part = ManufacturerPart.objects.get(MPN=row['part_mpn'])
# except (ValueError, ManufacturerPart.DoesNotExist): # except (ValueError, ManufacturerPart.DoesNotExist):
# exact_match_part = None # exact_match_part = None
# Supply list of part options for each row, sorted by how closely they match the part name # Supply list of part options for each row, sorted by how closely they match the part name
row['part_options'] = part_options row['part_options'] = part_options
@ -825,6 +840,10 @@ class PurchaseOrderUpload(MultiStepFormView):
# If there is an exact match based on SKU or MPN, use that # If there is an exact match based on SKU or MPN, use that
row['part_match'] = exact_match_part row['part_match'] = exact_match_part
def updatePartSelectionColumns(self, form):
# for idx, row in enumerate(self.rows):
# print(f'{idx} | {row}\n\n')
pass
def getFileManager(self, form=None): def getFileManager(self, form=None):
""" Create FileManager instance from upload file """ """ Create FileManager instance from upload file """
@ -860,6 +879,9 @@ class PurchaseOrderUpload(MultiStepFormView):
def handleFieldSelection(self, form): def handleFieldSelection(self, form):
""" Process field matching """ """ Process field matching """
# Retrieve FileManager instance from uploaded file
self.getFileManager(form)
# Update headers # Update headers
if self.file_manager: if self.file_manager:
self.file_manager.setup() self.file_manager.setup()
@ -875,6 +897,9 @@ class PurchaseOrderUpload(MultiStepFormView):
def handlePartSelection(self, form): def handlePartSelection(self, form):
# Retrieve FileManager instance from uploaded file
self.getFileManager(form)
# Extract form data # Extract form data
self.getTableDataFromForm(form.data) self.getTableDataFromForm(form.data)
@ -893,8 +918,10 @@ class PurchaseOrderUpload(MultiStepFormView):
if self.steps.current == 'upload': if self.steps.current == 'upload':
self.setupFieldSelection(form) self.setupFieldSelection(form)
elif self.steps.current == 'fields': elif self.steps.current == 'fields':
self.allowed_parts = SupplierPart.objects.all()
self.rows = self.file_manager.rows()
self.preFillSelections() self.preFillSelections()
print(self.rows) self.updatePartSelectionColumns(form)
# elif self.steps.current == 'parts': # elif self.steps.current == 'parts':
# self.handlePartSelection(form) # self.handlePartSelection(form)
@ -910,8 +937,6 @@ class PurchaseOrderUpload(MultiStepFormView):
# Validation is done during POST # Validation is done during POST
valid = True valid = True
elif step == 'fields': elif step == 'fields':
# Retrieve FileManager instance from uploaded file
self.getFileManager(form)
# Validate user form data # Validate user form data
valid = self.handleFieldSelection(form) valid = self.handleFieldSelection(form)