[MERGE] Merge backlog correction of import_contact

bzr revid: sbh@tinyerp.com-20110516053922-3dgm3ots97p6edon
This commit is contained in:
Bhumika (OpenERP)
2011-05-16 11:09:22 +05:30
4 changed files with 45 additions and 18 deletions
+1 -1
View File
@@ -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="It will import contacts from your google account."),
'import_google_contact': 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):
@@ -1,3 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_res_users_partner_manager","google.res.partner.manager","base.model_ir_model_data","base.group_partner_manager",1,1,1,0
"access_ir_model_data_partner_manager","ir.model.data.partner.manager","base.model_res_users","base.group_partner_manager",1,1,0,0
"access_ir_model_data_partner_manager","ir.model.data.partner.manager","base.model_res_users","base.group_partner_manager",1,1,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_res_users_partner_manager google.res.partner.manager base.model_ir_model_data base.group_partner_manager 1 1 1 0
3 access_ir_model_data_partner_manager ir.model.data.partner.manager base.model_res_users base.group_partner_manager 1 1 0 0
@@ -22,7 +22,6 @@ import datetime
import dateutil
from dateutil.parser import *
from pytz import timezone
import os
try:
import gdata
@@ -41,7 +40,8 @@ class synchronize_google_contact(osv.osv_memory):
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 !"))
@@ -68,9 +68,18 @@ class synchronize_google_contact(osv.osv_memory):
}
def create_partner(self, cr, uid, data={}, context=None):
partner_obj = self.pool.get('res.partner')
partner_id = partner_obj.create(cr, uid, {
'name': data.get('name',''),
if context == None:
context = {}
if not data:
return False
partner_pool = self.pool.get('res.partner')
company_pool = self.pool.get('res.company')
if 'company_id' in data:
company = company_pool.browse(cr, uid, data.get('company_id'), context=context)
return company.partner_id.id
partner_id = partner_pool.create(cr, uid, {
'name': data.get('name',''),
'user_id': uid,
'address' : [(6, 0, [data['address_id']])],
'customer': data.get('customer', False),
'supplier': data.get('supplier', False)
@@ -113,6 +122,16 @@ class synchronize_google_contact(osv.osv_memory):
'type': 'ir.actions.act_window',
}
def getCompanyId(self, cr, uid, company, context=None):
if context == None:
context = {}
company_pool = self.pool.get('res.company')
company_id = company_pool.search(cr, uid, [('name', '=', company)])
if company_id:
return company_id[0]
new_cid = company_pool.create(cr, uid, {'name': company})
return new_cid
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')
@@ -124,10 +143,13 @@ class synchronize_google_contact(osv.osv_memory):
else:
time_zone = tools.get_server_timezone()
au_tz = timezone(time_zone)
while contact:
for entry in contact.entry:
data = self._retreive_data(entry)
if 'company' in data:
company = data.pop('company')
if company:
data.update({'company_id': self.getCompanyId(cr, uid, company, context=context)})
google_id = data.pop('id')
model_data = {
'name': google_id,
@@ -154,6 +176,7 @@ class synchronize_google_contact(osv.osv_memory):
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':
@@ -162,8 +185,9 @@ class synchronize_google_contact(osv.osv_memory):
data['supplier'] = obj.supplier
partner_id = self.create_partner(cr, uid, data, context=context)
partner_ids.append(partner_id)
addresss_obj.write(cr, uid, [res_id], {'partner_id': partner_id}, context=context)
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)
@@ -185,7 +209,13 @@ class synchronize_google_contact(osv.osv_memory):
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:
@@ -13,11 +13,9 @@
<field name="create_partner" colspan="4"/>
<newline/>
<group attrs="{'invisible': [('create_partner','!=','create_all')]}" colspan="4" col="4">
<separator string="Partner status for this group:"/>
<field name="customer"/>
<newline/>
<label string=""/>
<field name="supplier"/>
<separator string="Partner status for this group:" colspan="4"/>
<field name="customer" colspan="4"/>
<field name="supplier" colspan="4"/>
</group>
</group>
<separator string="" colspan="4"/>
@@ -31,8 +29,7 @@
</form>
</field>
</record>
<record model="ir.actions.act_window" id="act_import_google_contacts_form">
<field name="name">Import Contacts</field>
<field name="type">ir.actions.act_window</field>
@@ -45,7 +42,7 @@
<menuitem id="menu_sync_contact"
parent="base.menu_address_book"
parent="base.menu_address_book"
action="act_import_google_contacts_form"
sequence="40" />
</data>