1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
7
# Author : Vincent Renaville
9
# WARNING: This program as such is intended to be used by professional
10
# programmers who take the whole responsability of assessing all potential
11
# consequences resulting from its eventual inadequacies and bugs
12
# End users who are looking for a ready-to-use solution with commercial
13
# garantees and support are strongly adviced to contract a Free Software
16
# This program is Free Software; you can redistribute it and/or
17
# modify it under the terms of the GNU General Public License
18
# as published by the Free Software Foundation; either version 2
19
# of the License, or (at your option) any later version.
21
# This program is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU General Public License for more details.
26
# You should have received a copy of the GNU General Public License
27
# along with this program; if not, write to the Free Software
28
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30
##############################################################################
34
# Created by Nicolas Bessi on 28.04.09.
35
# Copyright (c) 2009 CamptoCamp. All rights reserved.
44
_FORM = '''<?xml version="1.0"?>
45
<form string="Export adresses to ldap">
49
_FORM1 = """<?xml version="1.0"?>
50
<form string="Export log">
51
<separator colspan="4" string="Clic on 'Save as' to save the log file :" />
52
<field name="errors"/>
58
'string': 'Error report',
64
### As this is a bulck batch wizzard the performance process was not reallay taken in account ###
65
##The ideal way of doing would be to modify the connexion settings in order to have a connexion singelton
66
## in the file partner.py it will avoid connexion renegotiation for each partner.
67
def _action_import_adresses(self, cr, uid, data, context):
68
""" This function create or update each adresses present in the database.
69
It will also genreate an error report"""
70
logger = netsvc.Logger()
71
error_report = [u'Error report']
72
add_obj = pooler.get_pool(cr.dbname).get('res.partner.address')
73
add_ids = add_obj.search(cr,uid,[])
74
addresses = add_obj.browse(cr, uid, add_ids)
75
phone_fields = ['phone','fax','mobile','private_phone']
76
for add in addresses :
78
vals['partner_id'] = add.partner_id.id
79
vals['email'] = add.email
80
vals['phone'] = add.phone
82
vals['mobile'] = add.mobile
83
vals['firstname'] = add.firstname
84
vals['lastname'] = add.lastname
85
vals['private_phone'] = add.private_phone
86
vals['street'] = add.street
87
vals['street2'] = add.street2
88
vals['city'] = add.city
92
"^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", add.email) is None or\
93
re.search(u"[éèàêöüäï&]", add.email) is not None:
94
msg=u'Addresse %s for partner %s has email that is invalid %s'%(
95
unicode(vals['firstname']) +' '+ unicode(vals['lastname']),
99
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg)
100
error_report.append(msg)
101
vals['email'] = False
102
# Validating the Phone
103
for key in phone_fields :
104
if not unicode(vals[key]).startswith('+') or unicode(vals[key]).find("\n") != -1\
105
or re.search(u"[éèàêöüä#&]", unicode(vals[key])) is not None:
107
msg = u'Addresse %s for partner %s has %s that is invalid '%(
108
unicode(vals['firstname']) +' '+ unicode(vals['lastname']),
112
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg)
113
error_report.append(msg)
115
if not add.lastname and add.firstname:
116
msg = u'!!! Addresse %s for partner %s has no last name and first name that is valid partner name was used'%(
120
logger.notifyChannel('ldap export', netsvc.LOG_INFO, msg)
121
error_report.append(msg)
123
add.write(vals, {'init_mode':True})
124
#we by pass the encoding errors
125
map(lambda x: unicodedata.normalize("NFKD",x).encode('ascii','ignore'), error_report)
126
error_report = "\n".join(error_report)
127
logger.notifyChannel("MY TOPIC", netsvc.LOG_ERROR, error_report)
129
data= base64.encodestring(error_report.encode())
131
data= base64.encodestring("Could not generate report file. Please look in the log for details")
133
return {'errors': data}
135
class Wiz_import_addresses(wizard.interface):
145
('importadd','Export adresses into company LDAP')
150
'actions': [_action_import_adresses],
152
'state':[('end', 'OK', 'gtk-ok', True)],
159
Wiz_import_addresses('ldap.import_adresses')