[Merge] lp:~openerp-dev/openobject-addons/trunk-import_google-backlog2_import_meeting-jam
bzr revid: sbh@tinyerp.com-20110608111110-69kazvbrpstov1bj
This commit is contained in:
@@ -1359,24 +1359,13 @@ rule or repeating pattern of time to exclude from the recurring rule."),
|
||||
return res and res[0] or False
|
||||
|
||||
return res
|
||||
def web_client_unfucking_timebomb(self, ids):
|
||||
if (date.today() < date(2011, 5, 1)):
|
||||
import re
|
||||
if isinstance(ids, list) and len(ids) == 1:
|
||||
string = ids[0]
|
||||
if isinstance(string, str) and string.startswith('[') and string.endswith(']'):
|
||||
string = string[1:-1]
|
||||
list_ids = re.split(',\s*', string)
|
||||
ids = list_ids
|
||||
return ids
|
||||
|
||||
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
if 'date' in groupby:
|
||||
raise osv.except_osv(_('Warning !'), _('Group by date not supported, use the calendar view instead'))
|
||||
|
||||
virtual_id = context.get('virtual_id', False)
|
||||
|
||||
context.update({'virtual_id': False})
|
||||
res = super(calendar_event, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)
|
||||
|
||||
@@ -37,7 +37,7 @@ class crm_installer(osv.osv_memory):
|
||||
'thunderbird': fields.boolean('Thunderbird', help="Allows you to link your e-mail to OpenERP's documents. You can attach it to any existing one in OpenERP or create a new one."),
|
||||
'outlook': fields.boolean('MS-Outlook', help="Allows you to link your e-mail to OpenERP's documents. You can attach it to any existing one in OpenERP or create a new one."),
|
||||
'wiki_sale_faq': fields.boolean('Sale FAQ', help="Helps you manage wiki pages for Frequently Asked Questions on Sales Application."),
|
||||
'import_google_contact': fields.boolean('Google Contacts', help="Imports contacts from your google account."),
|
||||
'import_google': fields.boolean('Google Contacts', help="Imports contacts from your google account."),
|
||||
}
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<separator string="Synchronization" colspan="4" />
|
||||
<field name="crm_caldav" />
|
||||
<field name="fetchmail" />
|
||||
<field name="import_google_contact"/>
|
||||
<field name="import_google"/>
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Plug-In" colspan="4" />
|
||||
|
||||
@@ -24,7 +24,7 @@ from tools.translate import _
|
||||
try:
|
||||
import gdata.contacts.service
|
||||
import gdata.contacts.client
|
||||
|
||||
import gdata.calendar.service
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
|
||||
@@ -81,4 +81,4 @@ class google_login(osv.osv_memory):
|
||||
|
||||
google_login()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -214,7 +214,6 @@ class import_framework(Thread):
|
||||
fields.append(key)
|
||||
value = val(dict(dict_sugar))
|
||||
data_lst.append(value)
|
||||
|
||||
return fields, data_lst
|
||||
|
||||
def _generate_xml_id(self, name, table):
|
||||
@@ -297,7 +296,6 @@ class import_framework(Thread):
|
||||
domain_search = not domain_search and [('name', 'ilike', name)] or domain_search
|
||||
obj = self.obj.pool.get(model)
|
||||
xml_id = self._generate_xml_id(name, table)
|
||||
|
||||
xml_ref = self.mapped_id_if_exist(model, domain_search, table, name)
|
||||
fields.append('id')
|
||||
data.append(xml_id)
|
||||
@@ -342,13 +340,17 @@ class import_framework(Thread):
|
||||
|
||||
|
||||
"""
|
||||
|
||||
self.data_started = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self.cr = pooler.get_db(self.cr.dbname).cursor()
|
||||
try:
|
||||
result = []
|
||||
imported = set() #to invoid importing 2 times the sames modules
|
||||
for table in self.table_list:
|
||||
# try:
|
||||
# to_import = self.get_mapping()[table].get('import', True)
|
||||
# except:
|
||||
# import traceback,sys
|
||||
# info = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
||||
to_import = self.get_mapping()[table].get('import', True)
|
||||
if not table in imported:
|
||||
res = self._resolve_dependencies(self.get_mapping()[table].get('dependencies', []), imported)
|
||||
@@ -431,4 +433,4 @@ class import_framework(Thread):
|
||||
"""
|
||||
return "The import of data \n instance name : %s \n" % self.instance_name
|
||||
|
||||
#For example of use see import_sugarcrm
|
||||
#For example of use see import_sugarcrm
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,11 +15,11 @@
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import import_google_contact
|
||||
import sync_google_calendar
|
||||
import wizard
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
'name': 'Google Contact Import',
|
||||
'version': '1.0',
|
||||
@@ -27,15 +26,17 @@
|
||||
'description': """The module adds google contact in partner address""",
|
||||
'author': 'OpenERP SA',
|
||||
'website': 'http://www.openerp.com',
|
||||
'depends': ['base','google_base_account'],
|
||||
'depends': ['base', 'google_base_account','crm'],
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'wizard/google_contact_import_view.xml'
|
||||
],
|
||||
'sync_google_calendar_view.xml',
|
||||
'wizard/google_contact_import_view.xml',
|
||||
],
|
||||
'demo_xml': [],
|
||||
'test': [
|
||||
'test/test_sync_google_contact_import_partner.yml',
|
||||
'test/test_sync_google_contact_import_address.yml',
|
||||
# 'test/test_sync_google_contact_import_partner.yml',
|
||||
# 'test/test_sync_google_contact_import_address.yml',
|
||||
'test/test_sync_google_calendar.yml',
|
||||
],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
+16
-5
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,12 +15,23 @@
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import sync_google_calendar
|
||||
import wizard
|
||||
from osv import osv, fields
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
class crm_meeting(osv.osv):
|
||||
_inherit = "crm.meeting"
|
||||
|
||||
crm_meeting()
|
||||
|
||||
class crm_case_categ(osv.osv):
|
||||
""" Category of Case """
|
||||
_inherit = "crm.case.categ"
|
||||
_columns = {
|
||||
'user_id': fields.many2one('res.users', 'User')
|
||||
}
|
||||
crm_case_categ()
|
||||
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
I create a record for the gmail account for which I want to import the contacts.
|
||||
-
|
||||
!record {model: google.login, id: google_login_contact_id0}:
|
||||
user: testmail.openerp
|
||||
user: testmail.openerp@gmail.com
|
||||
password: openerptiny
|
||||
- |
|
||||
I login into that account.
|
||||
@@ -33,4 +33,4 @@
|
||||
model_ids = model_obj.search(cr, uid, [('res_id','in',meeting_ids),('model','=','crm.meeting'),('module','=','sync_google_calendar')])
|
||||
assert model_ids, 'Meetings not created !'
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -18,7 +18,6 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import import_google
|
||||
import google_contact_import
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,363 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import datetime
|
||||
|
||||
try:
|
||||
import gdata
|
||||
import gdata.contacts.service
|
||||
import gdata.contacts
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
from osv import fields
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
from import_google import import_contact
|
||||
|
||||
class google_login_contact(osv.osv_memory):
|
||||
_inherit = 'google.login'
|
||||
_name = 'google.login.contact'
|
||||
|
||||
def _get_next_action(self, cr, uid, context):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_contact_import_form')
|
||||
|
||||
view_id = False
|
||||
if data_id:
|
||||
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
|
||||
value = {
|
||||
'name': _('Import Contact'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'synchronize.google.contact.import',
|
||||
'view_id': False,
|
||||
'context': context,
|
||||
'views': [(view_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
return value
|
||||
google_login_contact()
|
||||
|
||||
class synchronize_google_contact(osv.osv_memory):
|
||||
_name = 'synchronize.google.contact.import'
|
||||
|
||||
def _get_group(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google=self.pool.get('google.login')
|
||||
if not user_obj.gmail_user or not user_obj.gmail_password:
|
||||
raise osv.except_osv(_('Warning !'), _("No Google Username or password Defined for user.\nPlease define in user view"))
|
||||
gd_client = google.google_login(user_obj.gmail_user,user_obj.gmail_password,type='group')
|
||||
if not gd_client:
|
||||
raise osv.except_osv(_('Error'), _("Authentication fail check the user and password !"))
|
||||
|
||||
res = []
|
||||
query = gdata.contacts.service.GroupsQuery(feed='/m8/feeds/groups/default/full')
|
||||
if gd_client:
|
||||
groups = gd_client.GetFeed(query.ToUri())
|
||||
for grp in groups.entry:
|
||||
res.append((grp.id.text, grp.title.text))
|
||||
res.append(('all','All Groups'))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'create_partner': fields.selection([('create_all','Create partner for each contact'),('create_address','Import only address')],'Options'),
|
||||
'customer': fields.boolean('Customer', help="Check this box to set newly created partner as Customer."),
|
||||
'supplier': fields.boolean('Supplier', help="Check this box to set newly created partner as Supplier."),
|
||||
'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By default it takes all."),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'create_partner': 'create_all',
|
||||
'group_name': 'all',
|
||||
}
|
||||
#
|
||||
# def create_partner(self, cr, uid, data={}, context=None):
|
||||
# if context == None:
|
||||
# context = {}
|
||||
# if not data:
|
||||
# return False
|
||||
# name = data.get("company") or data.get('name','')
|
||||
# partner_pool = self.pool.get('res.partner')
|
||||
# partner_id = partner_pool.create(cr, uid, {
|
||||
# 'name': name,
|
||||
# 'user_id': uid,
|
||||
# 'address' : [(6, 0, [data['address_id']])],
|
||||
# 'customer': data.get('customer', False),
|
||||
# 'supplier': data.get('supplier', False)
|
||||
# }, context=context)
|
||||
# return partner_id
|
||||
#
|
||||
# def set_partner(self, cr, uid, name, address_id, context=None):
|
||||
# partner_pool = self.pool.get('res.partner')
|
||||
# partner_ids = partner_pool.search(cr, uid, [('name', '=', name)], context=context)
|
||||
# if partner_ids:
|
||||
# address_pool = self.pool.get('res.partner.address')#TODO create partner of find the one with the same name
|
||||
# data = {'partner_id' : partner_ids[0]}
|
||||
# address_pool.write(cr, uid, [address_id], data, context=context)
|
||||
# return partner_ids[0]
|
||||
# return False
|
||||
|
||||
def import_contact_all(self, cr, uid, ids, context=None):
|
||||
tables = ['contact']
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google = self.pool.get('google.login')
|
||||
|
||||
gmail_user = user_obj.gmail_user
|
||||
gmail_pwd = user_obj.gmail_password
|
||||
context = {}
|
||||
gd_client = google.google_login(gmail_user, gmail_pwd, type='contact')
|
||||
context.update({'user': gmail_user,'password': gmail_pwd,'gd_client':gd_client})
|
||||
|
||||
imp = import_contact(self, cr, uid,'google', "synchronize_google_contact", context=context)
|
||||
imp.set_table_list(tables)
|
||||
imp.start()
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
#
|
||||
# if not gd_client:
|
||||
# raise osv.except_osv(_('Error'), _("Please specify correct user and password !"))
|
||||
#
|
||||
# if obj.group_name not in ['all']:
|
||||
# query = gdata.contacts.service.ContactsQuery()
|
||||
# query.group = obj.group_name
|
||||
# contact = gd_client.GetContactsFeed(query.ToUri())
|
||||
# else:
|
||||
# contact = gd_client.GetContactsFeed()
|
||||
#
|
||||
# ids = self.create_contact(cr, uid, ids, gd_client, contact, option=obj.create_partner,context=context)
|
||||
# if not ids:
|
||||
# return {'type': 'ir.actions.act_window_close'}
|
||||
#
|
||||
# return {
|
||||
# 'name': _(obj.create_partner =='create_all' and 'Partners') or _('Contacts'),
|
||||
# 'domain': "[('id','in', ["+','.join(map(str,ids))+"])]",
|
||||
# 'view_type': 'form',
|
||||
# 'view_mode': 'tree,form',
|
||||
# 'res_model': obj.create_partner =='create_all' and 'res.partner' or 'res.partner.address',
|
||||
# 'context': context,
|
||||
# 'views': [(False, 'tree'),(False, 'form')],
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# }
|
||||
|
||||
|
||||
# def create_contact(self, cr, uid, ids, gd_client, contact, option,context=None):
|
||||
# model_obj = self.pool.get('ir.model.data')
|
||||
# addresss_obj = self.pool.get('res.partner.address')
|
||||
# company_pool = self.pool.get('res.company')
|
||||
# addresses = []
|
||||
# partner_ids = []
|
||||
# contact_ids = []
|
||||
# if 'tz' in context and context['tz']:
|
||||
# time_zone = context['tz']
|
||||
# else:
|
||||
# time_zone = tools.get_server_timezone()
|
||||
# au_tz = timezone(time_zone)
|
||||
# while contact:
|
||||
# for entry in contact.entry:
|
||||
# data = self._retreive_data(entry)
|
||||
# google_id = data.pop('id')
|
||||
# model_data = {
|
||||
# 'name': google_id,
|
||||
# 'model': 'res.partner.address',
|
||||
# 'module': 'sync_google_contact',
|
||||
# 'noupdate': True
|
||||
# }
|
||||
#
|
||||
# data_ids = model_obj.search(cr, uid, [('model','=','res.partner.address'), ('name','=', google_id)])
|
||||
# if data_ids:
|
||||
# contact_ids = [model_obj.browse(cr, uid, data_ids[0], context=context).res_id]
|
||||
# elif data['email']:
|
||||
# contact_ids = addresss_obj.search(cr, uid, [('email', 'ilike', data['email'])])
|
||||
#
|
||||
# if contact_ids:
|
||||
# addresses.append(contact_ids[0])
|
||||
# address = addresss_obj.browse(cr, uid, contact_ids[0], context=context)
|
||||
# google_updated = entry.updated.text
|
||||
# utime = dateutil.parser.parse(google_updated)
|
||||
# au_dt = au_tz.normalize(utime.astimezone(au_tz))
|
||||
# updated_dt = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
# if address.write_date < updated_dt:
|
||||
# self.update_contact(cr, uid, contact_ids, data, context=context)
|
||||
# res_id = contact_ids[0]
|
||||
# if not contact_ids:
|
||||
# #create or link to an existing partner only if it's a new contact
|
||||
# data.update({'type': 'default'})
|
||||
# res_id = addresss_obj.create(cr, uid, data, context=context)
|
||||
# data['address_id'] = res_id
|
||||
# if option == 'create_all':
|
||||
# obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
# data['customer'] = obj.customer
|
||||
# data['supplier'] = obj.supplier
|
||||
# res = False
|
||||
# if 'company' in data:
|
||||
# res = self.set_partner(cr, uid, data.get('company'), res_id, context=context)
|
||||
# if res:
|
||||
# partner_ids.append(res)
|
||||
# if not res:
|
||||
# partner_id = self.create_partner(cr, uid, data, context=context)
|
||||
# partner_ids.append(partner_id)
|
||||
# addresses.append(res_id)
|
||||
#
|
||||
# if not data_ids: #link to google_id if it was not the case before
|
||||
# model_data.update({'res_id': res_id})
|
||||
# model_obj.create(cr, uid, model_data, context=context)
|
||||
#
|
||||
# next = contact.GetNextLink()
|
||||
# contact = next and gd_client.GetContactsFeed(next.href) or None
|
||||
#
|
||||
# if option == 'create_all':
|
||||
# return partner_ids
|
||||
# else:
|
||||
# return addresses
|
||||
|
||||
# def _retreive_data(self, entry):
|
||||
# data = {}
|
||||
# data['id'] = entry.id.text
|
||||
# name = tools.ustr(entry.title.text)
|
||||
# if name == "None":
|
||||
# name = entry.email[0].address
|
||||
# data['name'] = name
|
||||
# emails = ','.join(email.address for email in entry.email)
|
||||
# data['email'] = emails
|
||||
# if entry.organization:
|
||||
# if entry.organization.org_name:
|
||||
# data.update({'company': entry.organization.org_name.text})
|
||||
# if entry.organization.org_title:
|
||||
# data.update ({'function': entry.organization.org_title.text})
|
||||
#
|
||||
#
|
||||
# if entry.phone_number:
|
||||
# for phone in entry.phone_number:
|
||||
# if phone.rel == gdata.contacts.REL_WORK:
|
||||
# data['phone'] = phone.text
|
||||
# if phone.rel == gdata.contacts.PHONE_MOBILE:
|
||||
# data['mobile'] = phone.text
|
||||
# if phone.rel == gdata.contacts.PHONE_WORK_FAX:
|
||||
# data['fax'] = phone.text
|
||||
# return data
|
||||
|
||||
# def update_contact(self, cr, uid, contact_ids, data, context=None):
|
||||
# addresss_obj = self.pool.get('res.partner.address')
|
||||
# vals = {}
|
||||
# addr = addresss_obj.browse(cr,uid,contact_ids)[0]
|
||||
# name = str((addr.name or addr.partner_id and addr.partner_id.name or '').encode('utf-8'))
|
||||
#
|
||||
# if name != data.get('name'):
|
||||
# vals['name'] = data.get('name','')
|
||||
# if addr.email != data.get('email'):
|
||||
# vals['email'] = data.get('email','')
|
||||
# if addr.mobile != data.get('mobile'):
|
||||
# vals['mobile'] = data.get('mobile','')
|
||||
# if addr.phone != data.get('phone'):
|
||||
# vals['phone'] = data.get('phone','')
|
||||
# if addr.fax != data.get('fax'):
|
||||
# vals['fax'] = data.get('fax','')
|
||||
#
|
||||
# addresss_obj.write(cr, uid, contact_ids, vals, context=context)
|
||||
# return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
synchronize_google_contact()
|
||||
|
||||
|
||||
class google_login_calendar(osv.osv_memory):
|
||||
"""Gdata Login Object for Google Calendar Import"""
|
||||
_inherit = 'google.login'
|
||||
_name = 'google.login'
|
||||
|
||||
def _get_next_action(self, cr, uid, context):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_calendar_import_form')
|
||||
|
||||
view_id = False
|
||||
if data_id:
|
||||
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
|
||||
value = {
|
||||
'name': _('Import Events'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'synchronize.google.calendar',
|
||||
'view_id': False,
|
||||
'context': context,
|
||||
'views': [(view_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
return value
|
||||
google_login_calendar()
|
||||
|
||||
|
||||
class synchronize_google_calendar_events(osv.osv_memory):
|
||||
"""
|
||||
Wizard to initiate import specific calendar or all calendars
|
||||
"""
|
||||
_name = 'synchronize.google.calendar'
|
||||
|
||||
def _get_calendars(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google = self.pool.get('google.login')
|
||||
res = []
|
||||
try:
|
||||
gd_client = google.google_login(user_obj.gmail_user, user_obj.gmail_password, type='calendar')
|
||||
calendars = gd_client.GetAllCalendarsFeed()
|
||||
for cal in calendars.entry:
|
||||
res.append((cal.id.text, cal.title.text))
|
||||
except Exception, e:
|
||||
raise osv.except_osv('Error !', e.args[0].get('body'))
|
||||
res.append(('all', 'All Calendars'))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'calendar_name': fields.selection(_get_calendars, "Calendar Name", size=32),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'calendar_name': 'all',
|
||||
}
|
||||
|
||||
def import_calendar_events(self, cr, uid, ids, context=None):
|
||||
if context == None:
|
||||
context = {}
|
||||
if not ids:
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
table = ['Events']
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
gmail_user = user_obj.gmail_user
|
||||
gmail_pwd = user_obj.gmail_password
|
||||
if not gmail_user or not gmail_pwd:
|
||||
raise osv.except_osv(_('Error'), _("Invalid login detail !\n Specify Username/Password."))
|
||||
current_rec = self.browse(cr, uid, ids, context=context)
|
||||
calendars = False
|
||||
for rec in current_rec:
|
||||
if rec.calendar_name != 'all':
|
||||
calendars = [rec.calendar_name]
|
||||
else:
|
||||
calendars = map(lambda x: x[0], [cal for cal in self._get_calendars(cr, uid, context) if cal[0] != 'all'])
|
||||
context.update({'user': gmail_user,
|
||||
'password': gmail_pwd,
|
||||
'calendars': calendars,
|
||||
'instance': 'calendar'})
|
||||
imp = import_contact(self, cr, uid, 'import_google', "import_google_calendar", [gmail_user], context)
|
||||
imp.set_table_list(table)
|
||||
imp.start()
|
||||
return {}
|
||||
|
||||
synchronize_google_calendar_events()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
+42
-1
@@ -30,8 +30,43 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="view_synchronize_google_calendar_import_form">
|
||||
<field name="name">synchronize.google.calendar.form</field>
|
||||
<field name="model">synchronize.google.calendar</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Google Calendar Events">
|
||||
<group colspan="4" col="4" width="320">
|
||||
<field name="calendar_name" />
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<group colspan="2" col="2"/>
|
||||
<group colspan="2" col="2">
|
||||
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
|
||||
<button name="import_calendar_events" string="_Import Events" type="object" icon="terp-calendar"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<!--
|
||||
Login Action
|
||||
-->
|
||||
<record model="ir.actions.act_window" id="act_google_login_form">
|
||||
<field name="name">Import Google Calendar</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">google.login</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="google_base_account.view_google_login_form" />
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="act_google_login_contact_form">
|
||||
<field name="name">Import Contacts</field>
|
||||
<field name="name">Import Google Contacts</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">google.login.contact</field>
|
||||
<field name="view_type">form</field>
|
||||
@@ -44,5 +79,11 @@
|
||||
parent="base.menu_address_book"
|
||||
action="act_google_login_contact_form"
|
||||
sequence="40" />
|
||||
|
||||
<menuitem id="menu_sync_calendar"
|
||||
parent="crm.menu_meeting_sale"
|
||||
action="act_google_login_form"
|
||||
sequence="20" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -0,0 +1,259 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import re
|
||||
import urllib
|
||||
import dateutil
|
||||
from dateutil import *
|
||||
from pytz import timezone
|
||||
from datetime import datetime
|
||||
import time
|
||||
try:
|
||||
import gdata
|
||||
import gdata.contacts.service
|
||||
import gdata.calendar.service
|
||||
import gdata.contacts
|
||||
import gdata.calendar
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
from import_base.import_framework import *
|
||||
from import_base.mapper import *
|
||||
|
||||
class import_contact(import_framework):
|
||||
|
||||
gd_client = False
|
||||
calendars = False
|
||||
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
TABLE_CONTACT = 'contact'
|
||||
TABLE_EVENT = 'Events'
|
||||
|
||||
def initialize(self):
|
||||
google = self.obj.pool.get('google.login')
|
||||
self.gd_client = google.google_login(self.context.get('user'),
|
||||
self.context.get('password'),
|
||||
type = self.context.get('instance'))
|
||||
if self.context.get('instance') and self.context.get('instance') == 'calendar':
|
||||
self.calendars = self.context.get('calendars')
|
||||
|
||||
def get_mapping(self):
|
||||
return {
|
||||
self.TABLE_EVENT: self.get_event_mapping(),
|
||||
}
|
||||
|
||||
def get_data(self, table):
|
||||
val = {
|
||||
self.TABLE_EVENT: self.get_events(),
|
||||
}
|
||||
return val.get(table)
|
||||
|
||||
|
||||
def _get_tinydates(self, stime, etime):
|
||||
stime = dateutil.parser.parse(stime)
|
||||
etime = dateutil.parser.parse(etime)
|
||||
try:
|
||||
au_dt = au_tz.normalize(stime.astimezone(au_tz))
|
||||
timestring = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
au_dt = au_tz.normalize(etime.astimezone(au_tz))
|
||||
timestring_end = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
except:
|
||||
timestring = datetime.datetime(*stime.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
timestring_end = datetime.datetime(*etime.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
return (timestring, timestring_end)
|
||||
|
||||
def _get_rules(self, datas):
|
||||
new_val = {}
|
||||
if datas['FREQ'] == 'WEEKLY' and datas.get('BYDAY'):
|
||||
for day in datas['BYDAY'].split(','):
|
||||
new_val[day.lower()] = True
|
||||
datas.pop('BYDAY')
|
||||
|
||||
if datas.get('UNTIL'):
|
||||
until = parser.parse(''.join((re.compile('\d')).findall(datas.get('UNTIL'))))
|
||||
new_val['end_date'] = until.strftime('%Y-%m-%d')
|
||||
new_val['end_type'] = 'end_date'
|
||||
datas.pop('UNTIL')
|
||||
|
||||
if datas.get('COUNT'):
|
||||
new_val['count'] = datas.get('COUNT')
|
||||
new_val['end_type'] = 'count'
|
||||
datas.pop('COUNT')
|
||||
|
||||
if datas.get('INTERVAL'):
|
||||
new_val['interval'] = datas.get('INTERVAL')
|
||||
else:
|
||||
new_val['interval'] = 1
|
||||
|
||||
if datas.get('BYMONTHDAY'):
|
||||
new_val['day'] = datas.get('BYMONTHDAY')
|
||||
datas.pop('BYMONTHDAY')
|
||||
new_val['select1'] = 'date'
|
||||
|
||||
if datas.get('BYDAY'):
|
||||
d = datas.get('BYDAY')
|
||||
if '-' in d:
|
||||
new_val['byday'] = d[:2]
|
||||
new_val['week_list'] = d[2:4].upper()
|
||||
else:
|
||||
new_val['byday'] = d[:1]
|
||||
new_val['week_list'] = d[1:3].upper()
|
||||
new_val['select1'] = 'day'
|
||||
|
||||
if datas.get('BYMONTH'):
|
||||
new_val['month_list'] = datas.get('BYMONTH')
|
||||
datas.pop('bymonth')
|
||||
return new_val
|
||||
|
||||
|
||||
def _get_repeat_status(self, str_google):
|
||||
rrule = str_google[str_google.find('FREQ'):str_google.find('\nBEGIN')]
|
||||
status = {}
|
||||
for rule in rrule.split(';'):
|
||||
status[rule.split('=')[0]] = rule.split('=')[-1:] and rule.split('=')[-1:][0] or ''
|
||||
rules = self._get_rules(status)
|
||||
if status.get('FREQ') == 'WEEKLY':
|
||||
status.update({'rrule_type': 'weekly'})
|
||||
status.pop('FREQ')
|
||||
elif status.get('FREQ') == 'DAILY':
|
||||
status.update({'rrule_type': 'daily'})
|
||||
status.pop('FREQ')
|
||||
elif status.get('FREQ') == 'MONTHLY':
|
||||
status.update({'rrule_type': 'monthly'})
|
||||
status.pop('FREQ')
|
||||
elif status.get('FREQ') == 'YEARLY':
|
||||
status.update({'rrule_type': 'yearly'})
|
||||
status.pop('FREQ')
|
||||
status.update(rules)
|
||||
return status
|
||||
|
||||
|
||||
def _get_repeat_dates(self, x):
|
||||
if len(x) > 4:
|
||||
if x[3].startswith('BY'):
|
||||
zone_time = x[4].split('+')[-1:][0].split(':')[0][:4]
|
||||
else:
|
||||
zone_time = x[3].split('+')[-1:][0].split(':')[0][:4]
|
||||
else:
|
||||
zone_time = x[2].split('+')[-1:][0].split(':')[0][:4]
|
||||
tz_format = zone_time[:2]+':'+zone_time[2:]
|
||||
repeat_start = x[1].split('\n')[0].split(':')[1]
|
||||
repeat_end = x[2].split('\n')[0].split(':')[1]
|
||||
o = repeat_start.split('T')
|
||||
repeat_start = str(o[0][:4]) + '-' + str(o[0][4:6]) + '-' + str(o[0][6:8])
|
||||
if len(o) == 2:
|
||||
repeat_start += ' ' + str(o[1][:2]) + ':' + str(o[1][2:4]) + ':' + str(o[1][4:6])
|
||||
else:
|
||||
repeat_start += ' ' + '00' + ':' + '00' + ':' + '00'
|
||||
p = repeat_end.split('T')
|
||||
repeat_end = str(p[0][:4]) + '-' + str(p[0][4:6]) + '-' + str(p[0][6:8])
|
||||
if len(p) == 2:
|
||||
repeat_end += ' ' + str(p[1][:2]) + ':' + str(p[1][2:4]) + ':' + str(p[1][4:6])
|
||||
else:
|
||||
repeat_end += ' ' + '00' + ':' + '00' + ':' + '00'
|
||||
return (repeat_start, repeat_end, tz_format)
|
||||
|
||||
def get_events(self):
|
||||
if 'tz' in self.context and self.context['tz']:
|
||||
time_zone = self.context['tz']
|
||||
else:
|
||||
time_zone = tools.get_server_timezone()
|
||||
au_tz = timezone(time_zone)
|
||||
event_vals = []
|
||||
for cal in self.calendars:
|
||||
events_query = gdata.calendar.service.CalendarEventQuery(user=urllib.unquote(cal.split('/')[~0]))
|
||||
events_query.start_index = 1
|
||||
events_query.max_results = 1000
|
||||
event_feed = self.gd_client.GetCalendarEventFeed(events_query.ToUri())
|
||||
for feed in event_feed.entry:
|
||||
event = {
|
||||
'recurrency': "0",
|
||||
'end_date' : False,
|
||||
'end_type' : False,
|
||||
'byday': 0,
|
||||
'count' : 0,
|
||||
'interval': 1,
|
||||
'day': False,
|
||||
'select1': False,
|
||||
'week_list': "",
|
||||
'month_list': False,
|
||||
'rrule_type': False,
|
||||
}
|
||||
|
||||
timestring = timestring_end = datetime.datetime.now().strftime(self.DATETIME_FORMAT)
|
||||
if feed.when:
|
||||
timestring, timestring_end = self._get_tinydates(feed.when[0].start_time, feed.when[0].end_time)
|
||||
else:
|
||||
x = feed.recurrence.text.split(';')
|
||||
repeat_status = self._get_repeat_status(feed.recurrence.text)
|
||||
repeat_start, repeat_end, zone_time = self._get_repeat_dates(x)
|
||||
timestring = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(repeat_start, "%Y-%m-%d %H:%M:%S"))
|
||||
timestring_end = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(repeat_end, "%Y-%m-%d %H:%M:%S"))
|
||||
if repeat_status:
|
||||
repeat_status.update({'recurrency': True})
|
||||
event.update(repeat_status)
|
||||
|
||||
event.update({'id' : feed.id.text,
|
||||
'DateStart': timestring,
|
||||
'DateEnd': timestring_end,
|
||||
'Category':event_feed.title.text,
|
||||
'Name': feed.title.text or 'No title',
|
||||
'Description': feed.content.text,
|
||||
})
|
||||
event_vals.append(event)
|
||||
return event_vals
|
||||
|
||||
|
||||
def get_event_category(self, val, name):
|
||||
fields = ['name', 'object_id']
|
||||
nameid = 'event_category_'+name
|
||||
data = [name, 'crm.meeting']
|
||||
return self.import_object(fields, data, 'crm.case.categ', "crm_case_categ", nameid, [('name', 'ilike', name)])
|
||||
|
||||
def get_event(self, val):
|
||||
if val.get("recurrency"):
|
||||
val.update({"recurrency": "1"})
|
||||
return val
|
||||
|
||||
def get_event_mapping(self):
|
||||
return {
|
||||
'model': 'crm.meeting',
|
||||
'hook': self.get_event,
|
||||
'map': {
|
||||
'id': 'id',
|
||||
'name': 'Name',
|
||||
'description': 'Description',
|
||||
'email_from': 'Email',
|
||||
'date': 'DateStart',
|
||||
'date_deadline': 'DateEnd',
|
||||
'categ_id/id': call(self.get_event_category, value('Category')),
|
||||
'recurrency': 'recurrency',
|
||||
'end_date' : 'end_date',
|
||||
'end_type' : 'end_type',
|
||||
'byday':'byday',
|
||||
'count' : 'count',
|
||||
'interval': 'interval',
|
||||
'day': 'day',
|
||||
'select1': 'date',
|
||||
'week_list': 'week_list',
|
||||
'month_list':'month_list',
|
||||
'rrule_type': 'rrule_type',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,274 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import datetime
|
||||
import dateutil
|
||||
from dateutil.parser import *
|
||||
from pytz import timezone
|
||||
|
||||
try:
|
||||
import gdata
|
||||
import gdata.contacts.service
|
||||
import gdata.contacts
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
|
||||
from osv import fields,osv
|
||||
from tools.translate import _
|
||||
import tools
|
||||
|
||||
class google_login_contact(osv.osv_memory):
|
||||
_inherit = 'google.login'
|
||||
_name = 'google.login.contact'
|
||||
def _get_next_action(self, cr, uid, context=None):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google_contact', 'view_synchronize_google_contact_import_form')
|
||||
view_id = False
|
||||
if data_id:
|
||||
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
|
||||
value = {
|
||||
'name': _('Import Contact'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'synchronize.google.contact.import',
|
||||
'view_id': False,
|
||||
'context': context,
|
||||
'views': [(view_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
return value
|
||||
google_login_contact()
|
||||
|
||||
class synchronize_google_contact(osv.osv_memory):
|
||||
_name = 'synchronize.google.contact.import'
|
||||
|
||||
def _get_group(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google=self.pool.get('google.login')
|
||||
if not user_obj.gmail_user or not user_obj.gmail_password:
|
||||
raise osv.except_osv(_('Warning !'), _("No Google Username or password Defined for user.\nPlease define in user view"))
|
||||
gd_client = google.google_login(user_obj.gmail_user,user_obj.gmail_password,type='group')
|
||||
if not gd_client:
|
||||
raise osv.except_osv(_('Error'), _("Authentication fail check the user and password !"))
|
||||
|
||||
res = []
|
||||
query = gdata.contacts.service.GroupsQuery(feed='/m8/feeds/groups/default/full')
|
||||
if gd_client:
|
||||
groups = gd_client.GetFeed(query.ToUri())
|
||||
for grp in groups.entry:
|
||||
res.append((grp.id.text, grp.title.text))
|
||||
res.append(('all','All Groups'))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'create_partner': fields.selection([('create_all','Create partner for each contact'),('create_address','Import only address')],'Options'),
|
||||
'customer': fields.boolean('Customer', help="Check this box to set newly created partner as Customer."),
|
||||
'supplier': fields.boolean('Supplier', help="Check this box to set newly created partner as Supplier."),
|
||||
'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By default it takes all."),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'create_partner': 'create_all',
|
||||
'group_name': 'all',
|
||||
}
|
||||
|
||||
def create_partner(self, cr, uid, data={}, context=None):
|
||||
if context == None:
|
||||
context = {}
|
||||
if not data:
|
||||
return False
|
||||
name = data.get("company") or data.get('name','')
|
||||
partner_pool = self.pool.get('res.partner')
|
||||
partner_id = partner_pool.create(cr, uid, {
|
||||
'name': name,
|
||||
'user_id': uid,
|
||||
'address' : [(6, 0, [data['address_id']])],
|
||||
'customer': data.get('customer', False),
|
||||
'supplier': data.get('supplier', False)
|
||||
}, context=context)
|
||||
return partner_id
|
||||
|
||||
def set_partner(self, cr, uid, name, address_id, context=None):
|
||||
partner_pool = self.pool.get('res.partner')
|
||||
partner_ids = partner_pool.search(cr, uid, [('name', '=', name)], context=context)
|
||||
if partner_ids:
|
||||
address_pool = self.pool.get('res.partner.address')#TODO create partner of find the one with the same name
|
||||
data = {'partner_id' : partner_ids[0]}
|
||||
address_pool.write(cr, uid, [address_id], data, context=context)
|
||||
return partner_ids[0]
|
||||
return False
|
||||
|
||||
def import_contact(self, cr, uid, ids, context=None):
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
|
||||
gmail_user = user_obj.gmail_user
|
||||
gmail_pwd = user_obj.gmail_password
|
||||
|
||||
google = self.pool.get('google.login')
|
||||
gd_client = google.google_login(gmail_user, gmail_pwd, type='contact')
|
||||
|
||||
if not gd_client:
|
||||
raise osv.except_osv(_('Error'), _("Please specify correct user and password !"))
|
||||
|
||||
if obj.group_name not in ['all']:
|
||||
query = gdata.contacts.service.ContactsQuery()
|
||||
query.group = obj.group_name
|
||||
contact = gd_client.GetContactsFeed(query.ToUri())
|
||||
else:
|
||||
contact = gd_client.GetContactsFeed()
|
||||
|
||||
ids = self.create_contact(cr, uid, ids, gd_client, contact, option=obj.create_partner,context=context)
|
||||
if not ids:
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
return {
|
||||
'name': _(obj.create_partner =='create_all' and 'Partners') or _('Contacts'),
|
||||
'domain': "[('id','in', ["+','.join(map(str,ids))+"])]",
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': obj.create_partner =='create_all' and 'res.partner' or 'res.partner.address',
|
||||
'context': context,
|
||||
'views': [(False, 'tree'),(False, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
|
||||
|
||||
def create_contact(self, cr, uid, ids, gd_client, contact, option,context=None):
|
||||
model_obj = self.pool.get('ir.model.data')
|
||||
addresss_obj = self.pool.get('res.partner.address')
|
||||
company_pool = self.pool.get('res.company')
|
||||
addresses = []
|
||||
partner_ids = []
|
||||
contact_ids = []
|
||||
if 'tz' in context and context['tz']:
|
||||
time_zone = context['tz']
|
||||
else:
|
||||
time_zone = tools.get_server_timezone()
|
||||
au_tz = timezone(time_zone)
|
||||
while contact:
|
||||
for entry in contact.entry:
|
||||
data = self._retreive_data(entry)
|
||||
google_id = data.pop('id')
|
||||
model_data = {
|
||||
'name': google_id,
|
||||
'model': 'res.partner.address',
|
||||
'module': 'sync_google_contact',
|
||||
'noupdate': True
|
||||
}
|
||||
|
||||
data_ids = model_obj.search(cr, uid, [('model','=','res.partner.address'), ('name','=', google_id)])
|
||||
if data_ids:
|
||||
contact_ids = [model_obj.browse(cr, uid, data_ids[0], context=context).res_id]
|
||||
elif data['email']:
|
||||
contact_ids = addresss_obj.search(cr, uid, [('email', 'ilike', data['email'])])
|
||||
|
||||
if contact_ids:
|
||||
addresses.append(contact_ids[0])
|
||||
address = addresss_obj.browse(cr, uid, contact_ids[0], context=context)
|
||||
google_updated = entry.updated.text
|
||||
utime = dateutil.parser.parse(google_updated)
|
||||
au_dt = au_tz.normalize(utime.astimezone(au_tz))
|
||||
updated_dt = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
if address.write_date < updated_dt:
|
||||
self.update_contact(cr, uid, contact_ids, data, context=context)
|
||||
res_id = contact_ids[0]
|
||||
if not contact_ids:
|
||||
#create or link to an existing partner only if it's a new contact
|
||||
data.update({'type': 'default'})
|
||||
res_id = addresss_obj.create(cr, uid, data, context=context)
|
||||
data['address_id'] = res_id
|
||||
if option == 'create_all':
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
data['customer'] = obj.customer
|
||||
data['supplier'] = obj.supplier
|
||||
res = False
|
||||
if 'company' in data:
|
||||
res = self.set_partner(cr, uid, data.get('company'), res_id, context=context)
|
||||
if res:
|
||||
partner_ids.append(res)
|
||||
if not res:
|
||||
partner_id = self.create_partner(cr, uid, data, context=context)
|
||||
partner_ids.append(partner_id)
|
||||
addresses.append(res_id)
|
||||
|
||||
if not data_ids: #link to google_id if it was not the case before
|
||||
model_data.update({'res_id': res_id})
|
||||
model_obj.create(cr, uid, model_data, context=context)
|
||||
|
||||
next = contact.GetNextLink()
|
||||
contact = next and gd_client.GetContactsFeed(next.href) or None
|
||||
|
||||
if option == 'create_all':
|
||||
return partner_ids
|
||||
else:
|
||||
return addresses
|
||||
|
||||
def _retreive_data(self, entry):
|
||||
data = {}
|
||||
data['id'] = entry.id.text
|
||||
name = tools.ustr(entry.title.text)
|
||||
if name == "None":
|
||||
name = entry.email[0].address
|
||||
data['name'] = name
|
||||
emails = ','.join(email.address for email in entry.email)
|
||||
data['email'] = emails
|
||||
if entry.organization:
|
||||
if entry.organization.org_name:
|
||||
data.update({'company': entry.organization.org_name.text})
|
||||
if entry.organization.org_title:
|
||||
data.update ({'function': entry.organization.org_title.text})
|
||||
|
||||
|
||||
if entry.phone_number:
|
||||
for phone in entry.phone_number:
|
||||
if phone.rel == gdata.contacts.REL_WORK:
|
||||
data['phone'] = phone.text
|
||||
if phone.rel == gdata.contacts.PHONE_MOBILE:
|
||||
data['mobile'] = phone.text
|
||||
if phone.rel == gdata.contacts.PHONE_WORK_FAX:
|
||||
data['fax'] = phone.text
|
||||
return data
|
||||
|
||||
def update_contact(self, cr, uid, contact_ids, data, context=None):
|
||||
addresss_obj = self.pool.get('res.partner.address')
|
||||
vals = {}
|
||||
addr = addresss_obj.browse(cr,uid,contact_ids)[0]
|
||||
name = str((addr.name or addr.partner_id and addr.partner_id.name or '').encode('utf-8'))
|
||||
|
||||
if name != data.get('name'):
|
||||
vals['name'] = data.get('name','')
|
||||
if addr.email != data.get('email'):
|
||||
vals['email'] = data.get('email','')
|
||||
if addr.mobile != data.get('mobile'):
|
||||
vals['mobile'] = data.get('mobile','')
|
||||
if addr.phone != data.get('phone'):
|
||||
vals['phone'] = data.get('phone','')
|
||||
if addr.fax != data.get('fax'):
|
||||
vals['fax'] = data.get('fax','')
|
||||
|
||||
addresss_obj.write(cr, uid, contact_ids, vals, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
synchronize_google_contact()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,39 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
'name': 'Google Calendar',
|
||||
'version': '1.0',
|
||||
'category': 'Generic Modules/Others',
|
||||
'description': """The module adds google calendar events to meetings.""",
|
||||
'author': 'OpenERP SA',
|
||||
'website': 'http://www.openerp.com',
|
||||
'depends': ['base','google_base_account', 'crm'],
|
||||
'init_xml': [],
|
||||
'update_xml': ['wizard/wizard_import_calendar_events_view.xml', 'sync_google_calendar_view.xml'],
|
||||
'test': ['test/test_sync_google_calendar.yml'],
|
||||
'demo_xml': [],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
'certificate': '',
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,50 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
|
||||
class crm_meeting(osv.osv):
|
||||
_inherit = "crm.meeting"
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
ids = self.web_client_unfucking_timebomb(ids)
|
||||
res = super(crm_meeting, self).unlink(cr, uid, ids, context=context)
|
||||
ids_real = self.remove_virtual_id(ids)
|
||||
|
||||
model_obj = self.pool.get('ir.model.data')
|
||||
remain_ids = self.search(cr, uid, [('id','in',ids_real)])
|
||||
ids_to_remove = list(set(ids_real) - set(remain_ids))
|
||||
|
||||
model_ids = model_obj.search(cr, uid, [('res_id','in',ids_to_remove),('model','=','crm.meeting'),('module','=','sync_google_calendar')], context=context)
|
||||
model_obj.unlink(cr, uid, model_ids, context=context)
|
||||
return res
|
||||
|
||||
crm_meeting()
|
||||
|
||||
class crm_case_categ(osv.osv):
|
||||
""" Category of Case """
|
||||
_inherit = "crm.case.categ"
|
||||
_columns = {
|
||||
'user_id': fields.many2one('res.users', 'User')
|
||||
}
|
||||
crm_case_categ()
|
||||
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,24 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard_import_calendar_events
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,304 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
import tools
|
||||
|
||||
import time
|
||||
import datetime
|
||||
import dateutil
|
||||
from dateutil.tz import *
|
||||
from dateutil.parser import *
|
||||
from dateutil import parser
|
||||
from pytz import timezone
|
||||
import re
|
||||
import urllib
|
||||
|
||||
try:
|
||||
import gdata
|
||||
import gdata.calendar.service
|
||||
import gdata.calendar
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
|
||||
|
||||
def _get_tinydates(self, stime, etime):
|
||||
stime = dateutil.parser.parse(stime)
|
||||
etime = dateutil.parser.parse(etime)
|
||||
try:
|
||||
au_dt = au_tz.normalize(stime.astimezone(au_tz))
|
||||
timestring = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
au_dt = au_tz.normalize(etime.astimezone(au_tz))
|
||||
timestring_end = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
except:
|
||||
timestring = datetime.datetime(*stime.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
timestring_end = datetime.datetime(*etime.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
return (timestring, timestring_end)
|
||||
|
||||
|
||||
def _get_rules(self, datas):
|
||||
new_val = {}
|
||||
if datas['FREQ'] == 'WEEKLY' and datas.get('BYDAY'):
|
||||
for day in datas['BYDAY'].split(','):
|
||||
new_val[day.lower()] = True
|
||||
datas.pop('BYDAY')
|
||||
|
||||
if datas.get('UNTIL'):
|
||||
until = parser.parse(''.join((re.compile('\d')).findall(datas.get('UNTIL'))))
|
||||
new_val['end_date'] = until.strftime('%Y-%m-%d')
|
||||
new_val['end_type'] = 'end_date'
|
||||
datas.pop('UNTIL')
|
||||
|
||||
if datas.get('COUNT'):
|
||||
new_val['count'] = datas.get('COUNT')
|
||||
new_val['end_type'] = 'count'
|
||||
datas.pop('COUNT')
|
||||
|
||||
if datas.get('INTERVAL'):
|
||||
new_val['interval'] = datas.get('INTERVAL')
|
||||
else:
|
||||
new_val['interval'] = 1
|
||||
|
||||
if datas.get('BYMONTHDAY'):
|
||||
new_val['day'] = datas.get('BYMONTHDAY')
|
||||
datas.pop('BYMONTHDAY')
|
||||
new_val['select1'] = 'date'
|
||||
|
||||
if datas.get('BYDAY'):
|
||||
d = datas.get('BYDAY')
|
||||
if '-' in d:
|
||||
new_val['byday'] = d[:2]
|
||||
new_val['week_list'] = d[2:4].upper()
|
||||
else:
|
||||
new_val['byday'] = d[:1]
|
||||
new_val['week_list'] = d[1:3].upper()
|
||||
new_val['select1'] = 'day'
|
||||
|
||||
if datas.get('BYMONTH'):
|
||||
new_val['month_list'] = datas.get('BYMONTH')
|
||||
datas.pop('bymonth')
|
||||
return new_val
|
||||
|
||||
|
||||
def _get_repeat_status(self, str_google):
|
||||
rrule = str_google[str_google.find('FREQ'):str_google.find('\nBEGIN')]
|
||||
status = {}
|
||||
for rule in rrule.split(';'):
|
||||
status[rule.split('=')[0]] = rule.split('=')[-1:] and rule.split('=')[-1:][0] or ''
|
||||
rules = _get_rules(self, status)
|
||||
if status.get('FREQ') == 'WEEKLY':
|
||||
status.update({'rrule_type': 'weekly'})
|
||||
status.pop('FREQ')
|
||||
elif status.get('FREQ') == 'DAILY':
|
||||
status.update({'rrule_type': 'daily'})
|
||||
status.pop('FREQ')
|
||||
elif status.get('FREQ') == 'MONTHLY':
|
||||
status.update({'rrule_type': 'monthly'})
|
||||
status.pop('FREQ')
|
||||
elif status.get('FREQ') == 'YEARLY':
|
||||
status.update({'rrule_type': 'yearly'})
|
||||
status.pop('FREQ')
|
||||
status.update(rules)
|
||||
return status
|
||||
|
||||
|
||||
def _get_repeat_dates(self, x):
|
||||
if len(x) > 4:
|
||||
if x[3].startswith('BY'):
|
||||
zone_time = x[4].split('+')[-1:][0].split(':')[0][:4]
|
||||
else:
|
||||
zone_time = x[3].split('+')[-1:][0].split(':')[0][:4]
|
||||
else:
|
||||
zone_time = x[2].split('+')[-1:][0].split(':')[0][:4]
|
||||
tz_format = zone_time[:2]+':'+zone_time[2:]
|
||||
repeat_start = x[1].split('\n')[0].split(':')[1]
|
||||
repeat_end = x[2].split('\n')[0].split(':')[1]
|
||||
o = repeat_start.split('T')
|
||||
repeat_start = str(o[0][:4]) + '-' + str(o[0][4:6]) + '-' + str(o[0][6:8])
|
||||
if len(o) == 2:
|
||||
repeat_start += ' ' + str(o[1][:2]) + ':' + str(o[1][2:4]) + ':' + str(o[1][4:6])
|
||||
else:
|
||||
repeat_start += ' ' + '00' + ':' + '00' + ':' + '00'
|
||||
p = repeat_end.split('T')
|
||||
repeat_end = str(p[0][:4]) + '-' + str(p[0][4:6]) + '-' + str(p[0][6:8])
|
||||
if len(p) == 2:
|
||||
repeat_end += ' ' + str(p[1][:2]) + ':' + str(p[1][2:4]) + ':' + str(p[1][4:6])
|
||||
else:
|
||||
repeat_end += ' ' + '00' + ':' + '00' + ':' + '00'
|
||||
return (repeat_start, repeat_end, tz_format)
|
||||
|
||||
|
||||
class google_login(osv.osv_memory):
|
||||
_inherit = 'google.login'
|
||||
_name = 'google.login'
|
||||
|
||||
def _get_next_action(self, cr, uid, context=None):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
data_id = data_obj._get_id(cr, uid, 'sync_google_calendar', 'view_synchronize_google_calendar_import_form')
|
||||
view_id = False
|
||||
if data_id:
|
||||
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
|
||||
value = {
|
||||
'name': _('Import Events'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'synchronize.google.calendar',
|
||||
'view_id': False,
|
||||
'context': context,
|
||||
'views': [(view_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
return value
|
||||
|
||||
google_login()
|
||||
|
||||
|
||||
class synchronize_google_calendar_events(osv.osv_memory):
|
||||
_name = 'synchronize.google.calendar'
|
||||
|
||||
def _get_calendars(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google = self.pool.get('google.login')
|
||||
res = []
|
||||
try:
|
||||
gd_client = google.google_login(user_obj.gmail_user, user_obj.gmail_password, type='calendar')
|
||||
calendars = gd_client.GetAllCalendarsFeed()
|
||||
for cal in calendars.entry:
|
||||
res.append((cal.id.text, cal.title.text))
|
||||
except Exception, e:
|
||||
raise osv.except_osv('Error !', e.args[0].get('body'))
|
||||
res.append(('all', 'All Calendars'))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'calendar_name': fields.selection(_get_calendars, "Calendar Name", size=32),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'calendar_name': 'all',
|
||||
}
|
||||
|
||||
def get_events(self, cr, uid, event_feed, context=None):
|
||||
meeting_obj = self.pool.get('crm.meeting')
|
||||
categ_obj = self.pool.get('crm.case.categ')
|
||||
model_obj = self.pool.get('ir.model.data')
|
||||
object_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'crm.meeting')])
|
||||
meeting_ids = []
|
||||
categ_id = categ_obj.search(cr, uid, [('name', '=', event_feed.title.text), ('object_id', '=', object_id and object_id[0]), ('user_id', '=', uid)])
|
||||
if not categ_id:
|
||||
categ_id.append(categ_obj.create(cr, uid, {'name': event_feed.title.text,
|
||||
'object_id': object_id and object_id[0],
|
||||
'user_id': uid}))
|
||||
if 'tz' in context and context['tz']:
|
||||
time_zone = context['tz']
|
||||
else:
|
||||
time_zone = tools.get_server_timezone()
|
||||
au_tz = timezone(time_zone)
|
||||
|
||||
for feed in event_feed.entry:
|
||||
google_id = feed.id.text
|
||||
model_data = {
|
||||
'name': google_id,
|
||||
'model': 'crm.meeting',
|
||||
'module': 'sync_google_calendar',
|
||||
'noupdate': True,
|
||||
}
|
||||
vals = {
|
||||
'name': feed.title.text or '(No title)',
|
||||
'description': feed.content.text,
|
||||
'categ_id': categ_id and categ_id[0],
|
||||
}
|
||||
if feed.when:
|
||||
timestring, timestring_end = _get_tinydates(self, feed.when[0].start_time, feed.when[0].end_time)
|
||||
else:
|
||||
x = feed.recurrence.text.split(';')
|
||||
repeat_status = _get_repeat_status(self, feed.recurrence.text)
|
||||
repeat_start, repeat_end, zone_time = _get_repeat_dates(self, x)
|
||||
timestring = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(repeat_start, "%Y-%m-%d %H:%M:%S"))
|
||||
timestring_end = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(repeat_end, "%Y-%m-%d %H:%M:%S"))
|
||||
if repeat_status:
|
||||
repeat_status.update({'recurrency': True})
|
||||
vals.update(repeat_status)
|
||||
|
||||
vals.update({'date': timestring, 'date_deadline': timestring_end})
|
||||
data_ids = model_obj.search(cr, uid, [('model', '=', 'crm.meeting'), ('name', '=', google_id)])
|
||||
if data_ids:
|
||||
res_id = model_obj.browse(cr, uid, data_ids[0], context=context).res_id
|
||||
meeting = meeting_obj.browse(cr, uid, res_id, context=context)
|
||||
google_updated = feed.updated.text
|
||||
utime = dateutil.parser.parse(google_updated)
|
||||
au_dt = au_tz.normalize(utime.astimezone(au_tz))
|
||||
updated_dt = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
if meeting.write_date < updated_dt:
|
||||
meeting_ids.append(res_id)
|
||||
meeting_obj.write(cr, uid, [res_id], vals, context=context)
|
||||
else:
|
||||
res_id = meeting_obj.create(cr, uid, vals, context=context)
|
||||
meeting_ids.append(res_id)
|
||||
model_data.update({'res_id': res_id})
|
||||
model_obj.create(cr, uid, model_data, context=context)
|
||||
return meeting_ids
|
||||
|
||||
def import_calendar_events(self, cr, uid, ids, context=None):
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
if not ids:
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
gmail_user = user_obj.gmail_user
|
||||
gamil_pwd = user_obj.gmail_password
|
||||
|
||||
google = self.pool.get('google.login')
|
||||
gd_client = google.google_login(gmail_user, gamil_pwd, type='calendar')
|
||||
|
||||
if not gmail_user or not gamil_pwd:
|
||||
raise osv.except_osv(_('Error'), _("Please specify the user and password !"))
|
||||
|
||||
meetings = []
|
||||
if obj.calendar_name != 'all':
|
||||
events_query = gdata.calendar.service.CalendarEventQuery(user=urllib.unquote(obj.calendar_name.split('/')[~0]))
|
||||
events_query.start_index = 1
|
||||
events_query.max_results = 1000
|
||||
event_feed = gd_client.GetCalendarEventFeed(events_query.ToUri())
|
||||
meetings.append(self.get_events(cr, uid, event_feed, context=context))
|
||||
else:
|
||||
calendars = map(lambda x: x[0], [cal for cal in self._get_calendars(cr, uid, context) if cal[0] != 'all'])
|
||||
for cal in calendars:
|
||||
events_query = gdata.calendar.service.CalendarEventQuery(user=urllib.unquote(cal.split('/')[~0]))
|
||||
events_query.start_index = 1
|
||||
events_query.max_results = 1000
|
||||
event_feed = gd_client.GetCalendarEventFeed(events_query.ToUri())
|
||||
meetings.append(self.get_events(cr, uid, event_feed, context=context))
|
||||
|
||||
meeting_ids = []
|
||||
for meeting in meetings:
|
||||
meeting_ids += meeting
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.act_window_close',
|
||||
}
|
||||
|
||||
synchronize_google_calendar_events()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,41 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="view_synchronize_google_calendar_import_form">
|
||||
<field name="name">synchronize.google.calendar.form</field>
|
||||
<field name="model">synchronize.google.calendar</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Google Calendar Events">
|
||||
<group colspan="4" col="4">
|
||||
<field name="calendar_name" />
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
<group colspan="2" col="2"/>
|
||||
<group colspan="2" col="2">
|
||||
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
|
||||
<button name="import_calendar_events" string="_Import Events" type="object" icon="terp-calendar"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<!--
|
||||
Login Action
|
||||
-->
|
||||
<record model="ir.actions.act_window" id="act_google_login_form">
|
||||
<field name="name">Import Google Calendar</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">google.login</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="google_base_account.view_google_login_form" />
|
||||
</record>
|
||||
<menuitem id="menu_sync_contact"
|
||||
parent="crm.menu_meeting_sale"
|
||||
action="act_google_login_form"
|
||||
sequence="20" />
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user