Skip to content

Commit

Permalink
Merge af678e0 into 6527ba9
Browse files Browse the repository at this point in the history
  • Loading branch information
BT-ojossen committed Aug 7, 2019
2 parents 6527ba9 + af678e0 commit 36e350a
Show file tree
Hide file tree
Showing 22 changed files with 894 additions and 0 deletions.
101 changes: 101 additions & 0 deletions mail_operating_unit/README.rst
@@ -0,0 +1,101 @@
===================
Mail Operating Unit
===================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/12.0/mail_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-12-0/operating-unit-12-0-mail_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/213/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module introduces the following features:

* It introduces the operating unit (OU) to mail.
* We have the possibility to set an outgoing mail for each OU.
* We have the possibility to set the OU for each mail alias.
* If an OU is set in an mail alias it sets the domain according its OU.
* We have the possibility to set the OU for each mail template.
* If we sent a mail (ex. via sale order) we can only select the templates of
the same model where the OU is not set or of the same OU.
* If we sent a mail within a record it sets the sender_email_address (alias
and domain) and reply_to according its OU.

**Table of contents**

.. contents::
:local:

Usage
=====

Follow these steps to make it working:

#. Create an Outgoing Mail Server.
#. Use a current Operating Unit (OU) or create a new one.
#. Set values into the new fields 'Catchall alias', 'Catchall domain',
'Outgoing Mail Server').
#. Assignment of an OU to a mail alias. Then it takes the domain set in the OU
as domain for this mail alias. If no OU set, it takes the one from system
parameters. If the set OU has no 'Catchall domain' set, it stays
empty.
#. Assignment of an OU to a mail template. If we sent a mail (ex. via sale
order) we can only select the templates of the same model where the OU is
not set or of the same OU. If we sent a mail within a record it sets the
sender_email_address (alias and domain) and reply_to according its OU.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20mail_operating_unit%0Aversion:%2012.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
~~~~~~~

* brain-tec AG

Contributors
~~~~~~~~~~~~

* Olivier Jossen <olivier.jossen@braintec-group.com>

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/operating-unit <https://github.com/OCA/operating-unit/tree/12.0/mail_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
9 changes: 9 additions & 0 deletions mail_operating_unit/__init__.py
@@ -0,0 +1,9 @@
##############################################################################
#
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
#
##############################################################################

from . import models
from . import wizard
27 changes: 27 additions & 0 deletions mail_operating_unit/__manifest__.py
@@ -0,0 +1,27 @@
##############################################################################
#
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
#
##############################################################################

{
"name": "Mail Operating Unit",
"summary": "Adds the concept of operating unit (OU) according mail",
"version": "12.0.1.0.0",
"author": "brain-tec AG, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Purchase Management",
"depends": ["operating_unit", "mail"],
"license": "LGPL-3",
"data": [
"security/mail_alias_security.xml",
"security/mail_template_security.xml",
"views/operating_unit_views_ext.xml",
"views/mail_alias_views_ext.xml",
"views/mail_template_views_ext.xml",
"wizard/mail_compose_message_view_ext.xml",
],
"installable": True,
}
11 changes: 11 additions & 0 deletions mail_operating_unit/models/__init__.py
@@ -0,0 +1,11 @@
##############################################################################
#
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
#
##############################################################################

from . import mail_alias_ext
from . import mail_mail_ext
from . import mail_template_ext
from . import operating_unit
21 changes: 21 additions & 0 deletions mail_operating_unit/models/mail_alias_ext.py
@@ -0,0 +1,21 @@
##############################################################################
#
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
#
##############################################################################

from odoo import fields, models, api


class MailAliasExt(models.Model):
_inherit = 'mail.alias'

operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit')

@api.multi
def _get_alias_domain(self):
super(MailAliasExt, self)._get_alias_domain()
for record in self:
if record.operating_unit_id:
record.alias_domain = record.operating_unit_id.catchall_domain
41 changes: 41 additions & 0 deletions mail_operating_unit/models/mail_mail_ext.py
@@ -0,0 +1,41 @@
##############################################################################
#
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
#
##############################################################################

from odoo import api, models
from email.utils import formataddr


class MailMailExt(models.Model):
_inherit = 'mail.mail'

@api.model_create_multi
def create(self, vals_list):
mails = super(MailMailExt, self).create(vals_list)

for mail in mails:
if mail.mail_message_id.model and \
mail.mail_message_id.res_id:

model = mail.mail_message_id.model
res_id = mail.mail_message_id.res_id
record = self.env[model].browse(res_id)

if getattr(record, 'operating_unit_id', False):
if record.operating_unit_id.catchall_alias and \
record.operating_unit_id.catchall_domain:
sender_email_address = \
record.operating_unit_id.catchall_alias + '@' + \
record.operating_unit_id.catchall_domain
email_name = record.operating_unit_id.partner_id.name
mail.email_from = \
formataddr((email_name, sender_email_address))
mail.reply_to = mail.email_from
if record.operating_unit_id.outgoing_mail_server_id:
mail.mail_server_id =\
record.operating_unit_id.outgoing_mail_server_id.id

return mails
14 changes: 14 additions & 0 deletions mail_operating_unit/models/mail_template_ext.py
@@ -0,0 +1,14 @@
##############################################################################
#
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
#
##############################################################################

from odoo import fields, models


class MailTemplateExt(models.Model):
_inherit = 'mail.template'

operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit')
18 changes: 18 additions & 0 deletions mail_operating_unit/models/operating_unit.py
@@ -0,0 +1,18 @@
##############################################################################
#
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
#
##############################################################################

from odoo import fields, models


class OperatingUnitExt(models.Model):

_inherit = 'operating.unit'

catchall_alias = fields.Char(string='Catchall alias')
catchall_domain = fields.Char(string='Catchall domain')
outgoing_mail_server_id = fields.Many2one(
'ir.mail_server', string='Outgoing Mail Server')
1 change: 1 addition & 0 deletions mail_operating_unit/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
* Olivier Jossen <olivier.jossen@braintec-group.com>
11 changes: 11 additions & 0 deletions mail_operating_unit/readme/DESCRIPTION.rst
@@ -0,0 +1,11 @@
This module introduces the following features:

- It introduces the operating unit (OU) to mail.
- We have the possibility to set an outgoing mail for each OU.
- We have the possibility to set the OU for each mail alias.
- If an OU is set in an mail alias it sets the domain according its OU.
- We have the possibility to set the OU for each mail template.
- If we sent a mail (ex. via sale order) we can only select the templates of
the same model where the OU is not set or of the same OU.
- If we sent a mail within a record it sets the sender_email_address (alias and
domain) and reply_to according its OU.
Empty file.
12 changes: 12 additions & 0 deletions mail_operating_unit/readme/USAGE.rst
@@ -0,0 +1,12 @@
#. Create an Outgoing Mail Server.
#. Use a current Operating Unit (OU) or create a new one.
#. Set values into the new fields 'Catchall alias', 'Catchall domain',
'Outgoing Mail Server').
#. Assignment of an OU to a mail alias. Then it takes the domain set in the OU
as domain for this mail alias. If no OU set, it takes the one from system
parameters. If the set OU has no 'Catchall domain' set, it stays
empty.
#. Assignment of an OU to a mail template. If we sent a mail (ex. via sale
order) we can only select the templates of the same model where the OU is
not set or of the same OU. If we sent a mail within a record it sets the
sender_email_address (alias and domain) and reply_to according its OU.
19 changes: 19 additions & 0 deletions mail_operating_unit/security/mail_alias_security.xml
@@ -0,0 +1,19 @@
<!--
Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
-->
<odoo>

<record id="ir_rule_mail_alias_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="mail.model_mail_alias"/>
<field name="domain_force">['|',('operating_unit_id','=',False),
('operating_unit_id','in',user.operating_unit_ids.ids)]</field>
<field name="name">Mail Aliases from allowed operating units</field>
<field name="global" eval="True"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

</odoo>
19 changes: 19 additions & 0 deletions mail_operating_unit/security/mail_template_security.xml
@@ -0,0 +1,19 @@
<!--
Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com)
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
-->
<odoo>

<record id="ir_rule_mail_template_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="mail.model_mail_template"/>
<field name="domain_force">['|',('operating_unit_id','=',False),
('operating_unit_id','in',user.operating_unit_ids.ids)]</field>
<field name="name">Mail Templates from allowed operating units</field>
<field name="global" eval="True"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

</odoo>
Binary file added mail_operating_unit/static/description/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 36e350a

Please sign in to comment.