[IMP] mail alias review - work in progress
bzr revid: odo@openerp.com-20120806012717-k5rtz4i78o4m198b
This commit is contained in:
+1
-1
@@ -164,7 +164,7 @@ class crm_case_section(osv.osv):
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
alias_pool = self.pool.get('mail.alias')
|
||||
if not vals.get('alias_id'):
|
||||
name = vals.get('alias_name') or vals['name']
|
||||
name = vals.pop('alias_name', None) or vals['name']
|
||||
alias_id = alias_pool.create_unique_alias(cr, uid,
|
||||
{'alias_name': name},
|
||||
model_name="crm.lead",
|
||||
|
||||
@@ -19,16 +19,19 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from base_status.base_stage import base_stage
|
||||
import logging
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from lxml import etree
|
||||
from osv import fields, osv
|
||||
from datetime import datetime
|
||||
|
||||
import tools
|
||||
import collections
|
||||
import binascii
|
||||
from osv import fields, osv
|
||||
from openerp.modules.registry import RegistryManager
|
||||
from openerp import SUPERUSER_ID
|
||||
from base_status.base_stage import base_stage
|
||||
from tools.translate import _
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
AVAILABLE_STATES = [
|
||||
('draft', 'New'),
|
||||
('cancel', 'Refused'),
|
||||
@@ -511,14 +514,34 @@ class hr_job(osv.osv):
|
||||
_columns = {
|
||||
'survey_id': fields.many2one('survey', 'Interview Form', help="Choose an interview form for this job position and you will be able to print/answer this interview from all applicants who apply for this job"),
|
||||
'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
|
||||
help="The email address associated with this job position. New emails received will automatically "
|
||||
"create new applicants for this job."),
|
||||
help="Email alias for this job position. New emails will automatically "
|
||||
"create new applicants for this job position."),
|
||||
}
|
||||
|
||||
def init(self, cr):
|
||||
# Installation hook to create aliases for all jobs, right after _auto_init
|
||||
registry = RegistryManager.get(cr.dbname)
|
||||
mail_alias = registry.get('mail.alias')
|
||||
hr_job = registry.get('hr.job')
|
||||
jobs_no_alias = hr_job.search(cr, SUPERUSER_ID, [('alias_id', '=', False)])
|
||||
# Use read() not browse(), to avoid prefetching uninitialized inherited fields
|
||||
for job_data in hr_job.read(cr, SUPERUSER_ID, jobs_no_alias, ['name']):
|
||||
alias_id = mail_alias.create_unique_alias(cr, SUPERUSER_ID, {'alias_name': 'job_'+job_data['name'],
|
||||
'alias_force_id': job_data['id']},
|
||||
model_name=self._name)
|
||||
hr_job.write(cr, SUPERUSER_ID, job_data['id'], {'alias_id': alias_id})
|
||||
_logger.info('Mail alias created for hr.job %s (uid %s)', job_data['login'], job_data['id'])
|
||||
|
||||
# Finally attempt to reinstate the missing constraint
|
||||
try:
|
||||
cr.execute('ALTER TABLE hr_job ALTER COLUMN alias_id SET NOT NULL')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
alias_pool = self.pool.get('mail.alias')
|
||||
if not vals.get('alias_id'):
|
||||
name = vals.get('alias_name') or vals['name']
|
||||
name = vals.pop('alias_name', None) or vals['name']
|
||||
alias_id = alias_pool.create_unique_alias(cr, uid,
|
||||
{'alias_name': "job_"+name},
|
||||
model_name="hr.applicant",
|
||||
|
||||
@@ -348,11 +348,13 @@
|
||||
attrs="{'invisible':[('survey_id','=',False)]}"/>
|
||||
</div>
|
||||
</field>
|
||||
<field name="company_id" version="7.0" position="after">
|
||||
<xpath expr="/form/sheet/h1" version="7.0" position="after">
|
||||
<div colspan="4" attrs="{'invisible': [('alias_domain', '=', False)]}">
|
||||
<field name="alias_name" nolabel="1" class="oe_inline"/>@<field name="alias_domain" nolabel="1" class="oe_inline"/>
|
||||
<field name="id" invisible="1"/>
|
||||
<label for="alias_name" class="oe_edit_only"/>
|
||||
<field name="alias_name" nolabel="1" class="oe_inline" attrs="{'required': [('id', '!=', False)]}"/>@<field name="alias_domain" nolabel="1" class="oe_inline"/>
|
||||
</div>
|
||||
</field>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class mail_alias(osv.Model):
|
||||
}
|
||||
|
||||
_sql_constraints = [
|
||||
('mailbox_uniq', 'UNIQUE(alias_name)', 'Unfortunately this mail alias is already used, please choose a unique one')
|
||||
('alias_unique', 'UNIQUE(alias_name)', 'Unfortunately this email alias is already used, please choose a unique one')
|
||||
]
|
||||
|
||||
def _check_alias_defaults(self, cr, uid, ids, context=None):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
|
||||
# Copyright (C) 2012-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
|
||||
@@ -25,8 +25,8 @@ class project_configuration(osv.TransientModel):
|
||||
_inherit = 'base.config.settings'
|
||||
|
||||
_columns = {
|
||||
'alias_domain' : fields.char('Alias Domain', size=None,
|
||||
help="If you have setup a catch-all mail domain redirected to "
|
||||
'alias_domain' : fields.char('Alias Domain',
|
||||
help="If you have setup a catch-all email domain redirected to "
|
||||
"the OpenERP server, enter the domain name here."),
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//separator[@string='Others']" position='after'>
|
||||
<field name="alias_domain" placeholder="mycompany.my.openerp.com"/>
|
||||
<xpath expr="/form/group[last()]/div[last()]/div[last()]" position='after' version="7.0">
|
||||
<div>
|
||||
<label for="alias_domain" class="oe_inline"/><field name="alias_domain" placeholder="mycompany.my.openerp.com" class="oe_inline"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -73,13 +73,13 @@ class res_users(osv.osv):
|
||||
mail_alias = registry.get('mail.alias')
|
||||
res_users = registry.get('res.users')
|
||||
users_no_alias = res_users.search(cr, SUPERUSER_ID, [('alias_id', '=', False)])
|
||||
# User read() not browse(), to avoid prefetching uninitialized inherited fields
|
||||
# Use read() not browse(), to avoid prefetching uninitialized inherited fields
|
||||
for user_data in res_users.read(cr, SUPERUSER_ID, users_no_alias, ['login']):
|
||||
alias_id = mail_alias.create_unique_alias(cr, SUPERUSER_ID, {'alias_name': user_data['login'],
|
||||
'alias_model_id': self._name,
|
||||
'alias_force_id': user_data['id']})
|
||||
'alias_force_id': user_data['id']},
|
||||
model_name=self._name)
|
||||
res_users.write(cr, SUPERUSER_ID, user_data['id'], {'alias_id': alias_id})
|
||||
_logger.info('Mail alias created for user_data %s (uid %s)', user_data['login'], user_data['id'])
|
||||
_logger.info('Mail alias created for user %s (uid %s)', user_data['login'], user_data['id'])
|
||||
|
||||
# Finally attempt to reinstate the missing constraint
|
||||
try:
|
||||
|
||||
@@ -58,8 +58,8 @@ def short_name(name):
|
||||
but distinctive"""
|
||||
if not name: return name
|
||||
# keep 7 chars + end of the last word
|
||||
hardcut_tokens = name[:7].split()
|
||||
return ' '.join(name.split()[:len(hardcut_tokens)])
|
||||
keep_words = name[:7].strip().split()
|
||||
return ' '.join(name.split()[:len(keep_words)])
|
||||
|
||||
class project(osv.osv):
|
||||
_name = "project.project"
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
<field name="name" string="Project Name"/>
|
||||
</h1>
|
||||
<div attrs="{'invisible': [('alias_domain', '=', False)]}">
|
||||
<field name="id" invisible="1"/>
|
||||
<field name="alias_name" class="oe_inline" attrs="{'required': [('id', '!=', False)]}"/>@<field name="alias_domain" class="oe_inline"/>
|
||||
</div>
|
||||
<group>
|
||||
|
||||
Reference in New Issue
Block a user