diff --git a/many2many_attachment_preview/README.rst b/many2many_attachment_preview/README.rst new file mode 100755 index 000000000..e62fcf38e --- /dev/null +++ b/many2many_attachment_preview/README.rst @@ -0,0 +1,49 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg + :target: https://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +Many2Many Attachment Preview +============================ +This Module will help to preview the attachments in Many2Many fields. + +Configuration +============= +* No additional configurations needed +Company +------- +* `Cybrosys Techno Solutions `__ + +License +======= +GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) +(https://www.gnu.org/licenses/agpl-3.0-standalone.html) + +Credits +------- +* Developer: (V16) Ajith V, + (V15) Shonima, Contact: odoo@cybrosys.com + +Contacts +-------- +* Mail Contact : odoo@cybrosys.com +* Website : https://cybrosys.com + +Bug Tracker +----------- +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your +issue has already been reported. + +Maintainer +========== +.. image:: https://cybrosys.com/images/logo.png + :target: https://cybrosys.com + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit `Our Website `__ + +Further information +=================== +HTML Description: ``__ + + diff --git a/many2many_attachment_preview/__init__.py b/many2many_attachment_preview/__init__.py new file mode 100644 index 000000000..895d63311 --- /dev/null +++ b/many2many_attachment_preview/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Ajith() +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# +from . import models diff --git a/many2many_attachment_preview/__manifest__.py b/many2many_attachment_preview/__manifest__.py new file mode 100644 index 000000000..db84d37f0 --- /dev/null +++ b/many2many_attachment_preview/__manifest__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Ajith() +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# +{ + 'name': "Many2Many Attachment Preview", + 'version': '16.0.1.0.0', + 'summary': """Preview the attachment in Many2Many field""", + 'description': """"This module helps you to preview the attachments in + Many2Many fields.""", + 'category': 'Uncategorized', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'website': "http://www.cybrosys.com", + 'depends': ['base', 'sale_management'], + 'data': ['views/sale_order_views.xml'], + 'assets': { + 'web.assets_backend': [ + 'many2many_attachment_preview/static/src/js/attachment_preview.js', + 'many2many_attachment_preview/static/src/xml/attachment_preview.xml', + 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.6/dist/jquery.fancybox.min.css', + 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.6/dist/jquery.fancybox.min.js' + ], + }, + 'license': 'AGPL-3', + 'images': ['static/description/banner.png'], + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/many2many_attachment_preview/doc/RELEASE_NOTES.md b/many2many_attachment_preview/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..7b6a01b7f --- /dev/null +++ b/many2many_attachment_preview/doc/RELEASE_NOTES.md @@ -0,0 +1,6 @@ +## Module + +#### 29.08.2024 +#### Version 16.0.1.0.0 +#### ADD +- Initial Commit for Many2Many Attachment Preview diff --git a/many2many_attachment_preview/models/__init__.py b/many2many_attachment_preview/models/__init__.py new file mode 100644 index 000000000..e67dce5bf --- /dev/null +++ b/many2many_attachment_preview/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Ajith() +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# +from . import sale_order diff --git a/many2many_attachment_preview/models/sale_order.py b/many2many_attachment_preview/models/sale_order.py new file mode 100644 index 000000000..bc9057cb6 --- /dev/null +++ b/many2many_attachment_preview/models/sale_order.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Ajith() +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# +from odoo import fields, models + + +class SaleOrder(models.Model): + """Inherited sale. order class to add a new field for attachments""" + _inherit = 'sale.order' + + attachment_ids = fields.Many2many( + comodel_name='ir.attachment', + string="Attachments", help="Add Multiple attachment file") diff --git a/many2many_attachment_preview/static/description/assets/icons/check.png b/many2many_attachment_preview/static/description/assets/icons/check.png new file mode 100644 index 000000000..c8e85f51d Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/check.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/chevron.png b/many2many_attachment_preview/static/description/assets/icons/chevron.png new file mode 100644 index 000000000..2089293d6 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/chevron.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/cogs.png b/many2many_attachment_preview/static/description/assets/icons/cogs.png new file mode 100644 index 000000000..95d0bad62 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/cogs.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/consultation.png b/many2many_attachment_preview/static/description/assets/icons/consultation.png new file mode 100644 index 000000000..8319d4baa Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/consultation.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/ecom-black.png b/many2many_attachment_preview/static/description/assets/icons/ecom-black.png new file mode 100644 index 000000000..a9385ff13 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/ecom-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/education-black.png b/many2many_attachment_preview/static/description/assets/icons/education-black.png new file mode 100644 index 000000000..3eb09b27b Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/education-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/hotel-black.png b/many2many_attachment_preview/static/description/assets/icons/hotel-black.png new file mode 100644 index 000000000..130f613be Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/hotel-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/license.png b/many2many_attachment_preview/static/description/assets/icons/license.png new file mode 100644 index 000000000..a5869797e Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/license.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/lifebuoy.png b/many2many_attachment_preview/static/description/assets/icons/lifebuoy.png new file mode 100644 index 000000000..658d56ccc Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/lifebuoy.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/logo.png b/many2many_attachment_preview/static/description/assets/icons/logo.png new file mode 100644 index 000000000..478462d3e Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/logo.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/manufacturing-black.png b/many2many_attachment_preview/static/description/assets/icons/manufacturing-black.png new file mode 100644 index 000000000..697eb0e9f Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/manufacturing-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/pos-black.png b/many2many_attachment_preview/static/description/assets/icons/pos-black.png new file mode 100644 index 000000000..97c0f90c1 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/pos-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/puzzle.png b/many2many_attachment_preview/static/description/assets/icons/puzzle.png new file mode 100644 index 000000000..65cf854e7 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/puzzle.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/restaurant-black.png b/many2many_attachment_preview/static/description/assets/icons/restaurant-black.png new file mode 100644 index 000000000..4a35eb939 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/restaurant-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/service-black.png b/many2many_attachment_preview/static/description/assets/icons/service-black.png new file mode 100644 index 000000000..301ab51cb Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/service-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/trading-black.png b/many2many_attachment_preview/static/description/assets/icons/trading-black.png new file mode 100644 index 000000000..9398ba2f1 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/trading-black.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/training.png b/many2many_attachment_preview/static/description/assets/icons/training.png new file mode 100644 index 000000000..884ca024d Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/training.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/update.png b/many2many_attachment_preview/static/description/assets/icons/update.png new file mode 100644 index 000000000..ecbc5a01a Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/update.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/user.png b/many2many_attachment_preview/static/description/assets/icons/user.png new file mode 100644 index 000000000..6ffb23d9f Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/user.png differ diff --git a/many2many_attachment_preview/static/description/assets/icons/wrench.png b/many2many_attachment_preview/static/description/assets/icons/wrench.png new file mode 100644 index 000000000..6c04dea0f Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/icons/wrench.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/categories.png b/many2many_attachment_preview/static/description/assets/misc/categories.png new file mode 100644 index 000000000..bedf1e0b1 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/categories.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/check-box.png b/many2many_attachment_preview/static/description/assets/misc/check-box.png new file mode 100644 index 000000000..42caf24b9 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/check-box.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/compass.png b/many2many_attachment_preview/static/description/assets/misc/compass.png new file mode 100644 index 000000000..d5fed8faa Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/compass.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/corporate.png b/many2many_attachment_preview/static/description/assets/misc/corporate.png new file mode 100644 index 000000000..2eb13edbf Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/corporate.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/customer-support.png b/many2many_attachment_preview/static/description/assets/misc/customer-support.png new file mode 100644 index 000000000..79efc72ed Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/customer-support.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/cybrosys-logo.png b/many2many_attachment_preview/static/description/assets/misc/cybrosys-logo.png new file mode 100644 index 000000000..cc3cc0ccf Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/cybrosys-logo.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/features.png b/many2many_attachment_preview/static/description/assets/misc/features.png new file mode 100644 index 000000000..b41769f77 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/features.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/logo.png b/many2many_attachment_preview/static/description/assets/misc/logo.png new file mode 100644 index 000000000..478462d3e Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/logo.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/pictures.png b/many2many_attachment_preview/static/description/assets/misc/pictures.png new file mode 100644 index 000000000..56d255fe9 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/pictures.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/pie-chart.png b/many2many_attachment_preview/static/description/assets/misc/pie-chart.png new file mode 100644 index 000000000..426e05244 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/pie-chart.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/right-arrow.png b/many2many_attachment_preview/static/description/assets/misc/right-arrow.png new file mode 100644 index 000000000..730984a06 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/right-arrow.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/star.png b/many2many_attachment_preview/static/description/assets/misc/star.png new file mode 100644 index 000000000..2eb9ab29f Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/star.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/support.png b/many2many_attachment_preview/static/description/assets/misc/support.png new file mode 100644 index 000000000..4f18b8b82 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/support.png differ diff --git a/many2many_attachment_preview/static/description/assets/misc/whatsapp.png b/many2many_attachment_preview/static/description/assets/misc/whatsapp.png new file mode 100644 index 000000000..d513a5356 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/misc/whatsapp.png differ diff --git a/many2many_attachment_preview/static/description/assets/modules/budget_image.png b/many2many_attachment_preview/static/description/assets/modules/budget_image.png new file mode 100644 index 000000000..5a1a86acf Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/modules/budget_image.png differ diff --git a/many2many_attachment_preview/static/description/assets/modules/credit_image.png b/many2many_attachment_preview/static/description/assets/modules/credit_image.png new file mode 100644 index 000000000..af9c0df87 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/modules/credit_image.png differ diff --git a/many2many_attachment_preview/static/description/assets/modules/employee_image.png b/many2many_attachment_preview/static/description/assets/modules/employee_image.png new file mode 100644 index 000000000..c0dafb60f Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/modules/employee_image.png differ diff --git a/many2many_attachment_preview/static/description/assets/modules/export_image.png b/many2many_attachment_preview/static/description/assets/modules/export_image.png new file mode 100644 index 000000000..a3a248601 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/modules/export_image.png differ diff --git a/many2many_attachment_preview/static/description/assets/modules/gantt_image.png b/many2many_attachment_preview/static/description/assets/modules/gantt_image.png new file mode 100644 index 000000000..74c1033ca Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/modules/gantt_image.png differ diff --git a/many2many_attachment_preview/static/description/assets/modules/quotation_image.png b/many2many_attachment_preview/static/description/assets/modules/quotation_image.png new file mode 100644 index 000000000..0cb630dfe Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/modules/quotation_image.png differ diff --git a/many2many_attachment_preview/static/description/assets/screenshots/1.png b/many2many_attachment_preview/static/description/assets/screenshots/1.png new file mode 100644 index 000000000..06bae7cfd Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/screenshots/1.png differ diff --git a/many2many_attachment_preview/static/description/assets/screenshots/2.png b/many2many_attachment_preview/static/description/assets/screenshots/2.png new file mode 100644 index 000000000..d017e3508 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/screenshots/2.png differ diff --git a/many2many_attachment_preview/static/description/assets/screenshots/hero.gif b/many2many_attachment_preview/static/description/assets/screenshots/hero.gif new file mode 100644 index 000000000..dabf3e3d3 Binary files /dev/null and b/many2many_attachment_preview/static/description/assets/screenshots/hero.gif differ diff --git a/many2many_attachment_preview/static/description/banner.png b/many2many_attachment_preview/static/description/banner.png new file mode 100644 index 000000000..56127ff06 Binary files /dev/null and b/many2many_attachment_preview/static/description/banner.png differ diff --git a/many2many_attachment_preview/static/description/icon.png b/many2many_attachment_preview/static/description/icon.png new file mode 100644 index 000000000..475d79be7 Binary files /dev/null and b/many2many_attachment_preview/static/description/icon.png differ diff --git a/many2many_attachment_preview/static/description/index.html b/many2many_attachment_preview/static/description/index.html new file mode 100644 index 000000000..85c3dd80d --- /dev/null +++ b/many2many_attachment_preview/static/description/index.html @@ -0,0 +1,622 @@ +
+ +
+ +
+
+ Community +
+
+ Enterprise +
+
+ Odoo.sh +
+
+
+ + + +

+ Many2Many Attachment Preview

+

+ Preview the Attachments.

+ + + +
+ + +
+
+ +
+

+ Explore This + Module

+
+ + + + +
+
+ +
+

+ Overview +

+
+
+
+ This module helps you preview of the attachments (like pdf, png, jpg + etc.) which are uploaded in a Many2Many field. +
+
+ + + +
+
+ +
+

+ Features +

+
+
+
+
+ + Community & Enterprise Support +

+ Available in Odoo 16.0 Community and Enterprise.

+
+
+ + Available pdf, png, jpg (image formats) etc. +

+ Available pdf, png, jpg (image formats) etc.

+
+
+
+ + + +
+
+ +
+

+ Screenshots +

+
+
+
+ +
+

+ Can add multiple attachments

+ +
+ +
+

+ Clicking on attachment,we can preview the document.

+ +
+
+
+ + + +
+
+ +
+

+ Related + Products +

+
+
+
+ +
+
+ + + + +
+
+ +
+

+ Our Services +

+
+ +
+
+
+
+ +
+
+ Odoo + Customization
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Support
+
+ + +
+
+ +
+
+ Hire + Odoo + Developer
+
+ +
+
+ +
+
+ Odoo + Integration
+
+ +
+
+ +
+
+ Odoo + Migration
+
+ + +
+
+ +
+
+ Odoo + Consultancy
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Licensing Consultancy
+
+
+ +
+ + + + + +
+
+ +
+

+ Our + Industries +

+
+ +
+
+
+
+ +
+ Trading +
+

+ Easily procure + and + sell your products

+
+
+ +
+
+ +
+ POS +
+

+ Easy + configuration + and convivial experience

+
+
+ +
+
+ +
+ Education +
+

+ A platform for + educational management

+
+
+ +
+
+ +
+ Manufacturing +
+

+ Plan, track and + schedule your operations

+
+
+ +
+
+ +
+ E-commerce & Website +
+

+ Mobile + friendly, + awe-inspiring product pages

+
+
+ +
+
+ +
+ Service Management +
+

+ Keep track of + services and invoice

+
+
+ +
+
+ +
+ Restaurant +
+

+ Run your bar or + restaurant methodically

+
+
+ +
+
+ +
+ Hotel Management +
+

+ An + all-inclusive + hotel management application

+
+
+
+
+ + + + +
+
+ +
+

+ Support +

+
+
+
+
+
+
+ +
+
+

Need Help?

+

Got questions or need help? + Get in touch.

+ +

+ odoo@cybrosys.com

+
+
+
+
+
+
+
+ +
+
+

WhatsApp

+

Say hi to us on WhatsApp!

+ +

+ +91 86068 + 27707

+
+
+
+
+
+
+
+ +
+
+
+ \ No newline at end of file diff --git a/many2many_attachment_preview/static/src/js/attachment_preview.js b/many2many_attachment_preview/static/src/js/attachment_preview.js new file mode 100644 index 000000000..aca47766e --- /dev/null +++ b/many2many_attachment_preview/static/src/js/attachment_preview.js @@ -0,0 +1,134 @@ +/** @odoo-module **/ +import {registry} from "@web/core/registry"; +import {Component, useState} from "@odoo/owl"; +import {FileInput} from "@web/core/file_input/file_input"; +import {standardFieldProps} from "@web/views/fields/standard_field_props"; +import {useService} from "@web/core/utils/hooks"; +import {useX2ManyCrud} from "@web/views/fields/relational_utils"; + +/** + * The Many2ManyAttachmentPreview component is designed to manage the preview and handling + * of many2many fields that contain file attachments. It allows users to upload, preview, + * and remove files associated with a record. + * + * @class + * @extends Component + * + * @prop {Object} props - The props object includes all the standard field properties, + * as well as additional properties such as acceptedFileExtensions, + * className, and numberOfFiles. + * @prop {String} props.acceptedFileExtensions - (Optional) A string defining the accepted file + * extensions for uploads. + * @prop {String} props.className - (Optional) A string defining any additional CSS classes + * to be applied. + * @prop {Number} props.numberOfFiles - (Optional) A number representing the maximum number of + * files allowed. + * + * @setup + * @method setup - Initializes services and state for the component, including ORM service, + * notification service, and operations for managing many2many CRUD. + * + * @state {Object} state - Contains component state, including a flag for internal logic handling. + * + * @getter uploadText - Retrieves the label for the upload button, typically the field's label. + * + * @getter files - Returns a list of files associated with the record, including their IDs + * and other relevant data. + * + * @method getUrl(id) - Constructs the URL to access a file attachment by its ID. + * @param {Number} id - The ID of the file attachment. + * @returns {String} - The URL for the file attachment. + * + * @method getExtension(file) - Extracts the file extension from a file's name. + * @param {Object} file - The file object. + * @returns {String} - The file extension. + * + * @method onFileUploaded(files) - Handles the logic after files are uploaded, + * including error handling and saving the records. + * @param {Array} files - An array of uploaded files. + * @returns {Promise} + * + * @method onFileRemove(deleteId) - Handles the logic for removing a file by its ID, + * including updating the records. + * @param {Number} deleteId - The ID of the file to be removed. + * @returns {Promise} + * + * @supportedTypes - Specifies that this component supports "many2many" fields. + * + * @fieldsToFetch - Defines the fields to be fetched from the related records, such as + * 'name' and 'mimetype'. + * + * @registry.category("fields").add("many2many_attachment_preview", Many2ManyAttachmentPreview) + * - Registers the component in the Odoo registry. + */ + +export class Many2ManyAttachmentPreview extends Component { + static template = 'many2many_attachment_preview.Many2ManyImageField' + static components = { + FileInput, + }; + static props = { + ...standardFieldProps, + acceptedFileExtensions: {type: String, optional: true}, + className: {type: String, optional: true}, + numberOfFiles: {type: Number, optional: true}, + }; + + setup() { + this.orm = useService("orm"); + this.notification = useService("notification"); + this.operations = useX2ManyCrud(() => this.props.value, true); + this.state = useState({ + flag: false, + }); + } + + get uploadText() { + return this.props.record.fields[this.props.name].string; + } + + get files() { + return this.props.record.data[this.props.name].records.map((record) => { + return { + ...record.data, + id: record.resId, + }; + }); + } + + getUrl(id) { + return "/web/content/ir.attachment/" + id + "/datas"; + } + + getExtension(file) { + return file.name.replace(/^.*\./, ""); + } + + async onFileUploaded(files) { + for (const file of files) { + if (file.error) { + return this.notification.add(file.error, { + title: this.env._t("Uploading error"), + type: "danger", + }); + } + await this.operations.saveRecord([file.id]); + } + } + + async onFileRemove(deleteId) { + const record = this.props.value.records.find((record) => record.data.id === deleteId); + this.operations.removeRecord(record); + } +} + +Many2ManyAttachmentPreview.supportedTypes = ["many2many"]; +Many2ManyAttachmentPreview.fieldsToFetch = { + name: { + type: 'char' + }, + mimetype: { + type: 'char' + }, +} +registry.category("fields").add("many2many_attachment_preview", Many2ManyAttachmentPreview) diff --git a/many2many_attachment_preview/static/src/xml/attachment_preview.xml b/many2many_attachment_preview/static/src/xml/attachment_preview.xml new file mode 100644 index 000000000..423f9c5ae --- /dev/null +++ b/many2many_attachment_preview/static/src/xml/attachment_preview.xml @@ -0,0 +1,151 @@ + diff --git a/many2many_attachment_preview/views/sale_order_views.xml b/many2many_attachment_preview/views/sale_order_views.xml new file mode 100644 index 000000000..173d981f6 --- /dev/null +++ b/many2many_attachment_preview/views/sale_order_views.xml @@ -0,0 +1,22 @@ + + + + + + sale.order.view.form.inherit.many2many.attachment.preview + + + sale.order + + + + + + +