diff --git a/custom_ms_office_preview/README.md b/custom_ms_office_preview/README.md new file mode 100644 index 0000000..73b0ee1 --- /dev/null +++ b/custom_ms_office_preview/README.md @@ -0,0 +1,42 @@ +# Custom MS Office Preview + +## Overview +This module allows users to preview Microsoft Office files (such as Word, Excel, and PowerPoint) directly within the Odoo interface using the Microsoft Online Viewer. It extends the attachment model to recognize Office file types and provides a seamless viewing experience by embedding the Office Viewer in the file preview interface. + +## Features +- Preview Microsoft Office files (Word, Excel, PowerPoint) within Odoo. +- Extends the attachment model to recognize Office file types. +- Embeds the Microsoft Online Viewer in the file preview interface. + +## Installation +1. Clone the repository into your Odoo addons directory: + ```sh + git clone https://github.com/quodoo/odoo_addons.git + ``` +2. Update your Odoo configuration file to include the new module directory. +3. Restart the Odoo server. +4. Install the "Custom MS Office Preview" module from the Apps menu. + +## Usage +1. Upload a Microsoft Office file (Word, Excel, PowerPoint) as an attachment in Odoo. +2. Open the attachment to preview it using the Microsoft Online Viewer. + +## Configuration +No additional configuration is required. + +## Technical Details +- **Controller**: Handles the public URL for previewing attachments. +- **JavaScript**: Patches the attachment model to recognize Office file types and generate the appropriate preview URL. +- **XML**: Extends the file viewer templates to embed the Microsoft Online Viewer. + +## Warning +The controller makes all attachments public. You can create a guest token for a public link that allows the Microsoft preview to show the attachment. If you need help, contact me. + +## Author +### Quang Trinh +![Contact me on Zalo](../zalo.jpg) + +## Support +If you find this module helpful, please consider buying me a coffee to keep me motivated. + +![Buy me a coffee](../tpbank_qr.jpg) \ No newline at end of file diff --git a/custom_ms_office_preview/controllers/main.py b/custom_ms_office_preview/controllers/main.py index 2ea75ec..e78e60e 100644 --- a/custom_ms_office_preview/controllers/main.py +++ b/custom_ms_office_preview/controllers/main.py @@ -15,7 +15,6 @@ class AttachmentPreviewController(http.Controller): attachment_sudo = request.env["ir.attachment"].sudo().browse(attachment_id) _logger.debug(f"✅ Guest env applied {attachment_sudo}") - attachment_sudo.public = True if not attachment_sudo.exists(): raise NotFound() diff --git a/custom_ms_office_preview/static/src/js/attachment_model_patch.js b/custom_ms_office_preview/static/src/js/attachment_model_patch.js index c142005..1ec9d5f 100644 --- a/custom_ms_office_preview/static/src/js/attachment_model_patch.js +++ b/custom_ms_office_preview/static/src/js/attachment_model_patch.js @@ -35,10 +35,9 @@ patch(Attachment.prototype, { if (this.isMsOfficeDocument) { const route = url(this.urlRoute, this.urlQueryParams); const encodedRoute = encodeURIComponent(route); - console.log("route", route); - console.log("encodedRoute", encodedRoute); + console.log("link preview: ", `https://view.officeapps.live.com/op/embed.aspx?src=${encodedRoute}&wdStartOn=1&wdPrint=1&wdEmbedCode=0`); return `https://view.officeapps.live.com/op/embed.aspx?src=${encodedRoute}&wdStartOn=1&wdPrint=1&wdEmbedCode=0`; } return super.defaultSource; }, -}); +}); \ No newline at end of file