bzr revid: uco@tinyerp.com-20110301054908-zzd1f3apatda2y8c
This commit is contained in:
Ujjvala Collins (OpenERP)
2011-03-01 11:19:08 +05:30
10 changed files with 42 additions and 260 deletions
@@ -19,12 +19,12 @@
#
##############################################################################
from osv import fields,osv,orm
from osv import fields,osv
class res_users(osv.osv):
_inherit = "res.users"
_columns = {
'gmail_user': fields.char('User Name', size=64,),
'gmail_user': fields.char('Google Account', size=64,),
'gmail_password': fields.char('Password', size=64),
}
res_users()
@@ -30,7 +30,7 @@ class google_login(osv.osv_memory):
_description ='Google Contact'
_name = 'google.login'
_columns = {
'user': fields.char('User Name', size=64, required=True),
'user': fields.char('Username', size=64, required=True),
'password': fields.char('Password', size=64),
}
@@ -74,7 +74,7 @@ class google_login(osv.osv_memory):
}
self.pool.get('res.users').write(cr, uid, uid, res, context=context)
except :
raise osv.except_osv(_('Error'), _("Authication fail check the user and password !"))
raise osv.except_osv(_('Error'), _("Authentication fail check the user and password !"))
return self._get_next_action(cr, uid, context=context)
-25
View File
@@ -1,25 +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 sync_base
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-40
View File
@@ -1,40 +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 Contact',
'version': '1.0',
'category': 'Generic Modules/Others',
'description': """The module adds synchronization with multiple app """,
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'depends': ['base'],
'init_xml': [],
'update_xml': [
'wizard/sync_base_view.xml'
],
'demo_xml': [],
'installable': True,
'active': False,
'certificate': '',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-24
View File
@@ -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 synchronize_base
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,40 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="sync_base_import_wizard_view">
<field name="name">Synchronize contact</field>
<field name="model">synchronize.base.contact.wizard.import</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Import contact from external adress book">
<field name="tools"/>
<newline />
<separator string="" colspan="4"/>
<group colspan="4" col="4">
<group colspan="2"/>
<group colspan="2">
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
<button name="action_synchronize" string="_Synchronize" type="object" icon="terp-check"/>
</group>
</group>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="act_google_contact_import_form">
<field name="name">Import contacts from remote address book</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">synchronize.base.contact.wizard.import</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="sync_base_import_wizard_view" />
</record>
<menuitem name="Import contacts from remote address book" id="menu_sync_contact"
parent="base.menu_address_book" action="act_google_contact_import_form"
sequence="40" />
</data>
</openerp>
@@ -1,61 +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,osv
from tools.translate import _
class synchronize_base(osv.osv_memory):
_description ='Synchronize base import contact '
_name = "synchronize.base.contact.wizard.import"
def _get_tools_name(self, cr, user, context):
"""
@return the list of value of the selection field
should be overwritten by subclasses
"""
return []
_columns = {
'tools': fields.selection(_get_tools_name, 'App to synchronize with'),
}
def action_synchronize(self, cr, uid, ids, context=None):
wizard_data = self.browse(cr, uid, ids, context=context)
return self._get_action(cr, uid, wizard_data[0].tools, context=context)
def _get_action(self, cr, uid, tools, context=None):
if not tools:
raise osv.except_osv(_("Error !"),_("Select App to synchronize with."))
return self._get_actions_dic(cr, uid, context=context)[tools]
def _get_actions_dic(self, cr, uid, context=None):
"""
this method should be overwritten in specialize module
@return the dictonnaries of action
"""
return {'none' : {'type': 'ir.actions.act_window_close' }}
synchronize_base()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+2 -2
View File
@@ -24,10 +24,10 @@
'name': 'Google Contact',
'version': '1.0',
'category': 'Generic Modules/Others',
'description': """The module adds google contact in partner address""",
'description': """The module adds google contact in partner address""",
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'depends': ['base','google_base_account','sync_base'],
'depends': ['base','google_base_account'],
'init_xml': [],
'update_xml': [
'wizard/google_contact_import_view.xml'
@@ -30,53 +30,6 @@ try:
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'))
class google_base_import(osv.osv_memory):
_inherit = 'synchronize.base.contact.wizard.import'
def _get_tools_name(self, cr, user, context):
"""
@return the list of value of the selection field
should be overwritten by subclasses
"""
names = super(google_base_import, self)._get_tools_name(cr, user, context=context)
names.append(('gmail','Gmail address book'))
return names
_columns = {
'tools': fields.selection(_get_tools_name, 'App to synchronize with'),
}
def _get_actions_dic(self, cr, uid, context=None):
"""
this method should be overwritten in specialize module
@return the dictonnaries of action
"""
actions = super(google_base_import, self)._get_actions_dic(cr, uid, context=context)
data_obj = self.pool.get('ir.model.data')
data_id = data_obj._get_id(cr, uid, 'google_base_account', 'view_google_login_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': 'google.login.contact',
'view_id': False,
'context': context,
'views': [(view_id, 'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
actions['gmail'] = value
return actions
google_base_import()
class google_contact_import(osv.osv_memory):
_inherit = 'google.login'
_name = 'google.login.contact'
@@ -120,12 +73,12 @@ class synchronize_google_contact(osv.osv_memory):
return res
_columns = {
'create_partner': fields.boolean('Create Partner', help="It will create Partner for given gmail user otherwise only adds contacts in Partner Addresses.") ,
'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By defult it take all "),
'create_partner': fields.selection([('create_all','Create partner for each contact'),('create_address','Import only address')],'Options'),
'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By default it takes all."),
}
_defaults = {
'create_partner': True,
'create_partner': 'create_all',
'group_name': 'all',
}
@@ -138,7 +91,7 @@ class synchronize_google_contact(osv.osv_memory):
return partner_id, data
def import_contact(self, cr, uid, ids, context=None):
obj=self.browse(cr, uid, ids, context=context)[0]
obj = self.browse(cr, uid, ids, context=context)[0]
if obj.group_name == 'none':
return { 'type': 'ir.actions.act_window_close' }
@@ -155,28 +108,27 @@ class synchronize_google_contact(osv.osv_memory):
if obj.group_name not in ['all','none']:
query = gdata.contacts.service.ContactsQuery()
query.group =obj.group_name
query.group = obj.group_name
contact = gd_client.GetContactsFeed(query.ToUri())
else:
contact = gd_client.GetContactsFeed()
ids = self.create_contact( cr, uid, gd_client,contact, partner_id=obj.create_partner,context=context)
ids = self.create_contact(cr, uid, gd_client, contact, option=obj.create_partner,context=context)
if not ids:
return {'type': 'ir.actions.act_window_close'}
return {
'name': _('Partner'),
'name': _(obj.create_partner =='create_all' and 'Partner') or _('Contacts'),
'domain': "[('id','in', ["+','.join(map(str,ids))+"])]",
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': obj.create_partner and 'res.partner' or 'res.partner.address',
'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, gd_client,contact, partner_id=False,context=None):
def create_contact(self, cr, uid, gd_client, contact, option,context=None):
model_obj = self.pool.get('ir.model.data')
addresss_obj = self.pool.get('res.partner.address')
addresses = []
@@ -227,7 +179,7 @@ class synchronize_google_contact(osv.osv_memory):
#create or link to an existing partner only if it's a new contact
res_id = addresss_obj.create(cr, uid, data, context=context)
data['address_id'] = res_id
if partner_id:
if option == 'create_all':
partner_id, data = self.create_partner(cr, uid, data, context=context)
partner_ids.append(partner_id[0])
addresses.append(res_id)
@@ -237,15 +189,15 @@ class synchronize_google_contact(osv.osv_memory):
next = contact.GetNextLink()
contact = next and gd_client.GetContactsFeed(next.href) or None
if partner_id:
if option == 'create_all':
return partner_ids
else:
return addresses
def update_contact(self, cr, uid, contact_ids, data,context=None):
def update_contact(self, cr, uid, contact_ids, data, context=None):
addresss_obj = self.pool.get('res.partner.address')
if context==None:
context={}
if context == None:
context = {}
res = {}
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'))
@@ -9,8 +9,8 @@
<form string="Import Google Contacts">
<group colspan="4" col="4">
<field name="group_name" />
<separator string="Do you want to create partner?" colspan="4"/>
<field name="create_partner" colspan="4"/>
<separator string="Import Options" colspan="4"/>
<field name="create_partner"/>
</group>
<separator string="" colspan="4"/>
<group colspan="4" col="4">
@@ -23,5 +23,25 @@
</form>
</field>
</record>
<!--
Login Action
-->
<record model="ir.actions.act_window" id="act_google_login_form">
<field name="name">Import contacts from your google account</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">google.login.contact</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="base.menu_address_book"
action="act_google_login_form"
sequence="40" />
</data>
</openerp>