Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
176 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,32 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:alt: License | ||
|
||
CRM: Autoalias | ||
====================== | ||
|
||
Features | ||
======== | ||
|
||
* Creates an email alias automatically when creating a new lead/opportunity for attach the emails | ||
sent to that alias. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Hugo Santos <hugo.santos@factorlibre.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: http://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: http://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
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. | ||
|
||
To contribute to this module, please visit http://odoo-community.org. |
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 model |
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,37 @@ | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2015 FactorLibre (http://www.factorlibre.com) | ||
# Hugo Santos <hugo.santos@factorlibre.com> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
{ | ||
'name': 'Crm Auto Alias', | ||
'summary': 'Automatically generates an email alias related to lead', | ||
'version': '1.0', | ||
'author': "FactorLibre,Odoo Community Association (OCA)", | ||
'category': 'Customer Relationship Management', | ||
'depends': ['crm', 'mail'], | ||
'website': 'http://factorlibre.com', | ||
'data': [ | ||
'view/crm_lead_view.xml' | ||
], | ||
'demo': [], | ||
'test': ['test/test_autoalias.yml'], | ||
'installable': True, | ||
'auto_install': False, | ||
'license': 'AGPL-3', | ||
} |
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 crm_lead |
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,64 @@ | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2015 FactorLibre (http://www.factorlibre.com) | ||
# Hugo Santos <hugo.santos@factorlibre.com> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
from openerp import models, fields, api | ||
from uuid import uuid4 | ||
|
||
|
||
class CrmLead(models.Model): | ||
_inherit = 'crm.lead' | ||
|
||
email_alias = fields.Many2one('mail.alias', 'Alias', readonly=True) | ||
email_alias_email = fields.Char(string='Alias', | ||
compute='get_complete_alias', | ||
store=True) | ||
|
||
@api.one | ||
@api.depends('email_alias') | ||
def get_complete_alias(self): | ||
if self.email_alias: | ||
self.email_alias_email = self.email_alias.name_get()[0][1] | ||
|
||
@api.model | ||
def create(self, vals): | ||
ir_model = self.env['ir.model'] | ||
mail_alias_model = self.env['mail.alias'] | ||
lead_model_ids = ir_model.search([ | ||
('model', '=', 'crm.lead') | ||
]) | ||
alias_name = "{0}-crm".format(uuid4().hex) | ||
mail_alias_ids = mail_alias_model.search([ | ||
('alias_name', '=', alias_name) | ||
]) | ||
while mail_alias_ids: | ||
alias_name = "{0}-crm".format(uuid4().hex) | ||
mail_alias_ids = mail_alias_model.search([ | ||
('alias_name', '=', alias_name) | ||
]) | ||
alias = mail_alias_model.create({ | ||
'alias_name': alias_name, | ||
'alias_model_id': lead_model_ids[0].id | ||
}) | ||
vals.update({ | ||
'email_alias': alias.id | ||
}) | ||
record = super(CrmLead, self).create(vals) | ||
alias.alias_force_thread_id = record.id | ||
return record |
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,13 @@ | ||
- | ||
In order to test that the alias is created | ||
I create a new lead | ||
- | ||
!record {model: crm.lead, id: alias_test_lead}: | ||
name: Autoalias Lead | ||
type: lead | ||
- | ||
Then the autoalias must be created | ||
- | ||
!assert {model: crm.lead, id: alias_test_lead, string: the lead must have an alias}: | ||
- email_alias != None | ||
- email_alias_email != None |
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,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
|
||
<record id="crm_case_form_view_leads_alias" model="ir.ui.view"> | ||
<field name="name">CRM - Leads Autoalias</field> | ||
<field name="model">crm.lead</field> | ||
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='opt_out']" position="after"> | ||
<field name="email_alias_email"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="crm_case_form_view_oppor_alias" model="ir.ui.view"> | ||
<field name="name">Opportunities</field> | ||
<field name="model">crm.lead</field> | ||
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='opt_out']" position="after"> | ||
<field name="email_alias_email"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</data> | ||
</openerp> |