Skip to content

Commit 793b1c2

Browse files
author
John75SunCity
committed
feat: Improve portal file create form per business requirements
- Hide barcode field (system auto-generates temp barcode like TMP-FILE-XXXX-DEPT-000001) - Department field now read-only, inherited from selected container - File Category dropdown now pulls from model Selection field (Administrative, Financial, Legal, HR, etc.) - File State read-only, defaults to 'in' (managed by system) - Date Created defaults to today - Hide Date Received (set by technician when container scanned to work order) - Add JavaScript to update department display when container changes
1 parent bdbecf1 commit 793b1c2

File tree

2 files changed

+107
-76
lines changed

2 files changed

+107
-76
lines changed

records_management/controllers/portal.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,11 +2934,16 @@ def portal_file_create(self, **post):
29342934
except (ValueError, TypeError):
29352935
preselect_container_id = None
29362936

2937+
# Get file categories from the model's Selection field
2938+
file_categories = request.env['records.file']._fields['file_category'].selection
2939+
29372940
values = {
29382941
'containers': containers,
29392942
'preselect_container_id': preselect_container_id,
29402943
'permissions': self._get_user_permissions(),
29412944
'page_name': 'file_create',
2945+
'file_categories': file_categories,
2946+
'today': date.today().strftime('%Y-%m-%d'),
29422947
**dept_context, # departments, default_department, has_departments, show_department_selector
29432948
}
29442949
return request.render("records_management.portal_file_create", values)
@@ -2991,6 +2996,7 @@ def portal_file_create(self, **post):
29912996
'partner_id': partner.id,
29922997
'container_id': int(container_id),
29932998
'created_via_portal': True,
2999+
'state': 'in', # Default state - will be managed by system
29943000
}
29953001

29963002
# Only set department if we have one
@@ -2999,8 +3005,45 @@ def portal_file_create(self, **post):
29993005

30003006
if post.get('description'):
30013007
file_vals['description'] = post.get('description')
3002-
if post.get('barcode'):
3003-
file_vals['barcode'] = post.get('barcode')
3008+
3009+
# Set file category if provided
3010+
if post.get('file_category'):
3011+
file_vals['file_category'] = post.get('file_category')
3012+
3013+
# Set date_created (defaults to today if not provided)
3014+
if post.get('date_created'):
3015+
file_vals['date_created'] = post.get('date_created')
3016+
else:
3017+
file_vals['date_created'] = date.today()
3018+
3019+
# Generate temp barcode for tracking (similar to container temp barcode)
3020+
import re
3021+
3022+
# Get 4-char company code
3023+
if partner.customer_code:
3024+
company_code = re.sub(r'[^A-Za-z0-9]', '', partner.customer_code).upper()[:4].ljust(4, '0')
3025+
elif partner.ref:
3026+
company_code = re.sub(r'[^A-Za-z0-9]', '', partner.ref).upper()[:4].ljust(4, '0')
3027+
else:
3028+
company_code = 'CUST'
3029+
3030+
# Build temp barcode prefix
3031+
temp_prefix = f'TMP-FILE-{company_code}'
3032+
3033+
# Add department code if available
3034+
if final_department_id:
3035+
dept = request.env['records.department'].sudo().browse(final_department_id)
3036+
if dept.code:
3037+
dept_code = re.sub(r'[^A-Za-z0-9]', '', dept.code).upper()[:4].ljust(4, '0')
3038+
temp_prefix += f'-{dept_code}'
3039+
3040+
# Get next sequence number
3041+
existing_count = request.env['records.file'].sudo().search_count([
3042+
('temp_barcode', 'like', temp_prefix + '-%'),
3043+
('partner_id', '=', partner.id)
3044+
])
3045+
seq_num = str(existing_count + 1).zfill(6)
3046+
file_vals['temp_barcode'] = f'{temp_prefix}-{seq_num}'
30043047

30053048
file_record = request.env['records.file'].sudo().create(file_vals)
30063049

records_management/templates/portal_file_create.xml

Lines changed: 62 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
</small>
3030
</div>
3131

32-
<div class="form-group">
33-
<label for="barcode">Barcode</label>
34-
<input type="text" class="form-control" id="barcode" name="barcode"
35-
placeholder="Scan or enter barcode (optional)"/>
36-
</div>
32+
<!-- Barcode hidden - system auto-generates temp barcode -->
33+
<!-- A ZPL template will be used to print temp barcodes like containers -->
3734

3835
<div class="form-group">
3936
<label for="container_id">Container *</label>
40-
<select class="form-control" id="container_id" name="container_id" required="required">
41-
<option value="">-- Select Container --</option>
37+
<select class="form-control" id="container_id" name="container_id" required="required"
38+
onchange="updateDepartmentFromContainer(this)">
39+
<option value="" data-department="">-- Select Container --</option>
4240
<t t-foreach="containers" t-as="container">
4341
<option t-att-value="container.id"
42+
t-att-data-department="container.department_id.name or ''"
43+
t-att-data-department-id="container.department_id.id or ''"
4444
t-att-selected="preselect_container_id and container.id == preselect_container_id">
4545
<t t-esc="container.name"/>
46-
<t t-if="container.location_id"> - <t t-esc="container.location_id.name"/></t>
46+
<t t-if="container.barcode"> (<t t-esc="container.barcode"/>)</t>
4747
</option>
4848
</t>
4949
</select>
@@ -52,95 +52,63 @@
5252
</small>
5353
</div>
5454

55-
<!-- Smart Department Selection -->
56-
<t t-if="has_departments">
57-
<div class="form-group">
58-
<label for="department_id">Department</label>
59-
60-
<!-- Case 1: User has exactly one department - show read-only -->
61-
<t t-if="default_department and not show_department_selector">
62-
<input type="text" class="form-control" readonly="readonly"
63-
t-att-value="default_department.name"/>
64-
<input type="hidden" name="department_id" t-att-value="default_department.id"/>
65-
<small class="form-text text-muted">Your assigned department</small>
66-
</t>
67-
68-
<!-- Case 2: User has multiple departments - show dropdown -->
69-
<t t-elif="show_department_selector">
70-
<select class="form-control" id="department_id" name="department_id">
71-
<option value="">-- Select Department --</option>
72-
<t t-foreach="departments" t-as="dept">
73-
<option t-att-value="dept.id"><t t-esc="dept.name"/></option>
74-
</t>
75-
</select>
76-
</t>
77-
78-
<!-- Case 3: Company has departments but user has no access -->
79-
<t t-else="">
80-
<input type="text" class="form-control text-muted" readonly="readonly"
81-
value="Company Level"/>
82-
<input type="hidden" name="department_id" value=""/>
83-
<small class="form-text text-muted">File will be at company level</small>
84-
</t>
85-
</div>
86-
</t>
55+
<!-- Department - Read-only, inherited from container -->
56+
<div class="form-group">
57+
<label for="department_display">Department</label>
58+
<input type="text" class="form-control bg-light" id="department_display"
59+
readonly="readonly" placeholder="Select a container first"/>
60+
<input type="hidden" name="department_id" id="department_id" value=""/>
61+
<small class="form-text text-muted">
62+
Department is inherited from the selected container
63+
</small>
64+
</div>
8765

8866
<div class="form-group">
8967
<label for="file_category">File Category</label>
9068
<select class="form-control" id="file_category" name="file_category">
9169
<option value="">-- Select Category --</option>
92-
<option value="permanent">Permanent</option>
93-
<option value="temporary">Temporary</option>
94-
<option value="archived">Archived</option>
95-
<option value="active" selected="selected">Active</option>
70+
<t t-foreach="file_categories or []" t-as="cat">
71+
<option t-att-value="cat[0]"><t t-esc="cat[1]"/></option>
72+
</t>
9673
</select>
9774
<small class="form-text text-muted">
9875
Categorize this file for organizational purposes
9976
</small>
10077
</div>
10178

79+
<!-- File State - Read-only, defaults to container state or 'pending' -->
10280
<div class="form-group">
103-
<label for="state">File State</label>
104-
<select class="form-control" id="state" name="state">
105-
<option value="draft">Draft</option>
106-
<option value="active" selected="selected">Active</option>
107-
<option value="archived">Archived</option>
108-
</select>
81+
<label for="state_display">File State</label>
82+
<input type="text" class="form-control bg-light" id="state_display"
83+
value="Pending" readonly="readonly"/>
84+
<small class="form-text text-muted">
85+
File state is set automatically. It will change to "In Storage" when received at warehouse.
86+
</small>
10987
</div>
11088

111-
<div class="row">
112-
<div class="col-md-6">
113-
<div class="form-group">
114-
<label for="date_created">Date Created</label>
115-
<input type="date" class="form-control" id="date_created" name="date_created"/>
116-
<small class="form-text text-muted">
117-
When this file was originally created
118-
</small>
119-
</div>
120-
</div>
121-
<div class="col-md-6">
122-
<div class="form-group">
123-
<label for="received_date">Date Received</label>
124-
<input type="date" class="form-control" id="received_date" name="received_date"/>
125-
<small class="form-text text-muted">
126-
When this file was received into custody
127-
</small>
128-
</div>
129-
</div>
89+
<!-- Only Date Created - defaults to today, Date Received is set by technician -->
90+
<div class="form-group">
91+
<label for="date_created">Date Created</label>
92+
<input type="date" class="form-control" id="date_created" name="date_created"
93+
t-att-value="today"/>
94+
<small class="form-text text-muted">
95+
When this file was originally created (defaults to today)
96+
</small>
13097
</div>
98+
<!-- Date Received hidden - set when technician scans container to work order -->
13199

132100
<div class="form-group">
133101
<label for="description">Description</label>
134102
<textarea class="form-control" id="description" name="description" rows="3"
135103
placeholder="Optional: Describe the contents of this file"></textarea>
136104
</div>
137105

138-
<!-- Temporary Location Info (Customer fills this - we assign real stock location via scan) -->
106+
<!-- Temporary Location Info -->
139107
<div class="alert alert-info mt-3">
140108
<h6><i class="fa fa-info-circle"></i> Location Information</h6>
141109
<p class="mb-0 small">
142-
This file will be assigned a temporary location at your address/department.
143-
Our staff will assign the actual warehouse location when the file is scanned into inventory.
110+
This file will be assigned a temporary barcode for tracking.
111+
Our staff will assign the permanent barcode and warehouse location when the file is scanned into inventory.
144112
</p>
145113
</div>
146114

@@ -153,6 +121,26 @@
153121
</a>
154122
</div>
155123
</form>
124+
125+
<!-- JavaScript to update department from container -->
126+
<script>
127+
function updateDepartmentFromContainer(select) {
128+
var option = select.options[select.selectedIndex];
129+
var deptName = option.getAttribute('data-department') || '';
130+
var deptId = option.getAttribute('data-department-id') || '';
131+
132+
document.getElementById('department_display').value = deptName || 'No department assigned';
133+
document.getElementById('department_id').value = deptId;
134+
}
135+
136+
// Initialize on page load if container is pre-selected
137+
document.addEventListener('DOMContentLoaded', function() {
138+
var containerSelect = document.getElementById('container_id');
139+
if (containerSelect.value) {
140+
updateDepartmentFromContainer(containerSelect);
141+
}
142+
});
143+
</script>
156144

157145
<!-- Help Section -->
158146
<div class="mt-4 pt-3 border-top">
@@ -161,9 +149,9 @@
161149
</h6>
162150
<ul class="small text-muted">
163151
<li><strong>File Name:</strong> Enter a descriptive name for easy identification</li>
164-
<li><strong>Barcode:</strong> Scan or manually enter barcode if available</li>
165152
<li><strong>Container:</strong> Select the physical container this file belongs to</li>
166-
<li><strong>Department:</strong> Assign to appropriate department</li>
153+
<li><strong>Department:</strong> Automatically set from the container's department</li>
154+
<li><strong>Category:</strong> Choose the type of records in this file</li>
167155
</ul>
168156
</div>
169157
</div>

0 commit comments

Comments
 (0)