|
|
@@ -26,7 +26,7 @@ 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
|
|
|
29
|
+from django.db.models import Q, Func, Value, F
|
|
30
|
30
|
|
|
31
|
31
|
|
|
32
|
32
|
from django.views.generic import (
|
|
|
@@ -456,6 +456,10 @@ def generate_dimension_app_values(lot_no, code):
|
|
456
|
456
|
placeholders['inspect_date'] = inspect_date.strftime('%Y/%m/%d') if inspect_date else "-"
|
|
457
|
457
|
return placeholders
|
|
458
|
458
|
|
|
|
459
|
+def safe_strip(val):
|
|
|
460
|
+ """Remove '-' or return '' if None."""
|
|
|
461
|
+ return val.replace('-', '') if val else ''
|
|
|
462
|
+
|
|
459
|
463
|
def generate_dimension_app_drawing_values(lot_no, code):
|
|
460
|
464
|
"""
|
|
461
|
465
|
Fetch dimension records from manualSize and DataMs models
|
|
|
@@ -537,8 +541,23 @@ def generate_dimension_app_drawing_values(lot_no, code):
|
|
537
|
541
|
|
|
538
|
542
|
hide_con(placeholders, "v5_1", "27:33")
|
|
539
|
543
|
|
|
540
|
|
- drawing_data = ProductDrawing.objects.filter(
|
|
541
|
|
- Q(lot_no=lot_no) | Q(code_no=code)).first()
|
|
|
544
|
+
|
|
|
545
|
+ norm_lot_no = safe_strip(lot_no)
|
|
|
546
|
+ norm_code = safe_strip(code)
|
|
|
547
|
+
|
|
|
548
|
+ drawing_qs = ProductDrawing.objects.annotate(
|
|
|
549
|
+ norm_lot_no=Func(F('lot_no'), Value('-'), Value(''), function='replace'),
|
|
|
550
|
+ norm_code_no=Func(F('code_no'), Value('-'), Value(''), function='replace')
|
|
|
551
|
+ )
|
|
|
552
|
+
|
|
|
553
|
+ query = Q()
|
|
|
554
|
+ if norm_lot_no:
|
|
|
555
|
+ query |= Q(norm_lot_no=norm_lot_no)
|
|
|
556
|
+ if norm_code:
|
|
|
557
|
+ query |= Q(norm_code_no=norm_code)
|
|
|
558
|
+
|
|
|
559
|
+ drawing_data = drawing_qs.filter(query).first()
|
|
|
560
|
+
|
|
542
|
561
|
pprint(f"1.1 = {drawing_data}")
|
|
543
|
562
|
pprint(f"1.2 = {lot_no} {code}")
|
|
544
|
563
|
if drawing_data:
|