|
|
@@ -8,7 +8,8 @@ from .filters import ReportFilter
|
|
8
|
8
|
from .forms import ExportOptionsForm
|
|
9
|
9
|
from pprint import pprint
|
|
10
|
10
|
|
|
11
|
|
-from legacy.models import Data, DataMs, DataRl, DataWb, LotSummary, LotSummaryRl, LotSummaryWb, PressCal, RotateData, TbFgPressinfoLotlist
|
|
|
11
|
+from legacy.models import Data, DataMs, DataRl, DataWb, LotSummary, LotSummaryRl, LotSummaryWb, PressCal, RotateData, TbFgPressinfoLotlist,\
|
|
|
12
|
+ Manualsize
|
|
12
|
13
|
|
|
13
|
14
|
from .gen_report import gen_xlsx
|
|
14
|
15
|
from django.core.files.base import File
|
|
|
@@ -161,6 +162,62 @@ def generate_hardness_out_in_values(lot_no):
|
|
161
|
162
|
|
|
162
|
163
|
return placeholders
|
|
163
|
164
|
|
|
|
165
|
+def generate_dimension_values(lot_no):
|
|
|
166
|
+ """
|
|
|
167
|
+ Fetch dimension records from manualSize and DataMs models
|
|
|
168
|
+ and generate placeholder values for Standard, Actual, and Judgement.
|
|
|
169
|
+ Supports two row_no entries per lot.
|
|
|
170
|
+ """
|
|
|
171
|
+ # Fetch standard values from manualSize (limit to 2 rows)
|
|
|
172
|
+ manual_size_records = Manualsize.objects.filter(lotno=lot_no)
|
|
|
173
|
+
|
|
|
174
|
+ # Fetch actual and judgement values from DataMs ordered by row_no (limit to 2 rows)
|
|
|
175
|
+ data_ms_records = DataMs.objects.filter(lot_no=lot_no).order_by('row_no')[:2]
|
|
|
176
|
+
|
|
|
177
|
+ # Prepare placeholders
|
|
|
178
|
+
|
|
|
179
|
+ placeholders = {}
|
|
|
180
|
+ for i in range(1,7):
|
|
|
181
|
+ for j in range(1,4):
|
|
|
182
|
+ placeholders[f'v{i}_{j}'] = 0
|
|
|
183
|
+
|
|
|
184
|
+ pprint(placeholders)
|
|
|
185
|
+ pprint(manual_size_records)
|
|
|
186
|
+ for m in manual_size_records:
|
|
|
187
|
+ if m.size_name == "D":
|
|
|
188
|
+ placeholders['v1_1'] = placeholders['v4_1'] = f'{m.std} +{m.tolup} {m.tolun}'
|
|
|
189
|
+ if m.size_name == "T":
|
|
|
190
|
+ placeholders['v2_1'] = placeholders['v5_1'] = f'{m.std} +{m.tolup} {m.tolun}'
|
|
|
191
|
+ if m.size_name == "H":
|
|
|
192
|
+ placeholders['v3_1'] = placeholders['v6_1'] = f'{m.std} +{m.tolup} {m.tolun}'
|
|
|
193
|
+
|
|
|
194
|
+
|
|
|
195
|
+
|
|
|
196
|
+ # Ensure that we map each manualSize entry to a corresponding DataMs entry
|
|
|
197
|
+ for r in data_ms_records:
|
|
|
198
|
+ if r.row_no == 1:
|
|
|
199
|
+ placeholders[f'v1_2'] = r.dsize
|
|
|
200
|
+ placeholders[f'v1_3'] = r.dsizeok
|
|
|
201
|
+
|
|
|
202
|
+ placeholders[f'v2_2'] = r.tsize
|
|
|
203
|
+ placeholders[f'v2_3'] = r.tsizeok
|
|
|
204
|
+
|
|
|
205
|
+ placeholders[f'v3_2'] = r.hsize
|
|
|
206
|
+ placeholders[f'v3_3'] = r.hsizeok
|
|
|
207
|
+
|
|
|
208
|
+ if r.row_no == 2:
|
|
|
209
|
+ placeholders[f'v4_2'] = r.dsize
|
|
|
210
|
+ placeholders[f'v4_3'] = r.dsizeok
|
|
|
211
|
+
|
|
|
212
|
+ placeholders[f'v5_2'] = r.tsize
|
|
|
213
|
+ placeholders[f'v5_3'] = r.tsizeok
|
|
|
214
|
+
|
|
|
215
|
+ placeholders[f'v6_2'] = r.hsize
|
|
|
216
|
+ placeholders[f'v6_3'] = r.hsizeok
|
|
|
217
|
+
|
|
|
218
|
+ hide_con(placeholders, "v4_2", "24:28")
|
|
|
219
|
+ return placeholders
|
|
|
220
|
+
|
|
164
|
221
|
def merge_sheet_data_with_data(sheet_data, data):
|
|
165
|
222
|
"""
|
|
166
|
223
|
Merge `sheet_data` with `data`.
|
|
|
@@ -180,6 +237,13 @@ def create_coi_file(lot_no, sheets, user, md):
|
|
180
|
237
|
qa1 = User.objects.get(pk=md['qa1'])
|
|
181
|
238
|
qa2 = User.objects.get(pk=md['qa2'])
|
|
182
|
239
|
|
|
|
240
|
+ accept = specialAccept = False
|
|
|
241
|
+ if md['acceptStatus'] == "accepted":
|
|
|
242
|
+ accept = True
|
|
|
243
|
+ if md['acceptStatus'] == "special_accepted":
|
|
|
244
|
+ specialAccept = True
|
|
|
245
|
+
|
|
|
246
|
+
|
|
183
|
247
|
pprint(qa1)
|
|
184
|
248
|
pprint(qa2)
|
|
185
|
249
|
|
|
|
@@ -190,25 +254,38 @@ def create_coi_file(lot_no, sheets, user, md):
|
|
190
|
254
|
sheet_data[sheet_name] = generate_hardness_out_values(lot_no)
|
|
191
|
255
|
case 'hardness_out_in':
|
|
192
|
256
|
sheet_data[sheet_name] = generate_hardness_out_in_values(lot_no)
|
|
|
257
|
+ case 'dimension':
|
|
|
258
|
+ sheet_data[sheet_name] = generate_dimension_values(lot_no)
|
|
193
|
259
|
|
|
194
|
260
|
converted_data = convert_sheet_data(sheet_data)
|
|
195
|
261
|
|
|
196
|
262
|
print(f"sheet_data \n {sheet_data}")
|
|
197
|
263
|
print(f"converted_data \n {converted_data}")
|
|
198
|
264
|
|
|
|
265
|
+ results = queryFromMaster(lot_no)
|
|
|
266
|
+ first_result = results[0] if results else None
|
|
|
267
|
+ try:
|
|
|
268
|
+ pcs = int(first_result.PRO5) - int(first_result.PRO27)
|
|
|
269
|
+ except:
|
|
|
270
|
+ pcs = 0
|
|
|
271
|
+ if first_result:
|
|
|
272
|
+ size_str = f"{first_result.PRO10}x{first_result.PRO11}x{first_result.PRO12}";
|
|
|
273
|
+ spec = f"{first_result.PRO13} {first_result.PRO14} {first_result.PRO15} {first_result.PRO16} {first_result.PRO17} {first_result.PRO18}"
|
|
|
274
|
+ else:
|
|
|
275
|
+ size_str = ""
|
|
|
276
|
+ spec = ""
|
|
|
277
|
+
|
|
199
|
278
|
data = {
|
|
200
|
|
- "customer": "Tum Coder",
|
|
|
279
|
+ "customer": first_result.PRO1C,
|
|
201
|
280
|
"inspect_date": "2025-01-15",
|
|
202
|
|
- "lot_no": "12345",
|
|
203
|
|
- "staff_name": "Tum 8888",
|
|
204
|
|
- "man_name": "Tum 999",
|
|
205
|
|
- "size": "Large",
|
|
206
|
|
- "pcs": "10 pcs",
|
|
207
|
|
- "spec": "Spec-A",
|
|
208
|
|
- "hardness_out.acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
209
|
|
- "hardness_out.spe_acc": False, # Hide rows 24 to 28 if the prefix is "0"
|
|
210
|
|
- "acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
211
|
|
- "spe_acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
|
281
|
+ "lot_no": lot_no,
|
|
|
282
|
+ "size": size_str,
|
|
|
283
|
+ "pcs": pcs,
|
|
|
284
|
+ "spec": spec,
|
|
|
285
|
+ # "hardness_out.acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
|
286
|
+ # "hardness_out.spe_acc": False, # Hide rows 24 to 28 if the prefix is "0"
|
|
|
287
|
+ "acc": accept, # Hide rows 24 to 28 if the prefix is "0"
|
|
|
288
|
+ "spe_acc": specialAccept, # Hide rows 24 to 28 if the prefix is "0"
|
|
212
|
289
|
# "hardness_out.qa1": f"{qa1.first_name} {qa1.last_name}",
|
|
213
|
290
|
# "hardness_out.qa2": f"{qa2.first_name} {qa2.last_name}",
|
|
214
|
291
|
"qa1": f"{qa1.first_name} {qa1.last_name}",
|
|
|
@@ -385,7 +462,8 @@ def gen_report_view(request):
|
|
385
|
462
|
return HttpResponseBadRequest("Missing 'lot_no' in request data")
|
|
386
|
463
|
|
|
387
|
464
|
# Call the `create_coi_file` function with the provided lot_no
|
|
388
|
|
- report = create_coi_file(lot_no, exports, request.user, {'qa1': qa1, 'qa2': qa2})
|
|
|
465
|
+ report = create_coi_file(lot_no, exports, request.user, {'qa1': qa1, 'qa2': qa2, \
|
|
|
466
|
+ 'acceptStatus': data.get('acceptStatus')})
|
|
389
|
467
|
|
|
390
|
468
|
# Return a success response with the report details
|
|
391
|
469
|
return JsonResponse({
|