Skip to content
Permalink
Browse files

Merge 0c79d80 into 386a479

  • Loading branch information
BT-ojossen committed Oct 11, 2019
2 parents 386a479 + 0c79d80 commit e64fd14f4425f6f6c7d9a3ed088aade9953f413e
@@ -0,0 +1,102 @@
===================
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.
* We have the possibility to set the OU on each user for mails if operating_unit_id does not exist on record.
* 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.
@@ -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
@@ -0,0 +1,29 @@
##############################################################################
#
# 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.2",
"author": "brain-tec AG, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Purchase Management",
"depends": ["operating_unit", "mail", "base"],
"license": "LGPL-3",
"data": [
"data/mail_data.xml",
"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",
"views/res_users_view.xml",
"wizard/mail_compose_message_view_ext.xml",
],
"installable": True,
}
@@ -0,0 +1,21 @@
<odoo>
<template id="mail_notification_paynow" inherit_id="mail.mail_notification_paynow">
<xpath expr="//td[child::b[@t-esc='company.name']]" position="replace">
<td style="padding: 0; font-size:11px;">
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 32px 0px 4px 0px;"/>
<b t-esc="record.operating_unit_id.partner_id.name"/><br/>
<div style="color: #999999">
<t t-esc="record.operating_unit_id.partner_id.phone"/>
<t t-if="record.operating_unit_id.partner_id.email"> |
<a t-att-href="'mailto:%s' % record.operating_unit_id.partner_id.email" style="text-decoration:none; color: #999999;"><t t-esc="record.operating_unit_id.partner_id.email"/></a>
</t>
<t t-if="record.operating_unit_id.partner_id.website"> |
<a t-att-href="'%s' % record.operating_unit_id.partner_id.website" style="text-decoration:none; color: #999999;">
<t t-esc="record.operating_unit_id.partner_id.website"/>
</a>
</t>
</div>
</td>
</xpath>
</template>
</odoo>
@@ -0,0 +1,12 @@
##############################################################################
#
# 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 res_users
from . import mail_alias_ext
from . import mail_mail_ext
from . import mail_template_ext
from . import operating_unit
@@ -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
@@ -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)
operating_unit = False
if getattr(record, 'operating_unit_id', False):
operating_unit = record.operating_unit_id
elif self.env.context.get('uid', False):
user = self.env['res.users'].browse(self.env.context.get('uid'))
operating_unit = user.operating_unit_for_mails_id

if operating_unit and operating_unit.catchall_alias and operating_unit.catchall_domain:
sender_email_address = (operating_unit.catchall_alias + '@' +
operating_unit.catchall_domain)
email_name = operating_unit.partner_id.name
mail.email_from = formataddr((email_name, sender_email_address))
mail.reply_to = mail.email_from

if operating_unit.outgoing_mail_server_id:
mail.mail_server_id = operating_unit.outgoing_mail_server_id.id

return mails
@@ -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')
@@ -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')
@@ -0,0 +1,24 @@
##############################################################################
#
# 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, fields, models


class ResUsers(models.Model):

_inherit = 'res.users'

operating_unit_for_mails_id = fields.Many2one(
'operating.unit', 'Operating Unit For Mails',
domain="[('id', 'in', operating_unit_ids)]"
)

@api.onchange('operating_unit_ids')
def _on_change_operating_unit_ids(self):
if (self.operating_unit_for_mails_id and
self.operating_unit_for_mails_id.id not in self.operating_unit_ids.ids):
self.operating_unit_for_mails_id = False
@@ -0,0 +1 @@
* Olivier Jossen <olivier.jossen@braintec-group.com>
@@ -0,0 +1,12 @@
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.
- We have the possibility to set the OU on each user for mails if operating_unit_id does not exist on record.
- 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.
No changes.
@@ -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.
@@ -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>
@@ -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 not shown.

0 comments on commit e64fd14

Please sign in to comment.
You can’t perform that action at this time.