Browse Source
[ADD] First commit of the first generic modules to move in our new public branch
[ADD] First commit of the first generic modules to move in our new public branch
(lp:c2c-addons/6.1 rev 1)pull/7/head
Joël Grand-Guillaume
13 years ago
commit
6e8e680029
12 changed files with 1116 additions and 0 deletions
-
36partner_address_ldap/__init__.py
-
68partner_address_ldap/__openerp__.py
-
459partner_address_ldap/address.py
-
115partner_address_ldap/address_view.xml
-
76partner_address_ldap/company.py
-
25partner_address_ldap/company_view.xml
-
82partner_address_ldap/i18n/fr_FR.po
-
50partner_address_ldap/partner.py
-
4partner_address_ldap/security/security.xml
-
10partner_address_ldap/wizard.xml
-
32partner_address_ldap/wizard/__init__.py
-
159partner_address_ldap/wizard/wiz_import_adresses.py
@ -0,0 +1,36 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) |
|||
# All Right Reserved |
|||
# |
|||
# Author : Nicolas Bessi (Camptocamp), Thanks to Laurent Lauden for his code adaptation |
|||
# Contribution : Joel Grand-Guillaume |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsability of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# garantees and support are strongly adviced to contract a Free Software |
|||
# Service Company |
|||
# |
|||
# 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 2 |
|||
# 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, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
|
|||
import address |
|||
import partner |
|||
import company |
|||
import wizard |
@ -0,0 +1,68 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) |
|||
# All Right Reserved |
|||
# |
|||
# Author : Nicolas Bessi (Camptocamp), Thanks to Laurent Lauden for his code adaptation |
|||
# Active directory Donor: M. Benadiba (Informatique Assistances.fr) |
|||
# Contribution : Joel Grand-Guillaume |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsability of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# garantees and support are strongly adviced to contract a Free Software |
|||
# Service Company |
|||
# |
|||
# 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 2 |
|||
# 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, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
|
|||
{ |
|||
"name" : "Partner synchronization from OpenERP to ldap", |
|||
"version" : "1.2", |
|||
"author" : "Camptocamp", |
|||
"depends" : ["base"], |
|||
"category" : "Generic Modules/Misc", |
|||
"website": "http://www.camptocamp.com", |
|||
"description": """ |
|||
|
|||
Live partner address synchronization through a LDAP module (inetOrgPerson). |
|||
OpenERP becomes the master of the LDAP. Each time an address is deleted, created or updated the same is done in the ldap (a new record is pushed). |
|||
The LDAP configuration is done in the company view. There can be one different LDAP per company. Do not forget to activate |
|||
the LDAP link in the configuration. |
|||
The used LDAP depends on the current user company. |
|||
|
|||
This module does not allows bulk batching synchronisation into the LDAP and is thus not suitable for an instant use with an existing LDAP. |
|||
In order to use it with an existing LDAP you have to alter the uid of contact in your LDAP. The uid should be terp_ plus the OpenERP |
|||
contact id (for example terp_10). |
|||
|
|||
N.B: |
|||
The module requires the python-ldap library |
|||
Unicode support --> As python ldap does not support unicode we try to decode string if it fails we transliterate values. |
|||
Active Directory Support for Windows server 2003, try 2008 at your own risk |
|||
(AD support not tested for Version 6 of OpenERP looking for active dir test infra) |
|||
|
|||
|
|||
""", |
|||
"init_xml" : ["security/security.xml"], |
|||
"update_xml":['company_view.xml', |
|||
'address_view.xml', |
|||
"wizard.xml"], |
|||
"demo_xml" : [], |
|||
"active": False, |
|||
"installable": True |
|||
} |
@ -0,0 +1,459 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (c) 2010-2011 Camptocamp SA (http://www.camptocamp.com) |
|||
# All Right Reserved |
|||
# |
|||
# Author : Nicolas Bessi (Camptocamp), Thanks to Laurent Lauden for his code adaptation |
|||
# Active directory Donor: M. Benadiba (Informatique Assistances.fr) |
|||
# Contribution : Joel Grand-Guillaume |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsability of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# garantees and support are strongly adviced to contract a Free Software |
|||
# Service Company |
|||
# |
|||
# 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 2 |
|||
# 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, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
#TODO FInd why company parameter are cached |
|||
import re |
|||
import unicodedata |
|||
import netsvc |
|||
try: |
|||
import ldap |
|||
import ldap.modlist |
|||
except : |
|||
print 'python ldap not installed please install it in order to use this module' |
|||
|
|||
|
|||
from osv import osv, fields |
|||
from tools.translate import _ |
|||
|
|||
logger = netsvc.Logger() |
|||
|
|||
class LdapConnMApper(object): |
|||
"""LdapConnMApper: push specific fields from the Terp Partner_contacts to the |
|||
LDAP schema inetOrgPerson. Ldap bind options are stored in company.r""" |
|||
def __init__(self, cursor, uid, osv_obj, context=None): |
|||
"""Initialize connexion to ldap by using parameter set in the current user compagny""" |
|||
logger.notifyChannel("MY TOPIC", netsvc.LOG_DEBUG, |
|||
_('Initalize LDAP CONN')) |
|||
self.USER_DN = '' |
|||
self.CONTACT_DN = '' |
|||
self.LDAP_SERVER = '' |
|||
self.PASS = '' |
|||
self.OU = '' |
|||
self.connexion = '' |
|||
self.ACTIVDIR = False |
|||
|
|||
#Reading ldap pref |
|||
user = osv_obj.pool.get('res.users').browse(cursor, uid, uid, context=context) |
|||
company = osv_obj.pool.get('res.company').browse(cursor, |
|||
uid, |
|||
user.company_id.id, |
|||
context=context) |
|||
self.USER_DN = company.base_dn |
|||
self.CONTACT_DN = company.contact_dn |
|||
self.LDAP_SERVER = company.ldap_server |
|||
self.PASS = company.passwd |
|||
self.PORT = company.ldap_port |
|||
self.OU = company.ounit |
|||
self.ACTIVDIR = company.is_activedir |
|||
|
|||
mand = (self.USER_DN, self.CONTACT_DN, self.LDAP_SERVER , self.PASS, self.OU) |
|||
if company.ldap_active: |
|||
for param in mand: |
|||
if not param: |
|||
raise osv.except_osv(_('Warning !'), |
|||
_('An LDAP parameter is missing for company %s') % (company.name,)) |
|||
|
|||
def get_connexion(self): |
|||
"""create a new ldap connexion""" |
|||
logger.notifyChannel("LDAP Address", netsvc.LOG_DEBUG, |
|||
_('connecting to server ldap %s') % (self.LDAP_SERVER,)) |
|||
if self.PORT : |
|||
self.connexion = ldap.open(self.LDAP_SERVER, self.PORT) |
|||
else : |
|||
self.connexion = ldap.open(self.LDAP_SERVER) |
|||
self.connexion.simple_bind_s(self.USER_DN, self.PASS) |
|||
return self.connexion |
|||
|
|||
|
|||
class LDAPAddress(osv.osv): |
|||
"""Override the CRUD of the objet in order to dynamically bind to ldap""" |
|||
_inherit = 'res.partner.address' |
|||
ldapMapper = None |
|||
|
|||
def init(self, cr): |
|||
logger = netsvc.Logger() |
|||
try: |
|||
logger.notifyChannel(_('LDAP address init'), |
|||
netsvc.LOG_INFO, |
|||
_('try to ALTER TABLE res_partner_address RENAME ' |
|||
'column name to lastname ;')) |
|||
cr.execute('ALTER TABLE res_partner_address RENAME column name to lastname ;') |
|||
|
|||
except Exception, e: |
|||
cr.rollback() |
|||
logger.notifyChannel(_('LDAP address init'), |
|||
netsvc.LOG_INFO, |
|||
_('Warning ! impossible to rename column name' |
|||
' into lastname, this is probabely aleready' |
|||
' done or does not exist')) |
|||
|
|||
def _compute_name(self, firstname, lastname): |
|||
firstname = firstname or u'' |
|||
lastname = lastname or u'' |
|||
firstname = (u' '+ firstname).rstrip() |
|||
return u"%s%s" % (lastname, firstname) |
|||
|
|||
def _name_get_fnc(self, cursor, uid, ids, name, arg, context=None): |
|||
"""Get the name (lastname + firstname), otherwise ''""" |
|||
if not ids: |
|||
return [] |
|||
reads = self.read(cursor, uid, ids, ['lastname', 'firstname']) |
|||
res = [] |
|||
for record in reads: |
|||
## We want to have " firstname" or "" |
|||
name = self._compute_name(record['firstname'], record['lastname']) |
|||
res.append((record['id'], name)) |
|||
return dict(res) |
|||
|
|||
# TODO get the new version of name search not vulnerable to sql injections |
|||
# def name_search(self, cursor, user, name, args=None, operator='ilike', context=None, limit=100): |
|||
# if not context: context = {} |
|||
# prep_name = '.*%s.*' %(name) |
|||
# cursor.execute(("select id from res_partner_address where" |
|||
# " (to_ascii(convert( lastname, 'UTF8', 'LATIN1'),'LATIN-1') ~* '%s'" |
|||
# " or to_ascii(convert( firstname, 'UTF8', 'LATIN1'),'LATIN-1') ~* '%s')" |
|||
# " limit %s") % (prep_name, prep_name, limit)) |
|||
# res = cursor.fetchall() |
|||
# if res: |
|||
# res = [x[0] for x in res] |
|||
# else: |
|||
# res = [] |
|||
# # search in partner name to know if we are searching partner... |
|||
# partner_obj=self.pool.get('res.partner') |
|||
# part_len = len(res)-limit |
|||
# if part_len > 0: |
|||
# partner_res = partner_obj.search(cursor, user, [('name', 'ilike', name)], |
|||
# limit=part_len, context=context) |
|||
# for p in partner_res: |
|||
# addresses = partner_obj.browse(cursor, user, p).address |
|||
# # Take each contact and add it to |
|||
# for add in addresses: |
|||
# res.append(add.id) |
|||
# return self.name_get(cursor, user, res, context) |
|||
|
|||
|
|||
_columns = { |
|||
'firstname': fields.char('First name', size=256), |
|||
'lastname': fields.char('Last name', size=256), |
|||
'name': fields.function(_name_get_fnc, method=True, |
|||
type="char", size=512, |
|||
store=True, string='Contact Name', |
|||
help='Name generated from the first name and last name', |
|||
nodrop=True), |
|||
'private_phone':fields.char('Private phone', size=128), |
|||
} |
|||
|
|||
def create(self, cursor, uid, vals, context={}): |
|||
self.getconn(cursor, uid, {}) |
|||
ids = None |
|||
self.validate_entries(vals, cursor, uid, ids) |
|||
tmp_id = super(LDAPAddress, self).create(cursor, uid, |
|||
vals, context) |
|||
if self.ldaplinkactive(cursor, uid, context): |
|||
self.saveLdapContact(tmp_id, vals, cursor, uid, context) |
|||
return tmp_id |
|||
|
|||
def write(self, cursor, uid, ids, vals, context=None): |
|||
context = context or {} |
|||
self.getconn(cursor, uid, {}) |
|||
if not isinstance(ids, list): |
|||
ids = [ids] |
|||
if ids: |
|||
self.validate_entries(vals, cursor, uid, ids) |
|||
if context.has_key('init_mode') and context['init_mode'] : |
|||
success = True |
|||
else : |
|||
success = super(LDAPAddress, self).write(cursor, uid, ids, |
|||
vals, context) |
|||
if self.ldaplinkactive(cursor, uid, context): |
|||
for address_id in ids: |
|||
self.updateLdapContact(address_id, vals, cursor, uid, context) |
|||
return success |
|||
|
|||
def unlink(self, cursor, uid, ids, context=None): |
|||
if not context: context = {} |
|||
if ids: |
|||
self.getconn(cursor, uid, {}) |
|||
if not isinstance(ids, list): |
|||
ids = [ids] |
|||
if self.ldaplinkactive(cursor, uid, context): |
|||
for id in ids: |
|||
self.removeLdapContact(id, cursor, uid) |
|||
return super(LDAPAddress, self).unlink(cursor, uid, ids) |
|||
|
|||
def validate_entries(self, vals, cursor, uid, ids): |
|||
"""Validate data of an address based on the inetOrgPerson schema""" |
|||
for val in vals : |
|||
try : |
|||
if isinstance(vals[val], basestring): |
|||
vals[val] = unicode(vals[val].decode('utf8')) |
|||
except UnicodeError: |
|||
logger.notifyChannel('LDAP encode', netsvc.LOG_DEBUG, |
|||
'cannot unicode '+ vals[val]) |
|||
pass |
|||
|
|||
if ids is not None: |
|||
if isinstance(ids, (int, long)): |
|||
ids = [ids] |
|||
if len(ids) == 1: |
|||
self.addNeededFields(ids[0],vals,cursor,uid) |
|||
email = vals.get('email', False) |
|||
phone = vals.get('phone', False) |
|||
fax = vals.get('fax', False) |
|||
mobile = vals.get('mobile', False) |
|||
lastname = vals.get('lastname', False) |
|||
private_phone = vals.get('private_phone', False) |
|||
if email : |
|||
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", |
|||
email) is None: |
|||
raise osv.except_osv(_('Warning !'), |
|||
_('Please enter a valid e-mail')) |
|||
phones = (('phone', phone), ('fax', fax), ('mobile', mobile), |
|||
('private_phone', private_phone)) |
|||
for phone_tuple in phones: |
|||
phone_number = phone_tuple[1] |
|||
if phone_number : |
|||
if not phone_number.startswith('+'): |
|||
raise osv.except_osv(_('Warning !'), |
|||
_('Please enter a valid phone number in %s' |
|||
' international format (i.e. leading +)') % phone_tuple[0]) |
|||
|
|||
def getVals(self, att_name, key, vals, dico, uid, ids, cursor, context=None): |
|||
"""map to values to dict""" |
|||
if not context: context = {} |
|||
## We explicitely test False value |
|||
if vals.get(key, False) != False: |
|||
dico[att_name] = vals[key] |
|||
else : |
|||
if context.get('init_mode'): |
|||
return False |
|||
tmp = self.read(cursor, uid, ids, [key], context={}) |
|||
if tmp.get(key, False) : |
|||
dico[att_name] = tmp[key] |
|||
|
|||
|
|||
def _un_unicodize_buf(self, in_buf): |
|||
if isinstance(in_buf, unicode) : |
|||
try: |
|||
return in_buf.encode() |
|||
except Exception, e: |
|||
return unicodedata.normalize("NFKD", in_buf).encode('ascii','ignore') |
|||
return in_buf |
|||
|
|||
def unUnicodize(self, indict) : |
|||
"""remove unicode data of modlist as unicode is not supported |
|||
by python-ldap librairy till version 2.7""" |
|||
for key in indict : |
|||
if not isinstance(indict[key], list): |
|||
indict[key] = self._un_unicodize_buf(indict[key]) |
|||
else: |
|||
nonutfArray = [] |
|||
for val in indict[key] : |
|||
nonutfArray.append(self._un_unicodize_buf(val)) |
|||
indict[key] = nonutfArray |
|||
|
|||
def addNeededFields(self, id, vals, cursor, uid): |
|||
keys = vals.keys() |
|||
previousvalue = self.browse(cursor, uid, [id])[0] |
|||
if not vals.get('partner_id'): |
|||
vals['partner_id'] = previousvalue.partner_id.id |
|||
values_to_check = ('email', 'phone', 'fax', 'mobile', 'firstname', |
|||
'lastname', 'private_phone', 'street', 'street2') |
|||
for val in values_to_check: |
|||
if not vals.get(val): |
|||
vals[val] = previousvalue[val] |
|||
|
|||
def mappLdapObject(self, id, vals, cursor, uid, context): |
|||
"""Mapp ResPArtner adress to moddlist""" |
|||
self.addNeededFields(id, vals, cursor, uid) |
|||
conn = self.getconn(cursor, uid, {}) |
|||
keys = vals.keys() |
|||
partner_obj=self.pool.get('res.partner') |
|||
part_name = partner_obj.browse(cursor, uid, vals['partner_id']).name |
|||
vals['partner'] = part_name |
|||
name = self._compute_name(vals.get('firstname'), vals.get('lastname')) |
|||
if name : |
|||
cn = name |
|||
else: |
|||
cn = part_name |
|||
if not vals.get('lastname') : |
|||
vals['lastname'] = part_name |
|||
contact_obj = {'objectclass' : ['inetOrgPerson'], |
|||
'uid': ['terp_'+str(id)], |
|||
'ou':[conn.OU], |
|||
'cn':[cn], |
|||
'sn':[vals['lastname']]} |
|||
if not vals.get('street'): |
|||
vals['street'] = u'' |
|||
if not vals.get('street2'): |
|||
vals['street2'] = u'' |
|||
street_key = 'street' |
|||
if self.getconn(cursor, uid, {}).ACTIVDIR : |
|||
# ENTERING THE M$ Realm and it is weird |
|||
# We manage the address |
|||
street_key = 'streetAddress' |
|||
contact_obj[street_key] = vals['street'] + "\r\n" + vals['street2'] |
|||
#we modifiy the class |
|||
contact_obj['objectclass'] = ['top','person','organizationalPerson','inetOrgPerson','user'] |
|||
#we handle the country |
|||
if vals.get('country_id') : |
|||
country = self.browse(cursor, uid, id).country_id |
|||
if country : |
|||
vals['country_id'] = country.name |
|||
vals['c'] = country.code |
|||
else : |
|||
vals['country_id'] = False |
|||
vals['c'] = False |
|||
if vals.get('country_id', False) : |
|||
self.getVals('co', 'country_id', vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('c', 'c', vals, contact_obj, uid, id, cursor, context) |
|||
# we compute the display name |
|||
vals['display'] = '%s %s'%(vals['partner'], contact_obj['cn'][0]) |
|||
# we get the title |
|||
if self.browse(cursor, uid, id).function: |
|||
contact_obj['description'] = self.browse(cursor, uid, id).function.name |
|||
# we replace carriage return |
|||
if vals.get('comment', False): |
|||
vals['comment'] = vals['comment'].replace("\n","\r\n") |
|||
# Active directory specific fields |
|||
self.getVals('company', 'partner' ,vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('info', 'comment' ,vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('displayName', 'partner' ,vals, contact_obj, uid, id, cursor, context) |
|||
## Web site management |
|||
if self.browse(cursor, uid, id).partner_id.website: |
|||
vals['website'] = self.browse(cursor, uid, id).partner_id.website |
|||
self.getVals('wWWHomePage', 'website', vals, contact_obj, uid, id, cursor, context) |
|||
del(vals['website']) |
|||
self.getVals('title', 'title', vals, contact_obj, uid, id, cursor, context) |
|||
else : |
|||
contact_obj[street_key] = vals['street'] + u"\n" + vals['street2'] |
|||
self.getVals('o','partner' ,vals, contact_obj, uid, id, cursor, context) |
|||
|
|||
#Common attributes |
|||
self.getVals('givenName', 'firstname',vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('mail', 'email',vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('telephoneNumber', 'phone',vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('l', 'city',vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('facsimileTelephoneNumber', 'fax',vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('mobile', 'mobile',vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('homePhone', 'private_phone',vals, contact_obj, uid, id, cursor, context) |
|||
self.getVals('postalCode', 'zip',vals, contact_obj, uid, id, cursor, context) |
|||
self.unUnicodize(contact_obj) |
|||
return contact_obj |
|||
|
|||
def saveLdapContact(self, id, vals, cursor, uid, context=None): |
|||
"""save openerp adress to ldap""" |
|||
contact_obj = self.mappLdapObject(id,vals,cursor,uid,context) |
|||
conn = self.connectToLdap(cursor, uid, context=context) |
|||
try: |
|||
if self.getconn(cursor, uid, context).ACTIVDIR: |
|||
conn.connexion.add_s("CN=%s,OU=%s,%s"%(contact_obj['cn'][0], conn.OU, conn.CONTACT_DN), |
|||
ldap.modlist.addModlist(contact_obj)) |
|||
else: |
|||
conn.connexion.add_s("uid=terp_%s,OU=%s,%s"%(str(id), conn.OU, conn.CONTACT_DN), |
|||
ldap.modlist.addModlist(contact_obj)) |
|||
except Exception, e: |
|||
raise e |
|||
conn.connexion.unbind_s() |
|||
|
|||
def updateLdapContact(self, id, vals, cursor, uid, context): |
|||
"""update an existing contact with the data of OpenERP""" |
|||
conn = self.connectToLdap(cursor,uid,context={}) |
|||
try: |
|||
old_contatc_obj = self.getLdapContact(conn,id) |
|||
except ldap.NO_SUCH_OBJECT: |
|||
self.saveLdapContact(id,vals,cursor,uid,context) |
|||
return |
|||
contact_obj = self.mappLdapObject(id,vals,cursor,uid,context) |
|||
if conn.ACTIVDIR: |
|||
modlist = [] |
|||
for key, val in contact_obj.items() : |
|||
if key in ('cn', 'uid', 'objectclass'): |
|||
continue |
|||
if isinstance(val, list): |
|||
val = val[0] |
|||
modlist.append((ldap.MOD_REPLACE, key, val)) |
|||
else : |
|||
modlist = ldap.modlist.modifyModlist(old_contatc_obj[1], contact_obj) |
|||
try: |
|||
conn.connexion.modify_s(old_contatc_obj[0], modlist) |
|||
conn.connexion.unbind_s() |
|||
except Exception, e: |
|||
raise e |
|||
|
|||
def removeLdapContact(self, id, cursor, uid): |
|||
"""Remove a contact from ldap""" |
|||
conn = self.connectToLdap(cursor,uid,context={}) |
|||
to_delete = None |
|||
try: |
|||
to_delete = self.getLdapContact(conn,id) |
|||
except ldap.NO_SUCH_OBJECT: |
|||
logger.notifyChannel("Warning", netsvc.LOG_INFO, |
|||
_("'no object to delete in ldap' %s") %(id)) |
|||
except Exception, e : |
|||
raise e |
|||
try: |
|||
if to_delete : |
|||
conn.connexion.delete_s(to_delete[0]) |
|||
conn.connexion.unbind_s() |
|||
except Exception, e: |
|||
raise e |
|||
|
|||
def getLdapContact(self, conn, id): |
|||
result = conn.connexion.search_ext_s("ou=%s,%s"%(conn.OU,conn.CONTACT_DN), |
|||
ldap.SCOPE_SUBTREE, |
|||
"(&(objectclass=*)(uid=terp_"+str(id)+"))") |
|||
if not result: |
|||
raise ldap.NO_SUCH_OBJECT |
|||
return result[0] |
|||
|
|||
def ldaplinkactive(self, cursor, uid, context=None): |
|||
"""Check if ldap is activated for this company""" |
|||
user = self.pool.get('res.users').browse(cursor, uid, uid, context=context) |
|||
company = self.pool.get('res.company').browse(cursor, uid,user.company_id.id, context=context) |
|||
return company.ldap_active |
|||
|
|||
def getconn(self, cursor, uid, context=None): |
|||
"""LdapConnMApper""" |
|||
if not self.ldapMapper : |
|||
self.ldapMapper = LdapConnMApper(cursor, uid, self) |
|||
return self.ldapMapper |
|||
|
|||
def connectToLdap(self, cursor, uid, context=None): |
|||
"""Reinitialize ldap connection""" |
|||
#getting ldap pref |
|||
if not self.ldapMapper : |
|||
self.getconn(cursor, uid, context) |
|||
self.ldapMapper.get_connexion() |
|||
return self.ldapMapper |
|||
|
|||
LDAPAddress() |
@ -0,0 +1,115 @@ |
|||
<openerp> |
|||
<data> |
|||
#--------------------------------------------------------------------------------------------------------- |
|||
# Partner form->contact and tree view of address |
|||
#--------------------------------------------------------------------------------------------------------- |
|||
<record model="ir.ui.view" id="base.view_partner_address_tree"> |
|||
<field name="name">res.partner.address.tree</field> |
|||
<field name="model">res.partner.address</field> |
|||
<field name="type">tree</field> |
|||
<field name="arch" type="xml"> |
|||
<tree string="Partner contacts"> |
|||
<field name="partner_id" /> |
|||
<field name="firstname" /> |
|||
<field name="lastname" /> |
|||
<field name="phone"/> |
|||
<field name="email"/> |
|||
<field name="zip"/> |
|||
<field name="city"/> |
|||
<field name="country_id"/> |
|||
<field name="type"/> |
|||
</tree> |
|||
</field> |
|||
</record> |
|||
|
|||
<record model="ir.ui.view" id="view_partner_address_form1_inherit_ldap2"> |
|||
<field name="name">res.partner.address.form1.c2c_partner_adress</field> |
|||
<field name="model">res.partner.address</field> |
|||
<field name="type">form</field> |
|||
<field name="inherit_id" ref="base.view_partner_address_form1" /> |
|||
<field name="priority" eval="16" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="name" position="replace"> |
|||
<field name="name" invisible="1" select="2"/> |
|||
<field name="firstname"/> |
|||
<field name="lastname"/> |
|||
<newline/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
<record model="ir.ui.view" id="view_partner_address_form1_inherit_ldap"> |
|||
<field name="name">res.partner.address.form1.c2c_partner_adress</field> |
|||
<field name="model">res.partner.address</field> |
|||
<field name="type">form</field> |
|||
<field name="inherit_id" ref="base.view_partner_address_form1" /> |
|||
<field name="priority" eval="17" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="mobile" position="after"> |
|||
<field name="private_phone"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
|
|||
<!-- |
|||
========================================= |
|||
the short form used in the partner form |
|||
========================================= |
|||
--> |
|||
|
|||
<record model="ir.ui.view" id="view_partner_address_form_inerit_ldap"> |
|||
<field name="name">res.partner.address.form2_c2c_partner_address</field> |
|||
<field name="model">res.partner.address</field> |
|||
<field name="type">form</field> |
|||
<field name="priority" eval="16" /> |
|||
<field name="inherit_id" ref="base.view_partner_address_form2" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="name" select="1" position="replace"> |
|||
<field name="name" invisible="1" select="2"/> |
|||
<field name="firstname"/> |
|||
<field name="lastname"/> |
|||
<newline/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
|
|||
<record model="ir.ui.view" id="view_partner_address_form2_inerit_ldap"> |
|||
<field name="name">res.partner.address.form2_c2c_partner_address</field> |
|||
<field name="model">res.partner.address</field> |
|||
<field name="type">form</field> |
|||
<field name="inherit_id" ref="base.view_partner_address_form2" /> |
|||
<field name="priority" eval="17" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="mobile" position="after"> |
|||
<field name="private_phone"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
|
|||
<!-- |
|||
========================================= |
|||
the short form used in the res_partner standard form |
|||
========================================= |
|||
--> |
|||
<record model="ir.ui.view" id="view_partner_form_inherite_contact_ldap"> |
|||
<field name="name">res.partner.form2_partner_address</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="type">form</field> |
|||
<field name="inherit_id" ref="base.view_partner_form" /> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="/form/notebook/page/field[@name='address']/form/group/field[@name='mobile']" position="after"> |
|||
<field name="private_phone"/> |
|||
</xpath> |
|||
<xpath expr="/form/notebook/page/field[@name='address']/form/group/field[@name='name']" position="replace"> |
|||
<field name="firstname"/> |
|||
<field name="lastname"/> |
|||
<newline/> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,76 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) |
|||
# All Right Reserved |
|||
# |
|||
# Author : Nicolas Bessi (Camptocamp), Thanks to Laurent Lauden for his code adaptation |
|||
# Active directory Donor: M. Benadiba (Informatique Assistances.fr) |
|||
# Contribution : Joel Grand-Guillaume |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsability of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# garantees and support are strongly adviced to contract a Free Software |
|||
# Service Company |
|||
# |
|||
# 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 2 |
|||
# 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, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
|
|||
from osv import osv, fields |
|||
|
|||
class Res_company(osv.osv): |
|||
"""Defin ldap connexion parameters""" |
|||
|
|||
_inherit = 'res.company' |
|||
_columns = { |
|||
'base_dn': fields.char( |
|||
'User dn', |
|||
size=128, |
|||
help="Exemple: cn=contacts_admin,dc=ldap,dc=dcc2c" |
|||
), |
|||
'contact_dn': fields.char( |
|||
'Bind dn', |
|||
size=128, |
|||
help="Exemple: dc=ldap,dc=dcc2c -- watchout" +\ |
|||
" the OU will be automatically included inside" |
|||
), |
|||
'ounit': fields.char( |
|||
'Contact Organizational unit of the contacts', |
|||
size=128, |
|||
help="Exemple: Contacts" |
|||
), |
|||
'ldap_server': fields.char( |
|||
'Server address', |
|||
size=128, |
|||
help="Exemple: ldap.camptocamp.com" |
|||
), |
|||
'passwd': fields.char('ldap password', size=128, help="Exemple: Mypassword1234"), |
|||
'ldap_active': fields.boolean( |
|||
'Activate ldap link for this company', |
|||
help='If not check nothing will be reported into the ldap' |
|||
), |
|||
'is_activedir': fields.boolean( |
|||
'Active Directory ?', |
|||
help='The ldap is part of an Active Directory' |
|||
), |
|||
'ldap_port': fields.integer('LDAP Port', |
|||
help="If not specified, the default port" |
|||
"(389), will be used") |
|||
} |
|||
|
|||
Res_company() |
@ -0,0 +1,25 @@ |
|||
<?xml version="1.0"?> |
|||
<openerp> |
|||
<data> |
|||
<record model="ir.ui.view" id="view_company_for_ldap"> |
|||
<field name="name">res.company.form</field> |
|||
<field name="model">res.company</field> |
|||
<field name="inherit_id" ref="base.view_company_form"/> |
|||
<field name="type">form</field> |
|||
<field name="arch" type="xml"> |
|||
<page string="Configuration" position="after"> |
|||
<page string="LDAP"> |
|||
<field name="ldap_active" /> |
|||
<field name="is_activedir" attrs="{'readonly':[('ldap_active', '=', False)]}"/> |
|||
<field name="ldap_server" attrs="{'readonly':[('ldap_active', '=', False)]}"/> |
|||
<field name="ldap_port" attrs="{'readonly':[('ldap_active', '=', False)]}"/> |
|||
<field name="base_dn" attrs="{'readonly':[('ldap_active', '=', False)]}"/> |
|||
<field name="contact_dn" attrs="{'readonly':[('ldap_active', '=', False)]}"/> |
|||
<field name="ounit" attrs="{'readonly':[('ldap_active', '=', False)]}"/> |
|||
<field name="passwd" attrs="{'readonly':[('ldap_active', '=', False)]}"/> |
|||
</page> |
|||
</page> |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
@ -0,0 +1,82 @@ |
|||
# Translation of OpenERP Server. |
|||
# This file contains the translation of the following modules: |
|||
# * c2c_contact_to_ldap |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: OpenERP Server 5.0.7\n" |
|||
"Report-Msgid-Bugs-To: support@openerp.com\n" |
|||
"POT-Creation-Date: 2010-02-01 15:06:40+0000\n" |
|||
"PO-Revision-Date: 2010-02-01 15:06:40+0000\n" |
|||
"Last-Translator: <>\n" |
|||
"Language-Team: \n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=UTF-8\n" |
|||
"Content-Transfer-Encoding: \n" |
|||
"Plural-Forms: \n" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: field:res.company,is_activedir:0 |
|||
msgid "Active Directory ?" |
|||
msgstr "" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: model:ir.actions.wizard,name:c2c_contact_to_ldap.ldap_import_adresses |
|||
msgid "Export addresses to company LDAP" |
|||
msgstr "Exporte les adresses de OpenERP vers LDAP" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: wizard_field:ldap.import_adresses,importadd,errors:0 |
|||
msgid "Error report" |
|||
msgstr "Rapport d'erreur" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: constraint:ir.ui.view:0 |
|||
msgid "Invalid XML for View Architecture!" |
|||
msgstr "XML non valide pour l'architecture de la vue" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: wizard_button:ldap.import_adresses,init,importadd:0 |
|||
msgid "Export adresses into company LDAP" |
|||
msgstr "Exportation des adresses vers le ldap spécifié dans la société" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: wizard_view:ldap.import_adresses,importadd:0 |
|||
msgid "Export log" |
|||
msgstr "Log d'exportation" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: wizard_view:ldap.import_adresses,importadd:0 |
|||
msgid "Clic on 'Save as' to save the log file :" |
|||
msgstr "Cliquez sur save as pour sauvegarder le fichier" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: help:res.company,is_activedir:0 |
|||
msgid "The ldap is part of an Active Directory" |
|||
msgstr "Le ldap est un ldap Active Directory" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: wizard_button:ldap.import_adresses,importadd,end:0 |
|||
msgid "OK" |
|||
msgstr "" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: wizard_view:ldap.import_adresses,init:0 |
|||
msgid "Export adresses to ldap" |
|||
msgstr "Exporter les adresses dans le ldap" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: wizard_button:ldap.import_adresses,init,end:0 |
|||
msgid "Cancel" |
|||
msgstr "Annuler" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: field:res.company,ounit:0 |
|||
msgid "Contact Organizational unit of the contacts" |
|||
msgstr "OU (organizational unit des adresses)" |
|||
|
|||
#. module: c2c_contact_to_ldap |
|||
#: help:res.company,ounit:0 |
|||
msgid "Exemple: Contacts" |
|||
msgstr "" |
|||
|
@ -0,0 +1,50 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) |
|||
# All Right Reserved |
|||
# |
|||
# Author : Nicolas Bessi (Camptocamp), Thanks to Laurent Lauden for his code adaptation |
|||
# Active directory Donor: M. Benadiba (Informatique Assistances.fr) |
|||
# Contribution : Joel Grand-Guillaume |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsability of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# garantees and support are strongly adviced to contract a Free Software |
|||
# Service Company |
|||
# |
|||
# 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 2 |
|||
# 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, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
|
|||
from osv import osv, fields |
|||
|
|||
class LdapPartner(osv.osv): |
|||
"""Ensure that when deleting a partner unlink function is called on all |
|||
related addresses""" |
|||
_inherit = 'res.partner' |
|||
|
|||
def unlink(self, cursor, uid, ids, context=None): |
|||
context = context or {} |
|||
addr_obj = self.pool.get('res.partner.address') |
|||
if not isinstance(ids, list): |
|||
ids = [ids] |
|||
addr_ids = addr_obj.search(cursor, uid, [('partner_id', 'in', ids)]) |
|||
addr_obj.unlink(cursor, uid, addr_ids, context=context) |
|||
return super(LdapPartner, self).unlink(cursor, uid, ids, context=context) |
|||
|
|||
LdapPartner() |
@ -0,0 +1,4 @@ |
|||
<openerp> |
|||
<data> |
|||
</data> |
|||
</openerp> |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0"?> |
|||
<openerp> |
|||
<data> |
|||
<wizard |
|||
string="Export addresses to company LDAP" |
|||
model="res.company" |
|||
name="ldap.import_adresses" |
|||
id="ldap_import_adresses"/> |
|||
</data> |
|||
</openerp> |
@ -0,0 +1,32 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) |
|||
# All Right Reserved |
|||
# |
|||
# Author : Vincent Renaville |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsability of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# garantees and support are strongly adviced to contract a Free Software |
|||
# Service Company |
|||
# |
|||
# 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 2 |
|||
# 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, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
|
|||
import wiz_import_adresses |
@ -0,0 +1,159 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) |
|||
# All Right Reserved |
|||
# |
|||
# Author : Vincent Renaville |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsability of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# garantees and support are strongly adviced to contract a Free Software |
|||
# Service Company |
|||
# |
|||
# 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 2 |
|||
# 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, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
|
|||
# init_import.py |
|||
# |
|||
# Created by Nicolas Bessi on 28.04.09. |
|||
# Copyright (c) 2009 CamptoCamp. All rights reserved. |
|||
# |
|||
|
|||
import wizard |
|||
import pooler |
|||
import base64 |
|||
import unicodedata |
|||
import netsvc |
|||
import re |
|||
_FORM = '''<?xml version="1.0"?> |
|||
<form string="Export adresses to ldap"> |
|||
</form>''' |
|||
|
|||
|
|||
_FORM1 = """<?xml version="1.0"?> |
|||
<form string="Export log"> |
|||
<separator colspan="4" string="Clic on 'Save as' to save the log file :" /> |
|||
<field name="errors"/> |
|||
</form> |
|||
""" |
|||
|
|||
_FIELDS = { |
|||
'errors': { |
|||
'string': 'Error report', |
|||
'type': 'binary', |
|||
'readonly': True, |
|||
}, |
|||
} |
|||
|
|||
### As this is a bulck batch wizzard the performance process was not reallay taken in account ### |
|||
##The ideal way of doing would be to modify the connexion settings in order to have a connexion singelton |
|||
## in the file partner.py it will avoid connexion renegotiation for each partner. |
|||
def _action_import_adresses(self, cr, uid, data, context): |
|||
""" This function create or update each adresses present in the database. |
|||
It will also genreate an error report""" |
|||
logger = netsvc.Logger() |
|||
error_report = [u'Error report'] |
|||
add_obj = pooler.get_pool(cr.dbname).get('res.partner.address') |
|||
add_ids = add_obj.search(cr,uid,[]) |
|||
addresses = add_obj.browse(cr, uid, add_ids) |
|||
phone_fields = ['phone','fax','mobile','private_phone'] |
|||
for add in addresses : |
|||
vals = {} |
|||
vals['partner_id'] = add.partner_id.id |
|||
vals['email'] = add.email |
|||
vals['phone'] = add.phone |
|||
vals['fax'] = add.fax |
|||
vals['mobile'] = add.mobile |
|||
vals['firstname'] = add.firstname |
|||
vals['lastname'] = add.lastname |
|||
vals['private_phone'] = add.private_phone |
|||
vals['street'] = add.street |
|||
vals['street2'] = add.street2 |
|||
vals['city'] = add.city |
|||
# Validating the mail |
|||
if add.email : |
|||
if re.match( |
|||
"^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", add.email) is None or\ |
|||
re.search(u"[éèàêöüäï&]", add.email) is not None: |
|||
msg=u'Addresse %s for partner %s has email that is invalid %s'%( |
|||
unicode(vals['firstname']) +' '+ unicode(vals['lastname']), |
|||
add.partner_id.name, |
|||
unicode(add.email) |
|||
) |
|||
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg) |
|||
error_report.append(msg) |
|||
vals['email'] = False |
|||
# Validating the Phone |
|||
for key in phone_fields : |
|||
if not unicode(vals[key]).startswith('+') or unicode(vals[key]).find("\n") != -1\ |
|||
or re.search(u"[éèàêöüä#&]", unicode(vals[key])) is not None: |
|||
vals[key] = False |
|||
msg = u'Addresse %s for partner %s has %s that is invalid '%( |
|||
unicode(vals['firstname']) +' '+ unicode(vals['lastname']), |
|||
add.partner_id.name, |
|||
key |
|||
) |
|||
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg) |
|||
error_report.append(msg) |
|||
# Validating the CN |
|||
if not add.lastname and add.firstname: |
|||
msg = u'!!! Addresse %s for partner %s has no last name and first name that is valid partner name was used'%( |
|||
unicode(add.id), |
|||
add.partner_id.name, |
|||
) |
|||
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg) |
|||
error_report.append(msg) |
|||
# We save to LDAP |
|||
add.write(vals, {'init_mode':True}) |
|||
#we by pass the encoding errors |
|||
map(lambda x: unicodedata.normalize("NFKD",x).encode('ascii','ignore'), error_report) |
|||
error_report = "\n".join(error_report) |
|||
logger.notifyChannel("MY TOPIC", netsvc.LOG_ERROR, error_report) |
|||
try: |
|||
data= base64.encodestring(error_report.encode()) |
|||
except Exception, e: |
|||
data= base64.encodestring("Could not generate report file. Please look in the log for details") |
|||
|
|||
return {'errors': data} |
|||
|
|||
class Wiz_import_addresses(wizard.interface): |
|||
states = { |
|||
'init': { |
|||
'actions': [], |
|||
'result': { |
|||
'type': 'form', |
|||
'arch':_FORM, |
|||
'fields':{}, |
|||
'state':[ |
|||
('end','Cancel'), |
|||
('importadd','Export adresses into company LDAP') |
|||
] |
|||
} |
|||
}, |
|||
'importadd': { |
|||
'actions': [_action_import_adresses], |
|||
'result': { |
|||
'state':[('end', 'OK', 'gtk-ok', True)], |
|||
'arch' : _FORM1, |
|||
'fields' : _FIELDS, |
|||
'type':'form' |
|||
} |
|||
} |
|||
} |
|||
Wiz_import_addresses('ldap.import_adresses') |
Write
Preview
Loading…
Cancel
Save
Reference in new issue