-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] cmis_mail: store mail composer attachments in CMIS
- Loading branch information
1 parent
dfb8786
commit dc19fb0
Showing
12 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * cmis_mail | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__allowed_cmis_folder_field_ids | ||
msgid "Allowed Cmis Folder Field" | ||
msgstr "" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model,name:cmis_mail.model_mail_compose_message | ||
msgid "Email composition wizard" | ||
msgstr "" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__is_multiple_cmis_fields | ||
msgid "Is Multiple Cmis Fields" | ||
msgstr "" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__cmis_folder_field_id | ||
msgid "Save attachments into" | ||
msgstr "" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__is_save_in_cmis_enabled | ||
msgid "Store attachments in CMIS" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * cmis_mail | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__allowed_cmis_folder_field_ids | ||
msgid "Allowed Cmis Folder Field" | ||
msgstr "Dossiers CMIS autorisés" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model,name:cmis_mail.model_mail_compose_message | ||
msgid "Email composition wizard" | ||
msgstr "" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__is_multiple_cmis_fields | ||
msgid "Is Multiple Cmis Fields" | ||
msgstr "" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__cmis_folder_field_id | ||
msgid "Save attachments into" | ||
msgstr "Sauvegarder les pièces-jointes dans" | ||
|
||
#. module: cmis_mail | ||
#: model:ir.model.fields,field_description:cmis_mail.field_mail_compose_message__is_save_in_cmis_enabled | ||
msgid "Store attachments in CMIS" | ||
msgstr "Sauvegarder les pièces-jointes dans CMIS" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<section class="s_text_block"> | ||
<div class="container"> | ||
<h2 class="oe_slogan text-center">Alfodoo, the Odoo-Alfresco connector<br/></h2> | ||
<h3 class="oe_slogan text-center text-muted" style="color: rgb(165, 74, 123);"> | ||
<b>Streamline your business processes by managing your documents in their context within any Odoo apps.</b> | ||
</h3> | ||
<div class="row"> | ||
<div class="col-md-12 mb16 mt16" style="font-size: 18px;"> | ||
<p> | ||
<br/> | ||
</p> | ||
<p> | ||
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. | ||
</p> | ||
<p> | ||
<br/> | ||
<b>Benefits from the Alfodoo connector:</b> | ||
</p> | ||
<ul> | ||
<li> | ||
<p>Manage your content/documents linked to your Odoo processes;</p> | ||
</li> | ||
<li> | ||
<p>Make classification and indexing of content/documents easier and more qualitative;</p> | ||
</li> | ||
<li> | ||
<p>Enrich documents with Odoo business record information to exploit the powerful Alfresco document management capabilities.</p> | ||
</li> | ||
</ul> | ||
<p> | ||
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. | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</section> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import mail_compose_message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# 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, | ||
) | ||
allowed_cmis_folder_field_ids = fields.Many2many( | ||
comodel_name="ir.model.fields", | ||
readonly=True, | ||
) | ||
is_multiple_cmis_fields = fields.Boolean( | ||
readonly=True, | ||
) | ||
cmis_folder_field_id = fields.Many2one( | ||
string="Save attachments into", | ||
comodel_name="ir.model.fields", | ||
domain="[('id', 'in', allowed_cmis_folder_field_ids.ids)]", | ||
) | ||
|
||
@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 | ||
cmis_fields = self.env["ir.model.fields"].search( | ||
[("model", "=", related_model), ("ttype", "=", "cmis_folder")] | ||
) | ||
if cmis_fields: | ||
res.update( | ||
{ | ||
"allowed_cmis_folder_field_ids": [(6, 0, cmis_fields.ids)], | ||
"cmis_folder_field_id": cmis_fields[0].id, | ||
"is_multiple_cmis_fields": len(cmis_fields) > 1, | ||
} | ||
) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2022 ACSONE SA/NV | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record model="ir.ui.view" id="mail_compose_message_form_view"> | ||
<field name="name">mail.compose.message.form (in cmis_mail)</field> | ||
<field name="model">mail.compose.message</field> | ||
<field name="inherit_id" ref="mail.email_compose_message_wizard_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="template_id" position="after"> | ||
<field name="allowed_cmis_folder_field_ids" invisible="1" /> | ||
<field name="is_multiple_cmis_fields" invisible="1" /> | ||
<field name="is_save_in_cmis_enabled" attrs="{'invisible': [('attachment_ids', '=', [])]}" /> | ||
<newline /> | ||
<field name="cmis_folder_field_id" | ||
domain="[('model', '=', model), ('ttype', '=', 'cmis_folder')]" | ||
attrs="{'invisible': ['|', '|', ('is_save_in_cmis_enabled', '=', False), ('attachment_ids', '=', []), ('is_multiple_cmis_fields', '=', False)]}" /> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../cmis_mail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |