This commit is contained in:
XuanHuyen
2025-04-10 16:41:39 +07:00
parent 545e89ff1e
commit 049d002eb9
3 changed files with 44 additions and 4 deletions
+42
View File
@@ -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)
@@ -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()
@@ -35,8 +35,7 @@ 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;