Selaa lähdekoodia

report new format

tum 8 kuukautta sitten
vanhempi
commit
180f5929a8

+ 1 - 0
app/core/utils.py

@@ -233,6 +233,7 @@ SHEET_NAMES = {
233 233
     'hardness_both_size': 'Hardness Both Size',
234 234
     'dimension': 'Dimension',
235 235
     'dimension_app': 'Dimension Appearance',
236
+    'dimension_app_drawing': 'Dimension Appearance + Drawing',
236 237
     'dimension_bal_weight': 'Dimension Balance/Weight',
237 238
     'dim_bal_app_hard': 'Dimension Balance/Appearance/Hardness',
238 239
     'dim_bal_app_rot_hard': 'Dimension Balance/Appearance/Rotation/Hardness',

BIN
app/report/coi_templates.xlsx


+ 24 - 7
app/report/gen_report.py

@@ -193,20 +193,37 @@ def gen_xlsx(template_file, selected_sheets, prefix_filename, data):
193 193
                                 # img.height = 40  # Adjust size as needed
194 194
                                 pil_img = PILImage.open(image_path)
195 195
                                 original_width, original_height = pil_img.size
196
+                                pprint(f"1.0 = f{image_path}")
197
+                                pprint(f"1.1 = {original_width}x{original_height}")
196 198
 
197 199
                                 # Desired height (e.g., 40), calculate the new width to maintain aspect ratio
198
-                                desired_height = 30
199
-                                aspect_ratio = original_width / original_height
200
-                                new_width = int(desired_height * aspect_ratio)
200
+                                row_height = sheet.row_dimensions[cell.row].height
201
+                                desired_height = int(row_height)
201 202
 
202
-                                # Resize the image using Pillow (optional, for saving memory during export)
203
-                                resized_img = pil_img.resize((new_width, desired_height), PILImage.Resampling.LANCZOS)
204
-                                resized_img.save(image_path)  # Save the resized image back to the same path
203
+                                fixed_pixel_height = int(desired_height * 1.33)  # Convert point → pixel
205 204
 
205
+                                aspect_ratio = original_width / original_height
206
+                                new_width = int(fixed_pixel_height * aspect_ratio)
207
+
208
+                                resized_img = pil_img.resize((new_width, fixed_pixel_height), PILImage.Resampling.LANCZOS)
209
+
210
+# Generate new filename by adding '_resized' before extension
211
+                                base, ext = os.path.splitext(image_path)
212
+                                resized_path = f"{base}_resized{ext}"
213
+
214
+                                resized_img.save(resized_path)
215
+                                # aspect_ratio = original_width / original_height
216
+                                # new_width = int(desired_height * aspect_ratio)
217
+                                #
218
+                                # # Resize the image using Pillow (optional, for saving memory during export)
219
+                                # resized_img = pil_img.resize((new_width, desired_height), PILImage.Resampling.LANCZOS)
220
+                                # resized_img.save(image_path)  # Save the resized image back to the same path
221
+                                pprint(f"1.2 = {new_width}, {desired_height}")
206 222
                                 # Insert the resized image into the Excel sheet
207
-                                img = Image(image_path)
223
+                                img = Image(resized_path)
208 224
                                 img.width, img.height = new_width, desired_height  # Set the dimensions
209 225
                                 # sheet.add_image(img, cell.coordinate)
226
+                                print(f"1.3 = {row_height}")
210 227
                                 center_image_in_cell(sheet, img, cell.coordinate, )
211 228
                                 cell.value = None  # Clear placeholder
212 229
 

+ 3 - 2
app/report/templates/report/coi.html

@@ -7,6 +7,7 @@
7 7
 {% block content %}
8 8
 <div class="container mx-auto px-4 py-8" x-data="COIReport">
9 9
   <h1 class="text-2xl font-bold text-gray-800">Export Center</h1>
10
+  {{ lot_no }}
10 11
   <form method='post'>
11 12
     {% csrf_token %}
12 13
     <div class="flex items-center gap-2 mb-4">
@@ -84,7 +85,7 @@
84 85
                     <tbody>
85 86
                         <tr class="bg-blue-100">
86 87
                             <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Product Code :</td>
87
-                            <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ result.PRO1 }}</td>
88
+                            <td class="border border-gray-300 px-4 py-2 text-gray-700">{{ code }}</td>
88 89
                         </tr>
89 90
                         <tr>
90 91
                             <td class="border border-gray-300 px-4 py-2 font-medium text-gray-700">Lot No. :</td>
@@ -152,7 +153,7 @@ th, td {
152 153
   function COIReport() {
153 154
     return {
154 155
       lot_no: '{{ lot_no }}', // Bind this to the input value
155
-      exports: {{ selected_templates|safe }},
156
+      exports: {{ selected_templates|default:"[]"|safe }},
156 157
       qa1: null,
157 158
       qa2: null,
158 159
       gen_report_url: '{% url "report:gen_report" %}', 

+ 129 - 9
app/report/views.py

@@ -26,6 +26,8 @@ from django.conf import settings
26 26
 from itertools import chain
27 27
 
28 28
 from django_filters.views import FilterView
29
+from django.db.models import Q
30
+
29 31
 
30 32
 from django.views.generic import (
31 33
     ListView,)
@@ -384,6 +386,97 @@ def generate_dimension_app_values(lot_no, code):
384 386
     placeholders['inspect_date'] = inspect_date.strftime('%Y/%m/%d') if inspect_date else "-"
385 387
     return placeholders
386 388
 
389
+def generate_dimension_app_drawing_values(lot_no, code):
390
+    """
391
+    Fetch dimension records from manualSize and DataMs models
392
+    and generate placeholder values for Standard, Actual, and Judgement.
393
+    Supports two row_no entries per lot.
394
+    """
395
+    # Fetch standard values from manualSize (limit to 2 rows)
396
+    manual_size_records = Manualsize.objects.filter(lotno=lot_no)
397
+
398
+    dimens = AllProductDimensionForInsProcess.objects.filter(ProductCode=code)
399
+    # Fetch actual and judgement values from DataMs ordered by row_no (limit to 2 rows)
400
+    data_ms_records = DataMs.objects.filter(lot_no=lot_no).order_by('row_no')
401
+
402
+    # Prepare placeholders
403
+
404
+    # placeholders = {}
405
+    placeholders = clear_values(8,3)
406
+    # for i in range(1,7):
407
+        # for j in range(1,4):
408
+            # placeholders[f'v{i}_{j}'] = 0
409
+    
410
+    pprint(placeholders)
411
+    pprint(manual_size_records)
412
+
413
+    # for m in manual_size_records:
414
+        # if m.size_name == "D":
415
+            # placeholders['v1_1'] = placeholders['v5_1'] = f'{m.Std:.2f} +{m.TolUp:.2f} {m.TolUn:.2f}'
416
+        # if m.size_name == "T":
417
+            # placeholders['v2_1'] = placeholders['v6_1'] = f'{m.Std:.2f} +{m.TolUp:.2f} {m.TolUn:.2f}'
418
+        # if m.size_name == "H":
419
+            # placeholders['v3_1'] = placeholders['v7_1'] = f'{m.Std:.2f} +{m.TolUp:.2f} {m.TolUn:.2f}'
420
+    for m in dimens:  # Changed from manual_size_records to dimens
421
+        if m.Size_Name == "D":
422
+            placeholders['v1_1'] = placeholders['v5_1'] = f'D{m.Std:.2f} +{m.TolUp:.2f} {m.TolUn:.2f}'
423
+        if m.Size_Name == "T":
424
+            placeholders['v2_1'] = placeholders['v6_1'] = f'T{m.Std:.2f} +{m.TolUp:.2f} {m.TolUn:.2f}'
425
+        if m.Size_Name == "H":
426
+            placeholders['v3_1'] = placeholders['v7_1'] = f'H{m.Std:.2f} +{m.TolUp:.2f} {m.TolUn:.2f}'
427
+
428
+
429
+
430
+    # Ensure that we map each manualSize entry to a corresponding DataMs entry
431
+    inspect_date = None
432
+    for r in data_ms_records:
433
+        if r.row_no == 1:
434
+            placeholders[f'v1_2'] = r.dsize
435
+            placeholders[f'v1_3'] = r.dsizeok
436
+            
437
+            placeholders[f'v2_2'] = r.tsize
438
+            placeholders[f'v2_3'] = r.tsizeok
439
+            
440
+            placeholders[f'v3_2'] = r.hsize
441
+            placeholders[f'v3_3'] = r.hsizeok
442
+            inspect_date = r.created_at
443
+
444
+            # if is_ok(r):
445
+                # placeholders[f'v4_1'] = 'OK'
446
+                # placeholders[f'v4_2'] = 'OK'
447
+            # else:
448
+                # placeholders[f'v4_1'] = 'NG'
449
+                # placeholders[f'v4_2'] = 'OK'
450
+        
451
+        if r.row_no == 2:
452
+            placeholders[f'v5_2'] = r.dsize
453
+            placeholders[f'v5_3'] = r.dsizeok
454
+            
455
+            placeholders[f'v6_2'] = r.tsize
456
+            placeholders[f'v6_3'] = r.tsizeok
457
+            
458
+            placeholders[f'v7_2'] = r.hsize
459
+            placeholders[f'v7_3'] = r.hsizeok
460
+
461
+            # if is_ok(r):
462
+                # placeholders[f'v8_1'] = 'OK'
463
+                # placeholders[f'v8_2'] = 'OK'
464
+            # else:
465
+                # placeholders[f'v8_1'] = 'NG'
466
+                # placeholders[f'v8_2'] = 'NG'
467
+
468
+    hide_con(placeholders, "v5_1", "26:32")
469
+    
470
+    drawing_data = ProductDrawing.objects.filter(
471
+        Q(lot_no=lot_no) | Q(code_no=code)).first()
472
+    pprint(f"1.1 = {drawing_data}") 
473
+    pprint(f"1.2 = {lot_no} {code}")
474
+    if drawing_data:
475
+        placeholders["drawing"] = drawing_data.drawing if drawing_data.drawing else "-"
476
+
477
+    placeholders['inspect_date'] = inspect_date.strftime('%Y/%m/%d') if inspect_date else "-"
478
+    return placeholders
479
+
387 480
 def generate_dimension_bal_weight_values(lot_no, ms, code):
388 481
     """
389 482
     Fetch dimension records from manualSize and DataMs models
@@ -414,8 +507,11 @@ def generate_dimension_bal_weight_values(lot_no, ms, code):
414 507
     pprint(manual_size_records) 
415 508
     
416 509
     if ms:
417
-        w = ms.PRO6
418
-        placeholders['v4_1'] = placeholders['v9_1'] = w
510
+        try:
511
+            w = ms.PRO6
512
+            placeholders['v4_1'] = placeholders['v9_1'] = w
513
+        except:
514
+            print("no PRO6")
419 515
 
420 516
     dimens = AllProductDimensionForInsProcess.objects.filter(ProductCode=code)
421 517
     for m in dimens:  # Changed from manual_size_records to dimens
@@ -523,8 +619,11 @@ def generate_dim_bal_app_hard_values(lot_no, first_result, code):
523 619
     pprint(placeholders)
524 620
     pprint(manual_size_records) 
525 621
     if first_result:
526
-        w = first_result.PRO6
527
-        placeholders['v4_1'] = placeholders['v12_1'] = w
622
+        try:
623
+            w = first_result.PRO6
624
+            placeholders['v4_1'] = placeholders['v12_1'] = w
625
+        except:
626
+            print("No PRO6")
528 627
 
529 628
     dimens = AllProductDimensionForInsProcess.objects.filter(ProductCode=code)
530 629
     for m in dimens:  # Changed from manual_size_records to dimens
@@ -645,8 +744,11 @@ def generate_dim_bal_app_rot_hard_values(lot_no, first_result, code):
645 744
     pprint(placeholders)
646 745
     pprint(manual_size_records) 
647 746
     if first_result:
648
-        w = first_result.PRO6
649
-        placeholders['v4_1'] = placeholders['v13_1'] = w
747
+        try:
748
+            w = first_result.PRO6
749
+            placeholders['v4_1'] = placeholders['v13_1'] = w
750
+        except:
751
+            print("no PRO6")
650 752
 
651 753
     dimens = AllProductDimensionForInsProcess.objects.filter(ProductCode=code)
652 754
     for m in dimens:  # Changed from manual_size_records to dimens
@@ -855,6 +957,8 @@ def create_coi_file(lot_no, sheets, user, md):
855 957
             sheet_data[sheet_name] = generate_dimension_values(lot_no, code)
856 958
         elif sheet_name == 'dimension_app':
857 959
             sheet_data[sheet_name] = generate_dimension_app_values(lot_no, code)
960
+        elif sheet_name == 'dimension_app_drawing':
961
+            sheet_data[sheet_name] = generate_dimension_app_drawing_values(lot_no, code)
858 962
         elif sheet_name == 'dimension_bal_weight':
859 963
             sheet_data[sheet_name] = generate_dimension_bal_weight_values(lot_no, first_result, code)
860 964
         elif sheet_name == 'centering':
@@ -884,8 +988,16 @@ def create_coi_file(lot_no, sheets, user, md):
884 988
         size_str = ""
885 989
         spec = ""
886 990
 
991
+    mgt_code = first_result.PRO1 if first_result else "-"
992
+    mks_map = MksCodeMap.objects.filter(mgt_code=mgt_code).first()
993
+    if mks_map:
994
+        code = f"{mks_map.mks_code}(MKSコード)  {mgt_code}(参照)"
995
+    else:
996
+        code = f"{mgt_code}(参照)" or "-"
997
+
887 998
     data = {
888
-        "code": first_result.PRO1 if first_result else "-",
999
+        # "code": first_result.PRO1 if first_result else "-",
1000
+        "code": code,
889 1001
         "customer": first_result.PRO1C if first_result else "-",
890 1002
         # "inspect_date": inspect_date.strftime('%Y/%m/%d') if inspect_date else "-",
891 1003
         "lot_no": lot_no,
@@ -896,7 +1008,7 @@ def create_coi_file(lot_no, sheets, user, md):
896 1008
         # "hardness_out.spe_acc": False,  # Hide rows 24 to 28 if the prefix is "0"
897 1009
         "acc": accept,  # Hide rows 24 to 28 if the prefix is "0"
898 1010
         "spe_acc": specialAccept,  # Hide rows 24 to 28 if the prefix is "0"
899
-        "tool": first_result.PRO_TOOL,
1011
+        "tool": first_result.PRO_TOOL if first_result else "-",
900 1012
         # "hardness_out.qa1": f"{qa1.first_name} {qa1.last_name}",
901 1013
         # "hardness_out.qa2": f"{qa2.first_name} {qa2.last_name}",
902 1014
         "qa1": f"{qa1.first_name} {qa1.last_name}",
@@ -1017,11 +1129,19 @@ def coi_view(request):
1017 1129
                     pcs = int(first_result.PRO5) - int(first_result.PRO27)
1018 1130
                 except:
1019 1131
                     pcs = 0
1132
+                code = "-"
1020 1133
                 if first_result:
1021 1134
                     size_str = f"{first_result.PRO10}x{first_result.PRO11}x{first_result.PRO12}";
1022 1135
                     spec = f"{first_result.PRO13} {first_result.PRO14} {first_result.PRO15} {first_result.PRO16} {first_result.PRO17} {first_result.PRO18}"
1023 1136
                     #first_result.PRO1C = "TUM"
1024 1137
                     selected_templates  = CustomerTemplateMapping.objects.filter(customer_name=first_result.PRO1C).first().template_names
1138
+
1139
+                    mgt_code = first_result.PRO1 if first_result else "-"
1140
+                    mks_map = MksCodeMap.objects.filter(mgt_code=mgt_code).first()
1141
+                    if mks_map:
1142
+                        code = f"{mks_map.mks_code}(MKSコード)  {mgt_code}(参照)"
1143
+                    else:
1144
+                        code = f"{mgt_code}(参照)" or "-"
1025 1145
                 else:
1026 1146
                     size_str = ""
1027 1147
                     spec = ""
@@ -1040,7 +1160,7 @@ def coi_view(request):
1040 1160
                                                            'size_str': size_str,
1041 1161
                                                            'lot_no': lot_no,
1042 1162
                                                            'spec': spec, 'users': users, 'SHEET_NAMES': SHEET_NAMES, 
1043
-                                                           'results': results, 'fields': fields, 'selected_templates': selected_templates})
1163
+                                                           'results': results, 'fields': fields, 'selected_templates': selected_templates, 'code': code})
1044 1164
 
1045 1165
         messages.success(request, "Request Sent")
1046 1166
         return redirect(request.path_info)