72 lines
2.4 KiB
Python
72 lines
2.4 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 FpNcr(models.Model):
|
|
"""Bridge extension: expose Documents workspace on NCRs.
|
|
|
|
Adds a reverse link to any `documents.document` records that were
|
|
created by the bridge override on `ir.attachment`, plus a smart
|
|
button action that opens the filtered Documents kanban for the
|
|
current NCR.
|
|
"""
|
|
_inherit = 'fusion.plating.ncr'
|
|
|
|
x_fc_document_ids = fields.Many2many(
|
|
'documents.document',
|
|
'fp_bridge_ncr_document_rel',
|
|
'ncr_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 NCR.',
|
|
)
|
|
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.ncr'),
|
|
('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
|