85 lines
3.2 KiB
Python
85 lines
3.2 KiB
Python
# -*- 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 FpDocControl(models.Model):
|
|
"""Bridge extension: expose Documents workspace on Controlled Documents.
|
|
|
|
Doc Control already carries a native ``attachment_ids`` Many2many; the
|
|
bridge additionally exposes the `documents.document` mirror so users can
|
|
jump straight into the Documents app to use its preview, tag, share,
|
|
and lock features.
|
|
"""
|
|
_inherit = 'fusion.plating.doc.control'
|
|
|
|
x_fc_document_ids = fields.Many2many(
|
|
'documents.document',
|
|
'fp_bridge_doc_control_document_rel',
|
|
'doc_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 controlled document record.',
|
|
)
|
|
x_fc_document_count = fields.Integer(
|
|
string='# Documents',
|
|
compute='_compute_x_fc_document_ids',
|
|
store=False,
|
|
)
|
|
|
|
@api.depends('attachment_ids', '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
|
|
# Pull in both chatter attachments (matched via res_model/res_id) and
|
|
# any documents whose underlying ir.attachment is in the native
|
|
# attachment_ids M2m on this controlled document record.
|
|
native_attachment_ids = rec.attachment_ids.ids
|
|
if native_attachment_ids:
|
|
domain = [
|
|
'|',
|
|
'&', ('attachment_id.res_model', '=', 'fusion.plating.doc.control'),
|
|
('attachment_id.res_id', '=', rec.id),
|
|
('attachment_id', 'in', native_attachment_ids),
|
|
]
|
|
else:
|
|
domain = [
|
|
('attachment_id.res_model', '=', 'fusion.plating.doc.control'),
|
|
('attachment_id.res_id', '=', rec.id),
|
|
]
|
|
docs = Document.sudo().search(domain)
|
|
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
|