-
-
Notifications
You must be signed in to change notification settings - Fork 48
[19.0][MIG] edi_mail_import_oca #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
etobella
wants to merge
5
commits into
OCA:19.0
Choose a base branch
from
dixmit:19.0-mig-mail
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b55c8a5
[ADD] edi_mail_import_oca
etobella b64d22a
[IMP] edi_mail_import_oca: Black, isort, prettier
etobella a88067b
[MIG] edi_mail_import_oca: Migration to 19.0
etobella 12991dd
[IMP] edi_mail_import_oca: Pass verification logic to constrain.
etobella 422b3b0
[IMP] edi_mail_import_oca: Move logic to backend
etobella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,92 @@ | ||
| .. image:: https://odoo-community.org/readme-banner-image | ||
| :target: https://odoo-community.org/get-involved?utm_source=readme | ||
| :alt: Odoo Community Association | ||
|
|
||
| =================== | ||
| Edi Mail Import Oca | ||
| =================== | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:aff4c256557f2507c286234eccc96a32869385fb0ab0fab7f5509a292ae01a43 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
| :target: https://odoo-community.org/page/development-status | ||
| :alt: Beta | ||
| .. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
| :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
| :alt: License: AGPL-3 | ||
| .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/edi-framework/tree/19.0/edi_mail_import_oca | ||
| :alt: OCA/edi-framework | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/edi-framework-19-0/edi-framework-19-0-edi_mail_import_oca | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
| :target: https://runboat.odoo-community.org/builds?repo=OCA/edi-framework&target_branch=19.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| This module allows to process mails received as edi.exchange.records to | ||
| process them. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Use Cases / Context | ||
| =================== | ||
|
|
||
| Usually, when we think about EDI entrances, we think about SFTP or API, | ||
| however, there is an standard way to receive files that is emails. | ||
|
|
||
| This module tries to offer a way to reuse EDI and mail interface in | ||
| order to handle everything. | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi-framework/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/edi-framework/issues/new?body=module:%20edi_mail_import_oca%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * Dixmit | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - `Dixmit <https://www.dixmit.com>`__ | ||
|
|
||
| - Enric Tobella | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| This module is part of the `OCA/edi-framework <https://github.com/OCA/edi-framework/tree/19.0/edi_mail_import_oca>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or 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 models |
This file contains hidden or 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,16 @@ | ||
| # Copyright 2026 Dixmit | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| { | ||
| "name": "Edi Mail Import Oca", | ||
| "summary": """Process emails as EDI exchange recordsç""", | ||
| "version": "19.0.1.0.0", | ||
| "license": "AGPL-3", | ||
| "author": "Dixmit,Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/edi-framework", | ||
| "depends": ["edi_core_oca", "mail"], | ||
| "data": [ | ||
| "views/edi_exchange_type.xml", | ||
| ], | ||
| "demo": [], | ||
| } |
This file contains hidden or 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,2 @@ | ||
| from . import edi_exchange_type | ||
| from . import edi_exchange_record |
This file contains hidden or 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,67 @@ | ||
| # Copyright 2026 Dixmit | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| import base64 | ||
| import email | ||
| import json | ||
| import logging | ||
| import re | ||
|
|
||
| from odoo import api, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class EdiExchangeRecord(models.Model): | ||
| _inherit = "edi.exchange.record" | ||
|
|
||
| @api.model | ||
| def message_new(self, msg_dict, custom_values=None): | ||
| record = super().message_new( | ||
| msg_dict, | ||
| custom_values=custom_values, | ||
| ) | ||
| if record.type_id.direction != "input": | ||
| raise UserError( | ||
| self.env._("Received email for non-incoming exchange type.") | ||
| ) | ||
| if record.type_id.mail_as_attachment: | ||
| new_message_dict = msg_dict.copy() | ||
| attachments = new_message_dict.pop("attachments", []) | ||
| new_message_dict["attachments"] = [] | ||
| for attachment in attachments: | ||
| new_message_dict["attachments"].append( | ||
| { | ||
| "info": attachment.info, | ||
| "data": self._process_email_attachment(attachment), | ||
| "fname": attachment.fname, | ||
| } | ||
| ) | ||
| record._set_file_content(json.dumps(new_message_dict)) | ||
| record.edi_exchange_state = "input_received" | ||
| else: | ||
| content = False | ||
| filename = False | ||
| for attachment in msg_dict.get("attachments", []): | ||
| if re.match( | ||
| record.type_id.exchange_filename_pattern or ".*", | ||
etobella marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| attachment.fname, | ||
| re.IGNORECASE, | ||
| ): | ||
| content = self._process_email_attachment(attachment) | ||
simahawk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| filename = attachment.fname | ||
| break | ||
| if content: | ||
| record._set_file_content(content) | ||
| record.exchange_filename = filename | ||
| record.edi_exchange_state = "input_received" | ||
| return record | ||
|
|
||
| def _process_email_attachment(self, attachment): | ||
| """Process email attachment to be stored as file content.""" | ||
| data = attachment[1] | ||
| if isinstance(data, email.message.EmailMessage): | ||
| data = data.as_bytes() | ||
| if not isinstance(data, bytes): | ||
| data = str(data).encode("utf-8") | ||
| return base64.b64encode(data).decode("utf-8") | ||
This file contains hidden or 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,27 @@ | ||
| # Copyright 2026 Dixmit | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| import ast | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class EdiExchangeType(models.Model): | ||
| _name = "edi.exchange.type" | ||
| _inherit = ["edi.exchange.type", "mail.alias.mixin"] | ||
simahawk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| mail_as_attachment = fields.Boolean( | ||
| string="Import Email as an Attachment", | ||
| ) | ||
|
|
||
| def _alias_get_creation_values(self): | ||
| values = super()._alias_get_creation_values() | ||
| values["alias_model_id"] = ( | ||
| self.env["ir.model"].sudo()._get("edi.exchange.record").id | ||
etobella marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| if self.id: | ||
| values["alias_defaults"] = defaults = ast.literal_eval( | ||
| self.alias_defaults or "{}" | ||
| ) | ||
| defaults["backend_id"] = self.backend_id.id | ||
| defaults["type_id"] = self.id | ||
| return values | ||
This file contains hidden or 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,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or 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,3 @@ | ||
| Usually, when we think about EDI entrances, we think about SFTP or API, however, there is an standard way to receive files that is emails. | ||
|
|
||
| This module tries to offer a way to reuse EDI and mail interface in order to handle everything. |
This file contains hidden or 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,2 @@ | ||
| - [Dixmit](https://www.dixmit.com) | ||
| - Enric Tobella |
This file contains hidden or 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 @@ | ||
| This module allows to process mails received as edi.exchange.records to process them. | ||
simahawk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.