Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task: 2363 Flagging Duplicate VINs in BCeID Spreadsheet Uploads to Prevent Error 31 (duplicate VINs) #2370

Open
wants to merge 2 commits into
base: release-1.65.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions backend/api/services/sales_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,25 @@ def validate_spreadsheet(data, user_organization=None, skip_authorization=False)
)

row = start_row
vin_dict = {}
duplicates = {}

while row < min((MAX_READ_ROWS + start_row), sheet.nrows):
row_contents = sheet.row(row)
model_year = str(row_contents[0].value).strip()
make = str(row_contents[1].value).strip()
model_name = str(row_contents[2].value).strip()
vin = str(row_contents[3].value)
vin = str(row_contents[3].value).strip()
date = str(row_contents[4].value).strip()
row_contains_content = False
if len(model_year) > 0 or len(make) > 0 or len(model_name) > 0 or \
len(date) > 0:
row_contains_content = True
if row_contains_content:
if vin in vin_dict:
vin_dict[vin].append(row + 1)
else:
vin_dict[vin] = [row + 1]

if row_contains_content and row_contents[4].ctype != xlrd.XL_CELL_DATE:
raise ValidationError(
Expand All @@ -371,7 +378,14 @@ def validate_spreadsheet(data, user_organization=None, skip_authorization=False)
'the row and try again.'
)
row += 1

duplicates = {vin: rows for vin, rows in vin_dict.items() if len(rows) > 1}
if duplicates:
error_message = 'Spreadsheet contains duplicate VINs.|'
for vin, rows in duplicates.items():
row_list = ', '.join(map(str, rows))
error_message += f'VIN {vin}: rows {row_list}|'
error_message += 'Please make changes to the spreadsheet and try again.'
raise ValidationError(error_message)
return True


Expand Down
6 changes: 4 additions & 2 deletions frontend/src/app/components/FileDropArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const FileDropArea = (props) => {
}
}
}

const formattedErrorMessage = errorMessage ? errorMessage.split('|').map((msg, index) => (
<div key={index}>{msg}</div>
)) : null;
return (
<div className="row">
<div
Expand All @@ -40,7 +42,7 @@ const FileDropArea = (props) => {
<div className="bordered">
{errorMessage && (
<div className="alert alert-danger mb-2" role="alert">
{errorMessage}
{formattedErrorMessage}
</div>
)}
<div className="panel panel-default">
Expand Down