folder rename
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
_FOLDER_XMLID = 'fusion_plating_bridge_documents.documents_folder_plating_quality'
|
||||
|
||||
|
||||
class FpCapa(models.Model):
|
||||
"""Bridge extension: expose Documents workspace on CAPAs."""
|
||||
_inherit = 'fusion.plating.capa'
|
||||
|
||||
x_fc_document_ids = fields.Many2many(
|
||||
'documents.document',
|
||||
'fp_bridge_capa_document_rel',
|
||||
'capa_id',
|
||||
'document_id',
|
||||
string='Quality Documents',
|
||||
compute='_compute_x_fc_document_ids',
|
||||
store=False,
|
||||
help='Documents in the Plating — Quality workspace mirrored from '
|
||||
'attachments on this CAPA.',
|
||||
)
|
||||
x_fc_document_count = fields.Integer(
|
||||
string='# Documents',
|
||||
compute='_compute_x_fc_document_ids',
|
||||
store=False,
|
||||
)
|
||||
|
||||
@api.depends('message_attachment_count')
|
||||
def _compute_x_fc_document_ids(self):
|
||||
Document = self.env.get('documents.document') if 'documents.document' in self.env else None
|
||||
for rec in self:
|
||||
if not Document:
|
||||
rec.x_fc_document_ids = False
|
||||
rec.x_fc_document_count = 0
|
||||
continue
|
||||
docs = Document.sudo().search([
|
||||
('attachment_id.res_model', '=', 'fusion.plating.capa'),
|
||||
('attachment_id.res_id', '=', rec.id),
|
||||
])
|
||||
rec.x_fc_document_ids = docs
|
||||
rec.x_fc_document_count = len(docs)
|
||||
|
||||
def action_view_documents(self):
|
||||
self.ensure_one()
|
||||
folder_id = self._get_default_folder_id()
|
||||
ctx = {}
|
||||
if folder_id:
|
||||
ctx['default_folder_id'] = folder_id
|
||||
ctx['searchpanel_default_folder_id'] = folder_id
|
||||
return {
|
||||
'name': _('Quality Documents'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'documents.document',
|
||||
'view_mode': 'kanban,list,form',
|
||||
'domain': [('id', 'in', self.x_fc_document_ids.ids)],
|
||||
'context': ctx,
|
||||
}
|
||||
|
||||
def _get_default_folder_id(self):
|
||||
folder = self.env.ref(_FOLDER_XMLID, raise_if_not_found=False)
|
||||
return folder.id if folder else 0
|
||||
Reference in New Issue
Block a user