changes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
{
|
||||
"name": "Fusion PDF Preview",
|
||||
"version": "19.0.2.0.0",
|
||||
"version": "19.0.2.1.0",
|
||||
"depends": ["web"],
|
||||
"author": "Nexa Systems Inc",
|
||||
"category": "web",
|
||||
@@ -41,6 +41,7 @@ Key Features:
|
||||
"assets": {
|
||||
"web.assets_backend": [
|
||||
"fusion_pdf_preview/static/src/js/pdf_preview.js",
|
||||
"fusion_pdf_preview/static/src/js/open_attachment_action.js",
|
||||
"fusion_pdf_preview/static/src/js/user_menu.js",
|
||||
"fusion_pdf_preview/static/src/xml/pdf_viewer_dialog.xml",
|
||||
],
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
from . import res_users
|
||||
from . import ir_http
|
||||
from . import ir_actions_report
|
||||
from . import ir_attachment
|
||||
from . import res_config_settings
|
||||
from . import preview_log
|
||||
|
||||
48
fusion_pdf_preview/models/ir_attachment.py
Normal file
48
fusion_pdf_preview/models/ir_attachment.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# -*- 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',
|
||||
}
|
||||
42
fusion_pdf_preview/static/src/js/open_attachment_action.js
Normal file
42
fusion_pdf_preview/static/src/js/open_attachment_action.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { openPDFViewer } from "./pdf_preview";
|
||||
|
||||
/**
|
||||
* Client action: open an ir.attachment in the PDF preview dialog.
|
||||
*
|
||||
* Python callers return:
|
||||
* {
|
||||
* 'type': 'ir.actions.client',
|
||||
* 'tag': 'fusion_pdf_preview.open_attachment',
|
||||
* 'params': {
|
||||
* 'attachment_id': <int>,
|
||||
* 'title': <str>, // optional, defaults to "Document"
|
||||
* 'model_name': <str>, // optional, for audit log
|
||||
* 'record_ids': <str>, // optional, comma-sep for audit log
|
||||
* 'report_name': <str>, // optional, for audit log
|
||||
* },
|
||||
* }
|
||||
*
|
||||
* Non-PDF attachments fall back to opening in a new browser tab — the
|
||||
* preview dialog only renders PDF. ZPL labels (text/plain) should NOT
|
||||
* use this action; route those through the direct download act_url.
|
||||
*/
|
||||
registry.category("actions").add(
|
||||
"fusion_pdf_preview.open_attachment",
|
||||
async (env, action) => {
|
||||
const params = action.params || {};
|
||||
const attachmentId = params.attachment_id;
|
||||
if (!attachmentId) {
|
||||
return;
|
||||
}
|
||||
const title = params.title || "Document";
|
||||
const url = `/web/content/${attachmentId}`;
|
||||
openPDFViewer(env, url, title, {
|
||||
modelName: params.model_name || "",
|
||||
recordIds: params.record_ids || "",
|
||||
reportName: params.report_name || "",
|
||||
});
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user