Skip to content

Commit c1f8332

Browse files
author
John75SunCity
committed
fix: Add sudo() for portal inventory counts and staging location creation
- Inventory counts route: Added sudo() for all model search_count calls so portal users can see their container/file/document/temp/location counts - Staging location creation: Added sudo() so portal users can create customer.staging.location records - Stock location model: Added sudo() to _create_or_update_stock_location so the auto-created stock.location records work for portal users Portal users don't have direct access to records.container, records.file, records.document, temp.inventory, or stock.location models - they need sudo() with proper domain filtering by partner_id for security.
1 parent 41af572 commit c1f8332

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

records_management/controllers/portal.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5425,18 +5425,18 @@ def portal_inventory_counts(self, **kw):
54255425
if accessible_departments:
54265426
domain.append(('department_id', 'in', accessible_departments))
54275427

5428-
# Get counts for all inventory types
5429-
containers_count = request.env['records.container'].search_count(domain)
5430-
files_count = request.env['records.file'].search_count(domain)
5431-
documents_count = request.env['records.document'].search_count(domain)
5428+
# Get counts for all inventory types (use sudo for portal access)
5429+
containers_count = request.env['records.container'].sudo().search_count(domain)
5430+
files_count = request.env['records.file'].sudo().search_count(domain)
5431+
documents_count = request.env['records.document'].sudo().search_count(domain)
54325432

54335433
# Temp inventory count
54345434
temp_domain = [('partner_id', '=', partner.commercial_partner_id.id)]
5435-
temp_count = request.env['temp.inventory'].search_count(temp_domain)
5435+
temp_count = request.env['temp.inventory'].sudo().search_count(temp_domain)
54365436

54375437
# Customer staging locations count
54385438
locations_domain = [('partner_id', '=', partner.commercial_partner_id.id)]
5439-
locations_count = request.env['customer.staging.location'].search_count(locations_domain)
5439+
locations_count = request.env['customer.staging.location'].sudo().search_count(locations_domain)
54405440

54415441
return {
54425442
'containers': containers_count,
@@ -6586,8 +6586,8 @@ def portal_staging_location_create(self, **post):
65866586
partner = request.env.user.partner_id.commercial_partner_id
65876587

65886588
if request.httprequest.method == 'POST':
6589-
# Create location
6590-
StagingLocation = request.env['customer.staging.location']
6589+
# Create location (use sudo for portal users to create staging locations)
6590+
StagingLocation = request.env['customer.staging.location'].sudo()
65916591

65926592
vals = {
65936593
'name': post.get('name'),

records_management/models/customer_staging_location.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,13 @@ def _create_or_update_stock_location(self):
277277
}
278278

279279
if self.stock_location_id:
280-
# Update existing
281-
self.stock_location_id.write(location_vals)
280+
# Update existing (use sudo to bypass stock.location permissions)
281+
self.stock_location_id.sudo().write(location_vals)
282282
else:
283-
# Create new
284-
stock_location = self.env['stock.location'].create(location_vals)
285-
self.stock_location_id = stock_location.id
283+
# Create new (use sudo - portal users can create staging locations
284+
# but don't have direct stock.location create permissions)
285+
stock_location = self.env['stock.location'].sudo().create(location_vals)
286+
self.sudo().stock_location_id = stock_location.id
286287

287288
# ============================================================================
288289
# ACTIONS

0 commit comments

Comments
 (0)