|
|
@@ -65,7 +65,7 @@ class ReportCRUDView(ConfigurableCRUDView):
|
|
65
|
65
|
# config_edit_fields = ["lot_no", "code"]
|
|
66
|
66
|
ordering = ["-created_at", "-id",]
|
|
67
|
67
|
|
|
68
|
|
-def create_coi_file(lot_no, user):
|
|
|
68
|
+def create_coi_file(lot_no, sheets, user):
|
|
69
|
69
|
|
|
70
|
70
|
data = {
|
|
71
|
71
|
"customer": "Tum Coder",
|
|
|
@@ -92,10 +92,12 @@ def create_coi_file(lot_no, user):
|
|
92
|
92
|
"dimension_app.d2_act": "0[26:32]", # Hide rows 24 to 28 if the prefix is "0"
|
|
93
|
93
|
"dimension_app.acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
94
|
94
|
"dimension_app.spe_acc": True, # Hide rows 24 to 28 if the prefix is "0"
|
|
|
95
|
+ "sign1": user.profile.signed_picture,
|
|
|
96
|
+ "sign2": user.profile.signed_picture,
|
|
95
|
97
|
}
|
|
96
|
98
|
output_file = gen_xlsx(
|
|
97
|
99
|
template_file="/app/report/coi_templates.xlsx",
|
|
98
|
|
- selected_sheets=["hardness_out", "dimension_app"], # Replace with your actual sheet names
|
|
|
100
|
+ selected_sheets=sheets, # Replace with your actual sheet names
|
|
99
|
101
|
prefix_filename="/app/media/coi",
|
|
100
|
102
|
data=data
|
|
101
|
103
|
)
|
|
|
@@ -111,10 +113,25 @@ def create_coi_file(lot_no, user):
|
|
111
|
113
|
pprint(f"outputfile = {output_file}")
|
|
112
|
114
|
return report
|
|
113
|
115
|
|
|
|
116
|
+SHEET_NAMES = {
|
|
|
117
|
+ 'hardness_out': 'Hardness Out',
|
|
|
118
|
+ 'hardness_out_in': 'Hardness Out/In',
|
|
|
119
|
+ 'hardness_both_size': 'Hardness Both Size',
|
|
|
120
|
+ 'dimension': 'Dimension',
|
|
|
121
|
+ 'dimension_app': 'Dimension Appearance',
|
|
|
122
|
+ 'dimension_bal_weight': 'Dimension Balance/Weight',
|
|
|
123
|
+ 'dim_bal_app_hard': 'Dimension Balance/Appearance/Hardness',
|
|
|
124
|
+ 'dim_bal_app_rot_hard': 'Dimension Balance/Appearance/Rotation/Hardness',
|
|
|
125
|
+ 'thickness_8_point': 'Thickness 8 Points',
|
|
|
126
|
+ 'centering': 'Centering',
|
|
|
127
|
+}
|
|
114
|
128
|
def coi_view(request):
|
|
115
|
129
|
pprint(f"xxxx method = xxx {request.method}")
|
|
116
|
130
|
if request.method == "POST":
|
|
117
|
131
|
pprint(request.POST)
|
|
|
132
|
+ exports = request.POST.getlist("exports") # Retrieve the list of selected values
|
|
|
133
|
+ pprint(f"Selected Export Options: {exports}")
|
|
|
134
|
+
|
|
118
|
135
|
if 'export' in request.POST:
|
|
119
|
136
|
|
|
120
|
137
|
data = {
|
|
|
@@ -137,7 +154,7 @@ def coi_view(request):
|
|
137
|
154
|
}
|
|
138
|
155
|
output_file = gen_xlsx(
|
|
139
|
156
|
template_file="/app/report/coi_templates.xlsx",
|
|
140
|
|
- selected_sheets=["hardness_out", "dimension_app"], # Replace with your actual sheet names
|
|
|
157
|
+ selected_sheets=exports, # Replace with your actual sheet names
|
|
141
|
158
|
prefix_filename="/app/media/coi",
|
|
142
|
159
|
data=data
|
|
143
|
160
|
)
|
|
|
@@ -168,11 +185,10 @@ def coi_view(request):
|
|
168
|
185
|
'size_str': size_str,
|
|
169
|
186
|
'spec': spec})
|
|
170
|
187
|
|
|
171
|
|
- exports = request.POST.getlist("exports") # Retrieve the list of selected values
|
|
172
|
|
- pprint(f"Selected Export Options: {exports}")
|
|
173
|
188
|
messages.success(request, "Request Sent")
|
|
174
|
189
|
return redirect(request.path_info)
|
|
175
|
|
- return render(request, 'report/coi.html')
|
|
|
190
|
+ return render(request, 'report/coi.html', {'SHEET_NAMES': SHEET_NAMES})
|
|
|
191
|
+
|
|
176
|
192
|
|
|
177
|
193
|
@csrf_exempt # Disable CSRF for API requests (ensure this is secure in production)
|
|
178
|
194
|
@login_required
|
|
|
@@ -182,12 +198,13 @@ def gen_report_view(request):
|
|
182
|
198
|
# Parse JSON data from the request body
|
|
183
|
199
|
data = json.loads(request.body)
|
|
184
|
200
|
lot_no = data.get("lot_no")
|
|
|
201
|
+ exports = data.get("exports")
|
|
185
|
202
|
|
|
186
|
203
|
if not lot_no:
|
|
187
|
204
|
return HttpResponseBadRequest("Missing 'lot_no' in request data")
|
|
188
|
205
|
|
|
189
|
206
|
# Call the `create_coi_file` function with the provided lot_no
|
|
190
|
|
- report = create_coi_file(lot_no, request.user)
|
|
|
207
|
+ report = create_coi_file(lot_no, exports, request.user)
|
|
191
|
208
|
|
|
192
|
209
|
# Return a success response with the report details
|
|
193
|
210
|
return JsonResponse({
|