@@ -30,8 +30,8 @@ class google_login(osv.osv_memory):
|
||||
_description ='Google Contact'
|
||||
_name = 'google.login'
|
||||
_columns = {
|
||||
'user': fields.char('Username', size=64, required=True),
|
||||
'password': fields.char('Password', size=64),
|
||||
'user': fields.char('Google Username', size=64, required=True),
|
||||
'password': fields.char('Google Password', size=64),
|
||||
}
|
||||
|
||||
def google_login(self, user, password, type='group', context=None):
|
||||
@@ -42,7 +42,7 @@ class google_login(osv.osv_memory):
|
||||
gd_client = gdata.contacts.service.ContactsService()
|
||||
try:
|
||||
gd_client.ClientLogin(user, password,gd_client.source)
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
return False
|
||||
return gd_client
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ class synchronize_google_contact(osv.osv_memory):
|
||||
|
||||
_columns = {
|
||||
'create_partner': fields.selection([('create_all','Create partner for each contact'),('create_address','Import only address')],'Options'),
|
||||
'customer': fields.boolean('Customer'),
|
||||
'supplier': fields.boolean('Supplier'),
|
||||
'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By default it takes all."),
|
||||
}
|
||||
|
||||
@@ -87,9 +89,13 @@ class synchronize_google_contact(osv.osv_memory):
|
||||
|
||||
def create_partner(self, cr, uid, data={}, context=None):
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
name = data.get('name','')
|
||||
partner_id = partner_obj.create(cr, uid, {'name': name, 'address' : [(6, 0, [data['address_id']])]}, context=context)
|
||||
return partner_id, data
|
||||
partner_id = partner_obj.create(cr, uid, {
|
||||
'name': data.get('name',''),
|
||||
'address' : [(6, 0, [data['address_id']])],
|
||||
'customer': data.get('customer', False),
|
||||
'supplier': data.get('supplier', False)
|
||||
}, context=context)
|
||||
return partner_id
|
||||
|
||||
def import_contact(self, cr, uid, ids, context=None):
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
@@ -112,7 +118,7 @@ class synchronize_google_contact(osv.osv_memory):
|
||||
else:
|
||||
contact = gd_client.GetContactsFeed()
|
||||
|
||||
ids = self.create_contact(cr, uid, gd_client, contact, option=obj.create_partner,context=context)
|
||||
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'}
|
||||
|
||||
@@ -127,7 +133,7 @@ class synchronize_google_contact(osv.osv_memory):
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
|
||||
def create_contact(self, cr, uid, gd_client, contact, option,context=None):
|
||||
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')
|
||||
addresses = []
|
||||
@@ -141,6 +147,7 @@ class synchronize_google_contact(osv.osv_memory):
|
||||
'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)])
|
||||
@@ -158,7 +165,10 @@ class synchronize_google_contact(osv.osv_memory):
|
||||
res_id = addresss_obj.create(cr, uid, data, context=context)
|
||||
data['address_id'] = res_id
|
||||
if option == 'create_all':
|
||||
partner_id, data = self.create_partner(cr, uid, data, context=context)
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
data['customer'] = obj.customer
|
||||
data['supplier'] = obj.supplier
|
||||
partner_id = self.create_partner(cr, uid, data, context=context)
|
||||
partner_ids.append(partner_id)
|
||||
addresses.append(res_id)
|
||||
|
||||
|
||||
@@ -6,11 +6,16 @@
|
||||
<field name="model">synchronize.base</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Google Contacts">
|
||||
<group colspan="4" col="4">
|
||||
<form string="Import contacts from a google account">
|
||||
<group colspan="4" col="4" width="430">
|
||||
<field name="group_name" />
|
||||
<separator string="Import Options" colspan="4"/>
|
||||
<field name="create_partner"/>
|
||||
<newline/>
|
||||
<group attrs="{'invisible': [('create_partner','!=','create_all')]}" colspan="2" col="4">
|
||||
<field name="customer"/>
|
||||
<field name="supplier"/>
|
||||
</group>
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<group colspan="4" col="4">
|
||||
@@ -29,7 +34,7 @@
|
||||
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="name">Import Contacts</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">google.login.contact</field>
|
||||
<field name="view_type">form</field>
|
||||
|
||||
Reference in New Issue
Block a user