[REF] sync_google_contact: Improved searching of partner addresses from ir.model.data and removed google_id field from it.
bzr revid: uco@tinyerp.com-20110303122347-03hr3oo95nrqim5u
This commit is contained in:
parent
7c512f970b
commit
4548040fbf
|
@ -24,19 +24,10 @@ from osv import fields,osv
|
|||
class res_users(osv.osv):
|
||||
_inherit = "res.users"
|
||||
_columns = {
|
||||
'gmail_user': fields.char('Google Account', size=64,),
|
||||
'gmail_user': fields.char('Username', size=64,),
|
||||
'gmail_password': fields.char('Password', size=64),
|
||||
}
|
||||
res_users()
|
||||
|
||||
class ir_model_data(osv.osv):
|
||||
|
||||
_inherit = "ir.model.data"
|
||||
_columns = {
|
||||
'google_id': fields.char('Google Contact Id', size=128, readonly=True),
|
||||
}
|
||||
|
||||
ir_model_data()
|
||||
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook[last()]" position="inside">
|
||||
<page string=" Synchronization ">
|
||||
<separator string="Google User Detail" colspan="4" />
|
||||
<separator string="Google Account" colspan="4" />
|
||||
<field name="gmail_user"/>
|
||||
<field name="gmail_password" password="True"/>
|
||||
</page>
|
||||
|
|
|
@ -85,9 +85,7 @@ 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.search(cr, uid, [('name','ilike',name)], context=context)
|
||||
if not partner_id:
|
||||
partner_id.append(partner_obj.create(cr, uid, {'name': name, 'address' : [(6, 0, [data['address_id']])]}, context=context))
|
||||
partner_id = partner_obj.create(cr, uid, {'name': name, 'address' : [(6, 0, [data['address_id']])]}, context=context)
|
||||
return partner_id, data
|
||||
|
||||
def import_contact(self, cr, uid, ids, context=None):
|
||||
|
@ -137,8 +135,9 @@ class synchronize_google_contact(osv.osv_memory):
|
|||
while contact:
|
||||
for entry in contact.entry:
|
||||
data = {}
|
||||
google_id = entry.id.text
|
||||
model_data = {
|
||||
'name': 'google_contacts_information_%s' %(entry.id.text),
|
||||
'name': google_id,
|
||||
'model': 'res.partner.address',
|
||||
'module': 'sync_google_contact',
|
||||
}
|
||||
|
@ -146,13 +145,10 @@ class synchronize_google_contact(osv.osv_memory):
|
|||
if name == "None":
|
||||
name = entry.email[0].address
|
||||
|
||||
google_id = entry.id.text
|
||||
emails = ','.join(email.address for email in entry.email)
|
||||
if name and name != 'None':
|
||||
data['name'] = name
|
||||
|
||||
if google_id:
|
||||
model_data.update({'google_id': google_id})
|
||||
if entry.phone_number:
|
||||
for phone in entry.phone_number:
|
||||
if phone.rel == gdata.contacts.REL_WORK:
|
||||
|
@ -162,7 +158,7 @@ class synchronize_google_contact(osv.osv_memory):
|
|||
if phone.rel == gdata.contacts.PHONE_WORK_FAX:
|
||||
data['fax'] = phone.text
|
||||
|
||||
data_ids = model_obj.search(cr, uid, [('google_id','=',google_id)])
|
||||
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 emails:
|
||||
|
@ -181,7 +177,7 @@ class synchronize_google_contact(osv.osv_memory):
|
|||
data['address_id'] = res_id
|
||||
if option == 'create_all':
|
||||
partner_id, data = self.create_partner(cr, uid, data, context=context)
|
||||
partner_ids.append(partner_id[0])
|
||||
partner_ids.append(partner_id)
|
||||
addresses.append(res_id)
|
||||
model_data.update({'res_id': res_id})
|
||||
model_obj.create(cr, uid, model_data, context=context)
|
||||
|
|
Loading…
Reference in New Issue