Sanjay Gohel (Open ERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-import-outlook-pst-backlog-2-sgo into
lp:~openerp-dev/openobject-addons/trunk-import-outlook-pst.
Requested reviews:
Atul Patel(OpenERP) (atp-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import-outlook-pst-backlog-2-sgo/+merge/65165
hello,
I have make the correction
kindly check it
Thanks
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import-outlook-pst-backlog-2-sgo/+merge/65165
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-import-outlook-pst.
=== removed file 'import_outlook_pst/demo/contact.pst'
Binary files import_outlook_pst/demo/contact.pst 2011-05-23 08:54:23 +0000 and import_outlook_pst/demo/contact.pst 1970-01-01 00:00:00 +0000 differ
=== added file 'import_outlook_pst/demo/contacts.pst'
Binary files import_outlook_pst/demo/contacts.pst 1970-01-01 00:00:00 +0000 and import_outlook_pst/demo/contacts.pst 2011-06-20 09:02:39 +0000 differ
=== added file 'import_outlook_pst/demo/meeting.pst'
Binary files import_outlook_pst/demo/meeting.pst 1970-01-01 00:00:00 +0000 and import_outlook_pst/demo/meeting.pst 2011-06-20 09:02:39 +0000 differ
=== added file 'import_outlook_pst/extract.py'
--- import_outlook_pst/extract.py 1970-01-01 00:00:00 +0000
+++ import_outlook_pst/extract.py 2011-06-20 09:02:39 +0000
@@ -0,0 +1,129 @@
+from osv import fields, osv
+import base64
+import subprocess
+import mailbox
+import os, os.path,stat
+import vobject
+import tempfile
+import time
+import datetime
+from import_base.mapper import *
+from import_base.import_framework import *
+
+
+def read_pst(file):
+ parent_directory = tempfile.mkdtemp(prefix='outlook_', suffix='_pst')
+ outputdirectory = os.path.join(parent_directory, 'exctract_pst')
+ os.mkdir(outputdirectory)
+ pst_file = base64.decodestring(file)
+ att_folder_path = os.path.abspath(os.path.dirname("%temp%\\"))
+ att_path = os.path.join(att_folder_path,'exctract_file.pst')
+ file_pst = open(att_path, "w")
+ file_pst.write(pst_file)
+ file_pst.close()
+ try:
+ subprocess.call(['readpst', '-o', outputdirectory, '-r', att_path])
+ except:
+ raise osv.except_osv(_('readpst lib Error!'), _('Please install readpst lib for reading pst file using sudo apt-get install readpst.'))
+ name = False
+ directories = [outputdirectory]
+ for directory in directories:
+ for name in os.listdir(directory):
+ fullpath = os.path.join(directory,name)
+ if os.path.isfile(fullpath):
+ continue
+ elif os.path.isdir(fullpath):
+ directories.append(fullpath)
+ return name,fullpath
+
+
+def import_calendar_data(read_file):
+ list_dict = []
+ for reader in vobject.readComponents(read_file):
+ row = {}
+ for contents in reader.contents:
+ for address in reader.contents.get(contents):
+ if contents == 'dtend' or contents == 'dtstart' or contents == 'dtstamp' or contents == 'created':
+ cal_date = str(address.value)
+ change_date = datetime.datetime.strptime(cal_date, "%Y-%m-%d %H:%M:%S+00:00")
+ address.value = str(change_date)
+ if contents == 'last-mod':
+ continue
+ row[contents] = eval('reader.' + contents + '.value')
+ result = row.get('summary') + row.get('status')
+ row['id'] = result
+ list_dict.append(row)
+ return list_dict
+
+def get_address_type(row,address,list_dict, type, phone, fax):
+ row.update({'city': address.value.city,
+ 'street' : address.value.street,
+ 'country' : address.value.country,
+ 'zip' : address.value.code,
+ 'state' : address.value.region,
+ 'type' : type,
+ 'phone' : phone,
+ 'fax' : fax,
+ })
+ result = row.get('fn')+row.get('type')
+ row['id'] = result
+ list_dict.append(row)
+
+def import_contact_data(read_file):
+ list_dict = []
+ for reader in vobject.readComponents(read_file):
+ if reader.contents.has_key('fn'):
+ fn = eval('reader.' + unicode('fn') + '.value')
+ if reader.contents.has_key('email'):
+ email = eval('reader.' + unicode('email') + '.value')
+ if reader.contents.has_key('org'):
+ org = eval('reader.' + unicode('org') + '.value')
+ if reader.contents.has_key('title'):
+ title = eval('reader.' + unicode('title') + '.value')
+ if reader.contents.has_key('n'):
+ fname = eval('reader.' + unicode('n') + '.value')
+ prefix = fname.prefix
+ if reader.contents.has_key('tel'):
+ for adr in reader.contents.get('tel'):
+ if adr.params.get('TYPE')[0] == 'work' and adr.params.get('TYPE')[1] == 'voice':
+ work_voice = adr.value
+ if adr.params.get('TYPE')[0] == 'work' and adr.params.get('TYPE')[1] == 'fax':
+ work_fax = adr.value
+ if adr.params.get('TYPE')[0] == 'home' and adr.params.get('TYPE')[1] == 'voice':
+ home_voice = adr.value
+ if adr.params.get('TYPE')[0] == 'work' and adr.params.get('TYPE')[1] == 'fax':
+ home_fax = adr.value
+ if adr.params.get('TYPE')[0] == 'cell':
+ mobile = adr.value
+ if adr.params.get('TYPE')[0] == 'msg':
+ other_voice = adr.value
+ if adr.params.get('TYPE')[0] == 'fax':
+ other_fax = adr.value
+ if fn and reader.contents.has_key('adr'):
+ for address in reader.contents.get('adr'):
+ row = {
+ 'fn': fn,
+ 'prefix' : prefix,
+ 'email' : email,
+ 'function' : title,
+ 'org' : org,
+ 'mobile': mobile,
+ }
+ type = address.params.get('TYPE')[0]
+ if type == 'work':
+ get_address_type(row,address,list_dict, 'invoice',work_voice,work_fax)
+ if type == 'home':
+ get_address_type(row,address,list_dict, 'contact',home_voice,home_fax)
+ if type == 'postal':
+ get_address_type(row,address,list_dict, 'other',other_voice,other_fax)
+ return list_dict
+
+def get_pst(fullpath,name):
+ list_dict = []
+ fp = open(fullpath)
+ s = "".join(fp.readlines())
+ if name == 'calendar':
+ list_dict = import_calendar_data(s)
+ elif name == 'contacts':
+ list_dict = import_contact_data(s)
+ return list_dict
=== modified file 'import_outlook_pst/import_outlook_pst.py'
--- import_outlook_pst/import_outlook_pst.py 2011-05-23 08:54:23 +0000
+++ import_outlook_pst/import_outlook_pst.py 2011-06-20 09:02:39 +0000
@@ -19,11 +19,103 @@
#
##############################################################################
from osv import fields, osv
-import base64
-import subprocess
-import os, os.path
-import tempfile
-from tools.translate import _
+from import_base.mapper import *
+from import_base.import_framework import *
+import extract
+
+
+class outlook_import(import_framework):
+
+ FILE_CONTACT = 'contacts'
+ FILE_MEETING = 'calendar'
+
+ def initialize(self):
+ fullpth,directo = extract.read_pst(self.context.get('file'))
+ self.context['name'] = directo
+ self.context['fullpath'] = fullpth
+
+ def get_data(self,name):
+ """
+ @return: a list of dictionaries
+ each dictionnaries contains the list of pair external_field_name : value
+ """
+ directy = extract.get_pst(self.context.get('name'),self.context.get('fullpath'))
+ return directy
+
+
+ def get_meeting_mapping(self):
+ return {
+ 'model' : 'crm.meeting',
+ 'map' : {
+ 'name': 'summary',
+ 'date': 'dtstart',
+ 'date_deadline' : 'dtend',
+ 'location': 'location',
+ 'description' : 'description',
+ }
+ }
+ def import_contact(self, val):
+ if val.get('country'):
+ country_id = self.get_all_countries(val.get('country'))
+ states = self.get_all_states(val.get('state'), country_id)
+ val['country_id/id'] = country_id
+ val['state_id/id'] = states
+ return val
+
+ def get_company_id(self, dict, val):
+ if val:
+ fields = ['name']
+ data = val
+ return self.import_object(fields, data, 'res.company', 'cmpny', val and val[0] or False)
+
+ def get_title(self, dict, prefix):
+ fields = ['shortcut', 'name', 'domain']
+ if prefix:
+ data = [prefix, prefix, 'Contact']
+ return self.import_object(fields, data, 'res.partner.title', 'contact_title', prefix, [('shortcut', '=',prefix)])
+
+
+ def get_contact_mapping(self):
+ return {
+ 'model' : 'res.partner.address',
+ 'hook' : self.import_contact,
+ 'map' : {
+ 'name':'fn',
+ 'function': 'title',
+ 'street': 'street',
+ 'phone' : 'phone',
+ 'fax' : 'fax',
+ 'city': 'city',
+ 'zip' : 'zip',
+ 'mobile' : 'mobile',
+ 'email' : 'email',
+ 'state_id/id' : 'state_id/id',
+ 'company_id/id' : call(self.get_company_id, value('org')),
+ 'title/id' : call(self.get_title, value('prefix')),
+ 'country_id/id': 'country_id/id',
+ 'type':'type'
+ }
+ }
+
+ def get_mapping(self):
+
+ return {
+ 'contacts': self.get_contact_mapping(),
+ 'calendar' : self.get_meeting_mapping()
+ }
+
+ def get_all_states(self, external_val, country_id):
+ """Get states or create new state unless country_id is False"""
+ state_code = external_val[0:3] #take the tree first char
+ fields = ['country_id/id', 'name', 'code']
+ data = [country_id, external_val, state_code]
+ if country_id:
+ return self.import_object(fields, data, 'res.country.state', 'state_id', external_val)
+ return False
+
+ def get_all_countries(self, val):
+ """Get Country, if no country match do not create anything, to avoid duplicate country code"""
+ return self.mapped_id_if_exist('res.country', [('name', 'ilike', val)], 'country', val)
class import_outlook_pst(osv.osv):
"""Import Outlook Pst"""
@@ -33,25 +125,14 @@
'file': fields.binary('Upload pst File',filters='*.pst', required=True),
}
- def import_pst(self, cr, uid, ids, context=None):
- """Extract pst file"""
- if not context:
- context = {}
- for current in self.browse(cr, uid, ids):
- parent_directory = tempfile.mkdtemp(prefix='outlook_', suffix='_pst')
- outputdirectory = os.path.join(parent_directory, 'exctract_pst')
- os.mkdir(outputdirectory)
- pst_file = base64.decodestring(current.file)
- att_folder_path = os.path.abspath(os.path.dirname("%temp%\\"))
- att_path = os.path.join(att_folder_path,'exctract_file.pst')
- file_pst = open(att_path, "w")
- file_pst.write(pst_file)
- file_pst.close()
- try:
- subprocess.call(['readpst', '-o', outputdirectory, '-r', att_path])
- except:
- raise osv.except_osv(_('readpst lib Error!'), _('Please install readpst lib for reading pst file using sudo apt-get install readpst.'))
- directories = [outputdirectory]
- return {'type': 'ir.actions.act_window_close'}
+ def import_pst_contact(self, cr, uid, ids, context=None):
+ if not context:
+ context={}
+ for current in self.browse(cr, uid, ids):
+ context.update({'file': current.file})
+ imp = outlook_import(self, cr, uid, "outlook", "import_outlook_pst", context=context)
+ imp.set_table_list([imp.context.get('fullpath')])
+ imp.start()
+ return {}
import_outlook_pst()
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp