[MRG]merge with lp:~openerp-dev/openobject-addons/trunk-mail-alias-jam
authorTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Wed, 4 Jul 2012 09:40:29 +0000 (15:10 +0530)
committerTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Wed, 4 Jul 2012 09:40:29 +0000 (15:10 +0530)
bzr revid: tpa@tinyerp.com-20120704094029-zc0t2rveyt1sit4b

13 files changed:
addons/mail/__init__.py
addons/mail/__openerp__.py
addons/mail/mail_alias.py
addons/mail/mail_alias_view.xml
addons/mail/mail_demo.xml
addons/mail/mail_group.py
addons/mail/res_config.py [new file with mode: 0644]
addons/mail/res_config_view.xml [new file with mode: 0644]
addons/mail/res_users.py
addons/mail/user_mail_alias_demo.xml [deleted file]
addons/mail/wizard/__init__.py
addons/mail/wizard/update_mail_alias.py [deleted file]
addons/mail/wizard/update_mail_alias_wizard.xml [deleted file]

index f06b453..1b2b5cb 100644 (file)
@@ -28,6 +28,7 @@ import res_users
 import res_partner
 import report
 import wizard
+import res_config
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
index 5c0afc2..d4d93ab 100644 (file)
@@ -56,7 +56,7 @@ The main features are:
     'depends': ['base', 'base_tools'],
     'data': [
         'wizard/mail_compose_message_view.xml',
-        'wizard/update_mail_alias_wizard.xml',
+        'res_config_view.xml',
         'mail_message_view.xml',
         'mail_alias_data.xml',
         'mail_subscription_view.xml',
@@ -70,11 +70,10 @@ The main features are:
         'res_users_view.xml',
         'mail_alias_view.xml',
     ],
-    'demo_xml': [
-        'user_mail_alias_demo.xml',
+    'demo': [
+        'mail_demo.xml',
     ],
     'installable': True,
-    'auto_install': False,
     'certificate': '001056784984222247309',
     'images': [
         'images/customer_history.jpeg',
@@ -97,8 +96,5 @@ The main features are:
     'qweb': [
         'static/src/xml/mail.xml',
     ],
-    'demo': [
-        'mail_demo.xml',
-    ],
 }
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
index 292b2f7..c4328fa 100644 (file)
@@ -39,6 +39,14 @@ class mail_alias(osv.Model):
     _description = "Mail Alias"
     _rec_name = 'alias_name'
 
+    def _get_alias_domain(self, cr, uid, ids, name, args, context=None):
+        res = {}
+        config_parameter_pool = self.pool.get("ir.config_parameter")
+        domain = config_parameter_pool.get_param(cr, uid, "mail.catchall.domain", context=context)   
+        for alias in self.browse(cr, uid, ids, context=context):
+            res[alias.id] = domain or ""
+        return res
+
     _columns = {
         'alias_name': fields.char('Mailbox Alias', size=255, required=True,
                             help="The name of the mailbox alias, e.g. 'jobs' "
@@ -63,7 +71,8 @@ class mail_alias(osv.Model):
         'alias_force_thread_id': fields.integer('Record Thread ID',
                                       help="Optional ID of the thread (record) to which all "
                                            "messages will be attached, even if they did not reply to it. "
-                                           "If set, this will disable the creation of new records completely.")
+                                           "If set, this will disable the creation of new records completely."),
+        'alias_domain': fields.function(_get_alias_domain, string="Alias Doamin", type='char', size=None),
     }
     _defaults = {
         'alias_defaults': '{}',
@@ -82,9 +91,9 @@ class mail_alias(osv.Model):
         for record in self.browse(cr, uid, ids, context=context):
             try:
                 dict(eval(record.alias_defaults))
-                return True
             except:
                 return False
+            return True
 
     _constraints = [
         (_check_alias_defaults, "Default Values are in wrong format.\nIt must be in python dictionary format e.g.{'field_name': 'value' or {}}", ['alias_defaults']),
@@ -96,25 +105,27 @@ class mail_alias(osv.Model):
         Email Alias Domain from config.
         e.g. `jobs@openerp.my.openerp.com` or `sales@openerp.my.openerp.com`
         """
-        if context is None:
-            context = {}
         res = []
-        config_parameter_pool = self.pool.get("ir.config_parameter")
-        domain = config_parameter_pool.get_param(cr, uid, "mail.catchall.domain", context=context)         
-        for record in self.read(cr, uid, ids, ['alias_name'], context=context):
-            domain_alias = "%s@%s"%(record['alias_name'], domain)
+        for record in self.read(cr, uid, ids, ['alias_name', 'alias_domain'], context=context):
+            domain_alias = "%s@%s"%(record['alias_name'], record['alias_domain'])
             res.append((record['id'], domain_alias))
         return res
 
-    def create_unique_alias(self, cr, uid, values, sequence=1 ,context=None):
-        if sequence:
-            prob_alias = "%s%s"%(values['alias_name'], sequence)
-            search_alias = self.search(cr, uid, [('alias_name', '=', prob_alias)])
-            if search_alias:    
-                values = self.create_unique_alias(cr, uid, values, sequence+1, context)
-            else:
-                values.update({'alias_name': prob_alias})
-                return values
+    def _generate_alias(self, cr, uid, name, sequence=1 ,context=None):
+        new_name = "%s%s"%(name, sequence)
+        search_alias = self.search(cr, uid, [('alias_name', '=', new_name)])
+        if search_alias:    
+            self._generate_alias(cr, uid, name, sequence+1 ,context=None)
         else:
-            return values.update({'alias_name': "%s"%(values['alias_name'])})
+            return new_name
+
+    def create_unique_alias(self, cr, uid, vals, context=None):
+        model_pool = self.pool.get('ir.model')
+        values = {'alias_name': vals['alias_name']}
+        if self.search(cr, uid, [('alias_name', '=', vals['alias_name'])]):
+            values.update({'alias_name': self._generate_alias(cr, uid, vals['alias_name'], sequence=1, context=context)})
+        model_sids = model_pool.search(cr, uid, [('model', '=', vals['alias_model_id'])])
+        values.update({'alias_model_id': model_sids[0]})
+        return self.create(cr, uid, values, context=context)
+
 
index e72143b..adbc8f0 100644 (file)
             <field name="arch" type="xml">
                 <form string="Alias" version="7.0">
                     <sheet>
+                        <label for="alias_name" class="oe_edit_only"/>
+                        <h2><field name="alias_name"  class="oe_inline"/>@<field name="alias_domain" class="oe_inline"/></h2>
                         <group colspan="4" col="4">
-                            <field name="alias_name"/>
                             <field name="alias_model_id" readonly="1"/>
                             <field name="alias_user_id"/>
                             <field name="alias_force_thread_id"/>
-                            <field name="alias_defaults"/>
+                            <newline/>
+                            <separator string="Alias Mailbox Default Values" colspan="4"/>
+                            <field name="alias_defaults" colspan="4" nolabel="1"/>
                         </group>
                     </sheet>
                 </form>
index 1adec42..42e3716 100644 (file)
@@ -92,4 +92,19 @@ Check the file in attachment for more information !  (third comment)]]></field>
         </record>
 
     </data>
+
+    <data noupdate="1">
+        <record id="mail_alias_demo_user" model="mail.alias">
+            <field name="alias_name">demo</field>
+            <field name="alias_model_id" ref="model_res_users"/>
+            <field name="alias_user_id" ref="base.user_root"/>
+            <field name="alias_force_thread_id" ref="base.user_demo"/>
+            <field name="alias_defaults">{}</field>
+        </record>
+
+        <record model="res.users" id="base.user_demo">
+            <field name="alias_id" ref="mail_alias_demo_user"/>
+        </record>
+     
+     </data>
 </openerp>
index 3e34a71..5b01968 100644 (file)
@@ -154,13 +154,11 @@ class mail_group(osv.osv):
         return res
     
     def create(self, cr, uid, vals, context=None):
-        model_pool = self.pool.get('ir.model.data')
         alias_pool = self.pool.get('mail.alias')
-        model, res_id = model_pool.get_object_reference( cr, uid, "mail", "model_mail_group")
-        vals.update({'alias_name': "mailing-group",
-                     'alias_model_id': res_id})
-        alias_pool.create_unique_alias(cr, uid, vals, context=context)
-        res = super( mail_group, self).create(cr, uid, vals, context)
-        record = self.read(cr, uid, res, context)
-        alias_pool.write(cr, uid, [record['alias_id']], {"alias_force_thread_id":record['id']}, context)
+        if not vals.get('alias_id'):
+            alias_id = alias_pool.create_unique_alias(cr, uid, {'alias_name': "mail_group."+vals['name'], 'alias_model_id': self._name}, context=context)
+            vals.update({'alias_id': alias_id})
+        res = super(mail_group, self).create(cr, uid, vals, context)
+        alias_pool.write(cr, uid, [vals['alias_id']], {"alias_force_thread_id": res}, context)
         return res
+
diff --git a/addons/mail/res_config.py b/addons/mail/res_config.py
new file mode 100644 (file)
index 0000000..55efb2d
--- /dev/null
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>
+#
+##############################################################################
+
+from openerp.osv import osv, fields
+
+class project_configuration(osv.TransientModel):
+    _inherit = 'base.config.settings'
+
+    _columns = {
+        'alias_domain' : fields.char('Catch-all Mail Alias Domain', size=None,
+                                     help="If you have setup a catch-all mail domain redirected to "
+                                          "the OpenERP server, enter the domain name here."),
+    }
+
+    def get_default_alias_domain(self, cr, uid, ids, context=None):
+        return {'alias_domain': self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", context=context)}
+
+    def set_alias_domain(self, cr, uid, ids, context=None):
+        config_parameters = self.pool.get("ir.config_parameter")
+        for record in self.browse(cr, uid, ids, context=context):
+            config_parameters.set_param(cr, uid, "mail.catchall.domain", record.alias_domain or '', context=context)
\ No newline at end of file
diff --git a/addons/mail/res_config_view.xml b/addons/mail/res_config_view.xml
new file mode 100644 (file)
index 0000000..3b1536a
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="view_general_configuration_mail_alias_domain" model="ir.ui.view">
+            <field name="name">base.config.settings.mail.alias</field>
+            <field name="model">base.config.settings</field>
+            <field name="inherit_id" ref="base_setup.view_general_configuration"/>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <xpath expr="/form/sheet/group[@string='Others']" position='inside'>
+                    <field name="alias_domain" placeholder="mycompany.my.openerp.com"/>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>
index ea0c3a0..8b4b05c 100644 (file)
@@ -74,14 +74,12 @@ class res_users(osv.osv):
     
     def create(self, cr, uid, data, context=None):
         # create default alias same as the login
-        model_pool = self.pool.get('ir.model.data')
         alias_pool = self.pool.get('mail.alias')
-        res_id = model_pool.get_object( cr, uid, "mail", "model_res_users")
-        data.update({'alias_name': data.get('login'),
-                     'alias_model_id': res_id.id})
+        alias_id = alias_pool.create_unique_alias(cr, uid, {'alias_name': data['name'], 'alias_model_id': self._name}, context=context)
+        data.update({'alias_id': alias_id})
         user_id = super(res_users, self).create(cr, uid, data, context=context)
+        alias_pool.write(cr, uid, [alias_id], {"alias_force_thread_id": user_id}, context)
         user = self.browse(cr, uid, user_id, context=context)
-        alias_pool.write(cr, uid, [user.alias_id.id], {"alias_force_thread_id": user.id}, context)
         # make user follow itself
         self.message_subscribe(cr, uid, [user_id], [user_id], context=context)
         # create a welcome message to broadcast
diff --git a/addons/mail/user_mail_alias_demo.xml b/addons/mail/user_mail_alias_demo.xml
deleted file mode 100644 (file)
index eea7d52..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<openerp>
-    <data noupdate="1">
-        <record id="mail_alias_demo_user" model="mail.alias">
-            <field name="alias_name">demo</field>
-            <field name="alias_model_id" ref="model_res_users"/>
-            <field name="alias_user_id" ref="base.user_root"/>
-            <field name="alias_force_thread_id" ref="base.user_demo"/>
-            <field name="alias_defaults">{}</field>
-        </record>
-
-        <record model="res.users" id="base.user_demo">
-            <field name="alias_id" ref="mail_alias_demo_user"/>
-        </record>
-     
-     </data>
-</openerp>      
index bf35381..88b9581 100644 (file)
@@ -20,5 +20,5 @@
 ##############################################################################
 
 import mail_compose_message
-import update_mail_alias
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/mail/wizard/update_mail_alias.py b/addons/mail/wizard/update_mail_alias.py
deleted file mode 100644 (file)
index b419050..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
-#
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU 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 General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>
-#
-##############################################################################
-
-from osv import orm
-from osv import fields
-
-class transient_update_maildomain(orm.TransientModel):
-    
-    _name = "transient.update.maildomain"
-    _description = "Update Mail Domain"
-    _columns = {
-        'name' : fields.text('Domain', required=True),
-    }
-    def update_domain(self, cr, uid, ids, context=None):
-        config_parameter_pool = self.pool.get("ir.config_parameter")
-        for record in self.browse(cr, uid, ids, context):
-            config_parameter_pool.set_param(cr, uid, "mail.catchall.domain", record.name, context)
-        return {'type': 'ir.actions.act_window_close'}
diff --git a/addons/mail/wizard/update_mail_alias_wizard.xml b/addons/mail/wizard/update_mail_alias_wizard.xml
deleted file mode 100644 (file)
index 4580266..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<openerp>
-    <data>
-        <record model="ir.ui.view" id="transient_update_maildomain_form">
-            <field name="name">transient.update.maildomain.form</field>
-            <field name="model">transient.update.maildomain</field>
-            <field name="type">form</field>
-            <field name="arch" type="xml" >
-                <form string="Configure Mail Domain" version="7.0">
-                    <header>
-                        <button name="update_domain" string="Update" 
-                            type="object" class="oe_highlight"/>
-                        or
-                        <button special="cancel" string="Cancel" class="oe_link"/>
-                    </header>
-                    <group colspan="4">
-                        <separator string="Email Domain" colspan="4"/>
-                        <field name="name" nolabel="1" colspan="4" placeholder="openerp.my.openerp.com"/>
-                    </group>
-                </form>
-            </field>
-        </record>
-
-        <record id="action_transient_update_maildomain_form" model="ir.actions.act_window">
-            <field name="name">Configure Mail Domain</field>
-            <field name="res_model">transient.update.maildomain</field>
-            <field name="view_type">form</field>
-            <field name="view_mode">form</field>
-            <field name="target">new</field>
-        </record>
-
-        <!-- View for general setting -->>
-
-        <record id="view_general_configuration_mail_domain" model="ir.ui.view">
-            <field name="name">General Settings</field>
-            <field name="model">base.config.settings</field>
-            <field name="inherit_id" ref="base_setup.view_general_configuration"/>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-                <xpath expr="/form/sheet/group[@string='Others']" position='inside'>
-                    <group colspan="4" col="4">
-                        <label string="Configure Mail Domain" for="id"/>
-                        <button type="action" name="%(action_transient_update_maildomain_form)d" string="Configure" icon="gtk-execute"/>
-                    </group>
-                </xpath>
-            </field>
-        </record>
-
-    </data>
-</openerp>