49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import models
|
|
|
|
|
|
class IrAttachment(models.Model):
|
|
_inherit = "ir.attachment"
|
|
|
|
def action_fusion_preview(self, title=None, model_name=None, record_ids=None):
|
|
"""Return the right action to "view" this attachment.
|
|
|
|
- PDF attachments → fusion_pdf_preview's client dialog (preview
|
|
+ print + download all in one place, with audit log).
|
|
- Anything else (ZPL, CSV, XML, images, etc.) → legacy
|
|
new-tab/download URL since the PDF viewer can't render them.
|
|
|
|
Drop-in replacement for the common pattern:
|
|
return {
|
|
'type': 'ir.actions.act_url',
|
|
'url': '/web/content/%s?download=true' % att.id,
|
|
'target': 'new',
|
|
}
|
|
|
|
Use as: return att.action_fusion_preview(title='My Doc')
|
|
|
|
See CLAUDE.md "PDF Preview" for the full contract.
|
|
"""
|
|
self.ensure_one()
|
|
is_pdf = (
|
|
(self.mimetype or '').lower() == 'application/pdf'
|
|
or (self.name or '').lower().endswith('.pdf')
|
|
)
|
|
if is_pdf:
|
|
return {
|
|
'type': 'ir.actions.client',
|
|
'tag': 'fusion_pdf_preview.open_attachment',
|
|
'params': {
|
|
'attachment_id': self.id,
|
|
'title': title or self.name or 'Document',
|
|
'model_name': model_name or '',
|
|
'record_ids': str(record_ids) if record_ids else '',
|
|
},
|
|
}
|
|
return {
|
|
'type': 'ir.actions.act_url',
|
|
'url': '/web/content/%s?download=true' % self.id,
|
|
'target': 'new',
|
|
}
|