|
|
@@ -85,6 +85,19 @@ def convert_sheet_data(sheet_data):
|
|
85
|
85
|
|
|
86
|
86
|
return converted_data
|
|
87
|
87
|
|
|
|
88
|
+def hide_con(placeholders, mark_value, hide_rows):
|
|
|
89
|
+ """
|
|
|
90
|
+ Updates the 'placeholders' dictionary with a mark value and hide rows range.
|
|
|
91
|
+
|
|
|
92
|
+ :param placeholders: The dictionary to update.
|
|
|
93
|
+ :param mark_value: The key to check or update in the placeholders.
|
|
|
94
|
+ :param hide_rows: The row range to append in the format '[start:end]'.
|
|
|
95
|
+ """
|
|
|
96
|
+ if mark_value in placeholders:
|
|
|
97
|
+ placeholders[mark_value] = f"{placeholders[mark_value]}[{hide_rows}]"
|
|
|
98
|
+ else:
|
|
|
99
|
+ placeholders[mark_value] = f"0[{hide_rows}]"
|
|
|
100
|
+
|
|
88
|
101
|
def generate_hardness_out_values(lot_no):
|
|
89
|
102
|
"""
|
|
90
|
103
|
Generate a dictionary of placeholder values for a given lot_no.
|
|
|
@@ -108,6 +121,44 @@ def generate_hardness_out_values(lot_no):
|
|
108
|
121
|
|
|
109
|
122
|
return placeholders
|
|
110
|
123
|
|
|
|
124
|
+def generate_hardness_out_in_values(lot_no):
|
|
|
125
|
+ # Fetch records from the Data model
|
|
|
126
|
+ records = Data.objects.filter(lot_no=lot_no).order_by('row_no')
|
|
|
127
|
+ out_data = []
|
|
|
128
|
+ in_data = []
|
|
|
129
|
+
|
|
|
130
|
+ # Separate OUT and IN data
|
|
|
131
|
+ for record in records:
|
|
|
132
|
+ if record.r_type.upper() in ["OUT", "TOP", "FA1", "UPP", "UPPE", "RIM"]:
|
|
|
133
|
+ out_data.append(record)
|
|
|
134
|
+ elif record.r_type.upper() in ["IN", "UNDER", "UND", "FA2", "LOW", "LOWE", "BASE", "SOKO", "IN*"]:
|
|
|
135
|
+ in_data.append(record)
|
|
|
136
|
+
|
|
|
137
|
+ # Prepare placeholders
|
|
|
138
|
+ placeholders = {}
|
|
|
139
|
+ for idx, record in enumerate(out_data, start=1):
|
|
|
140
|
+ placeholders[f'v{idx}_1'] = record.p1
|
|
|
141
|
+ placeholders[f'v{idx}_2'] = record.p2
|
|
|
142
|
+ placeholders[f'v{idx}_3'] = record.p3
|
|
|
143
|
+ placeholders[f'v{idx}_4'] = record.avg
|
|
|
144
|
+ placeholders[f'v{idx}_5'] = record.rgrade
|
|
|
145
|
+
|
|
|
146
|
+ for idx, record in enumerate(in_data, start=1):
|
|
|
147
|
+ placeholders[f'v{len(out_data) + idx}_1'] = record.p1
|
|
|
148
|
+ placeholders[f'v{len(out_data) + idx}_2'] = record.p2
|
|
|
149
|
+ placeholders[f'v{len(out_data) + idx}_3'] = record.p3
|
|
|
150
|
+ placeholders[f'v{len(out_data) + idx}_4'] = record.avg
|
|
|
151
|
+ placeholders[f'v{len(out_data) + idx}_5'] = record.rgrade
|
|
|
152
|
+
|
|
|
153
|
+ # if "v3_1" in placeholders:
|
|
|
154
|
+ # placeholders["v3_1"] = f"{placeholders['v3_1']}[25:28]"
|
|
|
155
|
+ # else:
|
|
|
156
|
+ # placeholders[f"v3_1"] = "0[25:28]"
|
|
|
157
|
+
|
|
|
158
|
+ hide_con(placeholders, "v3_1", "25:28")
|
|
|
159
|
+
|
|
|
160
|
+ return placeholders
|
|
|
161
|
+
|
|
111
|
162
|
def merge_sheet_data_with_data(sheet_data, data):
|
|
112
|
163
|
"""
|
|
113
|
164
|
Merge `sheet_data` with `data`.
|
|
|
@@ -132,8 +183,12 @@ def create_coi_file(lot_no, sheets, user, md):
|
|
132
|
183
|
|
|
133
|
184
|
sheet_data = {}
|
|
134
|
185
|
for sheet_name in sheets:
|
|
135
|
|
- if sheet_name == 'hardness_out':
|
|
136
|
|
- sheet_data[sheet_name] = generate_hardness_out_values(lot_no)
|
|
|
186
|
+ match sheet_name:
|
|
|
187
|
+ case 'hardness_out':
|
|
|
188
|
+ sheet_data[sheet_name] = generate_hardness_out_values(lot_no)
|
|
|
189
|
+ case 'hardness_out_in':
|
|
|
190
|
+ sheet_data[sheet_name] = generate_hardness_out_in_values(lot_no)
|
|
|
191
|
+
|
|
137
|
192
|
converted_data = convert_sheet_data(sheet_data)
|
|
138
|
193
|
|
|
139
|
194
|
print(f"sheet_data \n {sheet_data}")
|
|
|
@@ -156,10 +211,6 @@ def create_coi_file(lot_no, sheets, user, md):
|
|
156
|
211
|
# "hardness_out.qa2": f"{qa2.first_name} {qa2.last_name}",
|
|
157
|
212
|
"qa1": f"{qa1.first_name} {qa1.last_name}",
|
|
158
|
213
|
"qa2": f"{qa2.first_name} {qa2.last_name}",
|
|
159
|
|
- "dimension_app.d1_act": "33",
|
|
160
|
|
- "dimension_app.d2_act": "0[26:32]", # Hide rows 24 to 28 if the prefix is "0"
|
|
161
|
|
- "dimension_app.acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
162
|
|
- "dimension_app.spe_acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
163
|
214
|
"sign1": qa1.profile.signed_picture,
|
|
164
|
215
|
"sign2": qa2.profile.signed_picture,
|
|
165
|
216
|
"pos1": qa1.profile.get_position_display(),
|
|
|
@@ -264,6 +315,7 @@ def coi_view(request):
|
|
264
|
315
|
return render(request, 'report/coi.html', {'result': first_result,
|
|
265
|
316
|
'pcs':pcs,
|
|
266
|
317
|
'size_str': size_str,
|
|
|
318
|
+ 'lot_no': lot_no,
|
|
267
|
319
|
'spec': spec, 'users': users, 'SHEET_NAMES': SHEET_NAMES})
|
|
268
|
320
|
|
|
269
|
321
|
messages.success(request, "Request Sent")
|
|
|
@@ -275,7 +327,7 @@ def coi_view(request):
|
|
275
|
327
|
@login_required
|
|
276
|
328
|
def gen_report_view(request):
|
|
277
|
329
|
if request.method == "POST":
|
|
278
|
|
- try:
|
|
|
330
|
+ # try:
|
|
279
|
331
|
# Parse JSON data from the request body
|
|
280
|
332
|
data = json.loads(request.body)
|
|
281
|
333
|
lot_no = data.get("lot_no").strip()
|
|
|
@@ -297,11 +349,11 @@ def gen_report_view(request):
|
|
297
|
349
|
"file_url": report.file.url if report.file else None,
|
|
298
|
350
|
})
|
|
299
|
351
|
|
|
300
|
|
- except json.JSONDecodeError:
|
|
301
|
|
- return HttpResponseBadRequest("Invalid JSON data")
|
|
302
|
|
- except Exception as e:
|
|
303
|
|
- pprint(e)
|
|
304
|
|
- return JsonResponse({"error": str(e)}, status=500)
|
|
|
352
|
+ # except json.JSONDecodeError:
|
|
|
353
|
+ # return HttpResponseBadRequest("Invalid JSON data")
|
|
|
354
|
+ # except Exception as e:
|
|
|
355
|
+ # pprint(e)
|
|
|
356
|
+ # return JsonResponse({"error": str(e)}, status=500)
|
|
305
|
357
|
else:
|
|
306
|
358
|
return HttpResponseBadRequest("Only POST requests are allowed")
|
|
307
|
359
|
|