Skip to content

Commit

Permalink
Merge 8885527 into 0f33cd7
Browse files Browse the repository at this point in the history
  • Loading branch information
hugosantosred committed May 26, 2015
2 parents 0f33cd7 + 8885527 commit 7f71d77
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crm_autoalias/README.rst
@@ -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.
1 change: 1 addition & 0 deletions crm_autoalias/__init__.py
@@ -0,0 +1 @@
from . import model
37 changes: 37 additions & 0 deletions crm_autoalias/__openerp__.py
@@ -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',
}
1 change: 1 addition & 0 deletions crm_autoalias/model/__init__.py
@@ -0,0 +1 @@
from . import crm_lead
64 changes: 64 additions & 0 deletions crm_autoalias/model/crm_lead.py
@@ -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
13 changes: 13 additions & 0 deletions crm_autoalias/test/test_autoalias.yml
@@ -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
28 changes: 28 additions & 0 deletions crm_autoalias/view/crm_lead_view.xml
@@ -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>

0 comments on commit 7f71d77

Please sign in to comment.