diff --git a/cmis_mail/__init__.py b/cmis_mail/__init__.py new file mode 100644 index 00000000..5cb1c491 --- /dev/null +++ b/cmis_mail/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/cmis_mail/__manifest__.py b/cmis_mail/__manifest__.py new file mode 100644 index 00000000..f3a8c87c --- /dev/null +++ b/cmis_mail/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Cmis Mail", + "description": """ + This module allows to store mail attachment with CMIS.""", + 'category': 'Document Management', + "version": "13.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV", + 'website': 'http://alfodoo.org/', + "depends": [ + "mail", + "cmis_field", + ], + "data": [ + "wizards/mail_compose_message.xml", + ], + 'installable': True, + 'images': [ + 'static/description/main_icon.png', + ], +} diff --git a/cmis_mail/static/description/icon.png b/cmis_mail/static/description/icon.png new file mode 100644 index 00000000..12cfdb74 Binary files /dev/null and b/cmis_mail/static/description/icon.png differ diff --git a/cmis_mail/static/description/index.html b/cmis_mail/static/description/index.html new file mode 100644 index 00000000..935f4cab --- /dev/null +++ b/cmis_mail/static/description/index.html @@ -0,0 +1,36 @@ +
+
+

Alfodoo, the Odoo-Alfresco connector

+

+ Streamline your business processes by managing your documents in their context within any Odoo apps. +

+
+
+

+
+

+

+ Alfodoo provides a unique solution to seamlessly integrate the open-source ECM Alfresco with Odoo and let the user manages his documents in Alfresco without leaving his Odoo work environment. +

+

+
+ Benefits from the Alfodoo connector: +

+
    +
  • +

    Manage your content/documents linked to your Odoo processes;

    +
  • +
  • +

    Make classification and indexing of content/documents easier and more qualitative;

    +
  • +
  • +

    Enrich documents with Odoo business record information to exploit the powerful Alfresco document management capabilities.

    +
  • +
+

+ This module provides a specialized field to use to link an Odoo model with a cmis content. It's the base module of the Alfodoo addons. +

+
+
+
+
diff --git a/cmis_mail/static/description/main_icon.png b/cmis_mail/static/description/main_icon.png new file mode 100644 index 00000000..2ea088f4 Binary files /dev/null and b/cmis_mail/static/description/main_icon.png differ diff --git a/cmis_mail/wizards/__init__.py b/cmis_mail/wizards/__init__.py new file mode 100644 index 00000000..b528d997 --- /dev/null +++ b/cmis_mail/wizards/__init__.py @@ -0,0 +1 @@ +from . import mail_compose_message diff --git a/cmis_mail/wizards/mail_compose_message.py b/cmis_mail/wizards/mail_compose_message.py new file mode 100644 index 00000000..34a3cbc7 --- /dev/null +++ b/cmis_mail/wizards/mail_compose_message.py @@ -0,0 +1,74 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import base64 +import mimetypes +from io import BytesIO + +from odoo import api, fields, models + + +class MailComposeMessage(models.TransientModel): + _inherit = "mail.compose.message" + + is_save_in_cmis_enabled = fields.Boolean( + string="Store attachments in CMIS", + default=False, + ) + cmis_folder_field_id = fields.Many2one( + string="Save attachments into", + comodel_name="ir.model.fields", + ) + + @api.model + def default_get(self, fields): # pylint:disable=redefined-outer-name + res = super().default_get(fields) + related_model = res.get("model") + if not related_model: + return res + default_cmis_field = self.env["ir.model.fields"].search( + [("model", "=", related_model), ("ttype", "=", "cmis_folder")], limit=1 + ) + if default_cmis_field: + res["cmis_folder_field_id"] = default_cmis_field.id + return res + + def _get_cmis_parent_folder(self): + self.ensure_one() + field_name = self.cmis_folder_field_id.name + related_record = self.env[self.model].browse(self.res_id) + field = related_record._fields[field_name] + cmis_backend = field.get_backend(self.env) + root_objectId = related_record[field_name] + if not root_objectId: + field.create_value(related_record) + root_objectId = related_record[field_name] + return cmis_backend.get_cmis_repository().getObject(root_objectId) + + @api.model + def get_mimetype(self, file_name): + return mimetypes.guess_type(file_name)[0] + + def _save_attachments_in_cmis(self): + self.ensure_one() + if not self.model or not self.res_id: + return + for attachment in self.attachment_ids: + props = { + "cmis:name": attachment.name, + } + mimetype = self.get_mimetype(attachment.name) + cmis_parent_folder = self._get_cmis_parent_folder() + cmis_parent_folder.createDocument( + attachment.name, + properties=props, + contentFile=BytesIO(base64.b64decode(attachment.datas)), + contentType=mimetype, + ) + + def send_mail(self, auto_commit=False): + res = super().send_mail(auto_commit=auto_commit) + for rec in self: + if rec.is_save_in_cmis_enabled: + rec._save_attachments_in_cmis() + return res diff --git a/cmis_mail/wizards/mail_compose_message.xml b/cmis_mail/wizards/mail_compose_message.xml new file mode 100644 index 00000000..59ed8739 --- /dev/null +++ b/cmis_mail/wizards/mail_compose_message.xml @@ -0,0 +1,16 @@ + + + + + mail.compose.message.form (in cmis_mail) + mail.compose.message + + + + + + + + + diff --git a/setup/cmis_mail/odoo/addons/cmis_mail b/setup/cmis_mail/odoo/addons/cmis_mail new file mode 120000 index 00000000..497a559d --- /dev/null +++ b/setup/cmis_mail/odoo/addons/cmis_mail @@ -0,0 +1 @@ +../../../../cmis_mail \ No newline at end of file diff --git a/setup/cmis_mail/setup.py b/setup/cmis_mail/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/cmis_mail/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)