tum 11 月之前
父節點
當前提交
21ef4ebbc2

+ 4 - 4
app/legacy/models.py

@@ -472,14 +472,14 @@ class DataRl(models.Model):
472 472
 
473 473
 class DataWb(models.Model):
474 474
     row_no = models.IntegerField(blank=True, null=True)
475
+    lot_no = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
476
+    code = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
475 477
     result = models.FloatField(blank=True, null=True)
476 478
     weight = models.FloatField(blank=True, null=True)
477 479
     judgement = models.CharField(max_length=10, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
478 480
     created_at = models.DateTimeField(blank=True, null=True)
479 481
     updated_at = models.DateTimeField(blank=True, null=True)
480
-    lot_no = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
481 482
     machine_id = models.IntegerField(blank=True, null=True)
482
-    code = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
483 483
     emp_id = models.IntegerField(blank=True, null=True)
484 484
     repair_by = models.CharField(max_length=30, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
485 485
 
@@ -712,6 +712,8 @@ class PressCal(models.Model):
712 712
 
713 713
 class RotateData(models.Model):
714 714
     row_no = models.IntegerField(blank=True, null=True)
715
+    lot_no = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
716
+    code = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
715 717
     speed_spec = models.FloatField(blank=True, null=True)
716 718
     speed_test = models.FloatField(blank=True, null=True)
717 719
     speedok = models.CharField(db_column='speedOk', max_length=4, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)  # Field name made lowercase.
@@ -719,9 +721,7 @@ class RotateData(models.Model):
719 721
     station_no = models.IntegerField()
720 722
     created_at = models.DateTimeField(blank=True, null=True)
721 723
     updated_at = models.DateTimeField(blank=True, null=True)
722
-    lot_no = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
723 724
     machine_id = models.IntegerField(blank=True, null=True)
724
-    code = models.CharField(max_length=50, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
725 725
     emp_id = models.IntegerField()
726 726
     devid = models.CharField(max_length=40, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)
727 727
     mode = models.CharField(max_length=10, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True)

+ 4 - 0
app/legacy/templatetags/legacy_filters.py

@@ -44,3 +44,7 @@ def safe_floatformat(value, decimal_places):
44 44
     except (ValueError, TypeError):
45 45
         # If the value is not a number, return it as is
46 46
         return value
47
+
48
+@register.filter
49
+def get_item(dictionary, key):
50
+    return dictionary.get(key, None)

+ 35 - 0
app/report/templates/report/_tbl.html

@@ -0,0 +1,35 @@
1
+{% load legacy_filters %}
2
+<div class="clear-both bg-white shadow rounded-lg overflow-x-auto my-6">
3
+<h2 class="text-2xl md:text-2xl font-semibold text-gray-700 dark:text-gray-200  m-3 tracking-wide leading-snug">
4
+  {{ header }}</h2>
5
+<table class="w-full border-collapse border border-gray-200">
6
+    <thead>
7
+        <tr class="bg-gray-100 text-left text-sm uppercase">
8
+            {% for field in fields %}
9
+            <th class="border border-gray-200 px-4 py-2 text-left">{% firstof field.verbose_name field.name %} </th>
10
+            {% endfor %}
11
+        </tr>
12
+    </thead>
13
+    <tbody>
14
+        {% for obj in objs %}
15
+            <tr class="hover:bg-gray-50">
16
+                {% for field in fields %}
17
+                <td class="border border-gray-200 px-4 py-2">
18
+                    {% if field.name == 'id' %}
19
+                            {{ obj|attr:field.name }}
20
+                    {% elif field.name == 'file' and obj.file %}
21
+                    <a href="{{ obj.file.url }}" target="_blank">View</a>
22
+                    {% else %}
23
+                        {{ obj|attr:field.name | safe_floatformat:2 }}
24
+                    {% endif %}
25
+                </td>
26
+                {% endfor %}
27
+            </tr>
28
+        {% empty %}
29
+            <tr>
30
+                <td colspan="5" class="py-4 px-4 text-center text-gray-600">No data available.</td>
31
+            </tr>
32
+        {% endfor %}
33
+    </tbody>
34
+</table>
35
+</div>

+ 22 - 19
app/report/templates/report/coi.html

@@ -1,5 +1,7 @@
1 1
 {% extends 'base.html' %}
2 2
 {% load tailwind_filters %}
3
+{% load legacy_filters %}
4
+
3 5
 {% block title %}Report Dashboard{% endblock %}
4 6
 
5 7
 {% block content %}
@@ -108,27 +110,28 @@
108 110
                 </table>
109 111
                     </div>
110 112
 </div>
111
-{% include "report/_hardnessout.html" %}
112
-<div class="border-t border-gray-300 my-4"></div>
113
-{% include "report/_hardness_outin.html" %}
114
-<div class="border-t border-gray-300 my-4"></div>
115
-{% include "report/_hardnessboth.html" %}
116
-<div class="border-t border-gray-300 my-4"></div>
117
-{% include "report/_dimen.html" %}
118
-<div class="border-t border-gray-300 my-4"></div>
119
-{% include "report/_dimen_app.html" %}
120
-<div class="border-t border-gray-300 my-4"></div>
121
-{% include "report/_dimen_bal.html" %}
122
-<div class="border-t border-gray-300 my-4"></div>
123
-{% include "report/_dim_bl_app_hard.html" %}
124
-<div class="border-t border-gray-300 my-4"></div>
125
-{% include "report/_dim_bal_app_rot_hard.html" %}
126
-<div class="border-t border-gray-300 my-4"></div>
127
-{% include "report/_t8p.html" %}
128
-<div class="border-t border-gray-300 my-4"></div>
129
-{% include "report/_cen.html" %}
113
+{% for model_name, objs in results.items %}
114
+  {% if objs %}
115
+    {% include "report/_tbl.html" with objs=objs fields=fields|get_item:model_name header=model_name %}
116
+  {% endif %}
117
+{% endfor %}
118
+
130 119
 {% endblock %}
131 120
 {% block footer_script %}
121
+<style>
122
+/* Remove fixed layout and allow columns to grow dynamically */
123
+table {
124
+    table-layout: auto; /* Default is auto, can be explicitly set */
125
+    width: 100%; /* Ensures table spans available space */
126
+}
127
+
128
+th, td {
129
+    white-space: nowrap; /* Prevents text wrapping */
130
+    text-overflow: ellipsis; /* Adds ellipsis for overflowed content if combined with max-width */
131
+    vertical-align: top; /* Aligns content to the top */
132
+}
133
+</style>
134
+
132 135
 <script type="text/javascript">
133 136
   function COIReport() {
134 137
     return {

+ 46 - 1
app/report/views.py

@@ -8,6 +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
12
+
11 13
 from .gen_report import gen_xlsx
12 14
 from django.core.files.base import File
13 15
 from pathlib import Path
@@ -250,6 +252,38 @@ SHEET_NAMES = {
250 252
     'thickness_8_point': 'Thickness 8 Points',
251 253
     'centering': 'Centering',
252 254
 }
255
+def get_fields(model):
256
+    # model_fields = {f.name: f for f in model._meta.get_fields()}
257
+    # fields = list(model_fields.values())
258
+    # return fields
259
+    fields = [f for f in model._meta.get_fields() if not f.auto_created]
260
+    return fields
261
+
262
+def filter_by_lot_no(lot_no):
263
+    models = [Data, DataMs, DataRl, DataWb, LotSummary, LotSummaryRl, LotSummaryWb, PressCal, RotateData ]  # List of models to process
264
+    results = {}
265
+    fields = {}
266
+
267
+    for model in models:
268
+
269
+        model_fields = [f.name for f in model._meta.get_fields()]
270
+        # Check if "id" and "row_no" are in the model's fields
271
+        order_fields = []
272
+        if "id" in model_fields:
273
+            order_fields.append("id")
274
+        if "row_no" in model_fields:
275
+            order_fields.append("row_no")
276
+        # Dynamically filter and order results
277
+        model_name = model.__name__
278
+        if order_fields:
279
+            results[model_name] = model.objects.filter(lot_no=lot_no).order_by(*order_fields)
280
+        else:
281
+            results[model_name] = model.objects.filter(lot_no=lot_no)  # No 
282
+        
283
+        fields[model_name] = get_fields(model)
284
+
285
+    return results, fields
286
+
253 287
 def coi_view(request):
254 288
     pprint(f"xxxx method = xxx {request.method}")
255 289
     users = User.objects.all()
@@ -312,11 +346,22 @@ def coi_view(request):
312 346
                 else:
313 347
                     size_str = ""
314 348
                     spec = ""
349
+                results, fields = filter_by_lot_no(lot_no)
350
+                # results1 = Data.objects.filter(lot_no=lot_no).order_by("id", "row_no")
351
+                # fields1 =  get_fields(Data)
352
+
353
+                # results2 = DataMs.objects.filter(lot_no=lot_no).order_by("id", "row_no")
354
+                # fields2 =  get_fields(DataMs)
355
+
356
+
357
+
358
+
315 359
                 return render(request, 'report/coi.html', {'result': first_result, 
316 360
                                                            'pcs':pcs, 
317 361
                                                            'size_str': size_str,
318 362
                                                            'lot_no': lot_no,
319
-                                                           'spec': spec, 'users': users, 'SHEET_NAMES': SHEET_NAMES})
363
+                                                           'spec': spec, 'users': users, 'SHEET_NAMES': SHEET_NAMES, 
364
+                                                           'results': results, 'fields': fields})
320 365
 
321 366
         messages.success(request, "Request Sent")
322 367
         return redirect(request.path_info)