[IMP] review of contact import
authortfr@openerp.com <>
Fri, 24 Jun 2011 16:11:17 +0000 (18:11 +0200)
committertfr@openerp.com <>
Fri, 24 Jun 2011 16:11:17 +0000 (18:11 +0200)
bzr revid: tfr@openerp.com-20110624161117-6n2qzn3u2iix1pvb

addons/base_calendar/base_calendar.py
addons/import_base/import_framework.py
addons/import_base/mapper.py
addons/import_google/partner.py
addons/import_google/wizard/import_google.py

index d0dfbe2..d47de04 100644 (file)
@@ -1366,7 +1366,7 @@ rule or repeating pattern of time to exclude from the recurring rule."),
             
         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)
         for re in res:
index 8e93082..9b25ecb 100644 (file)
@@ -237,6 +237,7 @@ class import_framework(Thread):
             Check if the external id exist in the openerp database
             in order to check if the id exist the table where it come from
             should be provide
+            @return the xml_id generated if the external_id exist in the database or false
         """
         if not external_id:
             return False
index 582a45e..7f97ed0 100644 (file)
@@ -94,12 +94,18 @@ class value(mapper):
         and don't care about the name of the field
         call(self.method, value('field1'))
     """
-    def __init__(self, val, default=''):
+    def __init__(self, val, default='', fallback=False):
         self.val = val
         self.default = default
+        self.fallback = fallback
         
     def __call__(self, external_values):
-        return external_values.get(self.val, self.default) 
+        val = external_values.get(self.val, self.default) 
+        if self.fallback and (not val or val == self.default):
+            val = external_values.get(self.fallback, self.default)
+        return val 
+    
+
     
 class map_val(mapper):
     """
index b7c640a..232f18d 100644 (file)
 
 from osv import fields,osv
 
-class res_partner_address(osv.osv):
-    _inherit = "res.partner.address"
-
-    _columns = {
-        'write_date': fields.datetime('Date Modified', readonly=True, help="Modification date and time of address."),
-    }
-
-    def unlink(self, cr, uid, ids, context=None):
-        model_obj = self.pool.get('ir.model.data')
-        model_ids = model_obj.search(cr, uid, [('res_id','in',ids),('model','=','res.partner.address'),('module','=','sync_google_contact')], context=context)
-        model_obj.unlink(cr, uid, model_ids, context=context)
-        return super(res_partner_address, self).unlink(cr, uid, ids, context=context)
-
-res_partner_address()
-
 class crm_case_categ(osv.osv):
     """ Category of Case """
     _inherit = "crm.case.categ"
index 2aedade..87155c8 100644 (file)
@@ -27,6 +27,7 @@ from dateutil import *
 from pytz import timezone
 from datetime import datetime
 import time
+from osv import *
 try:
     import gdata
     import gdata.contacts.service
@@ -195,7 +196,7 @@ class google_import(import_framework):
             event_feed = self.gd_client.GetCalendarEventFeed(events_query.ToUri())
             for feed in event_feed.entry:
                 event = {
-                    'recurrency': "0",
+                    'recurrency': False,
                     'end_date' : False,
                     'end_type' : False,
                     'byday': 0,
@@ -238,15 +239,14 @@ class google_import(import_framework):
         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):
+    def get_rec(self, val):
         if val.get("recurrency"):
-            val.update({"recurrency": "1"})
-        return val
+            return "1"
+        return "0"
 
     def get_event_mapping(self):
         return {
             'model': 'crm.meeting',
-            'hook': self.get_event,
             'map': {
                     'id': 'id',
                     'name': 'Name',
@@ -255,7 +255,7 @@ class google_import(import_framework):
                     'date': 'DateStart',
                     'date_deadline': 'DateEnd',
                     'categ_id/id': call(self.get_event_category, value('Category')),
-                    'recurrency': 'recurrency',
+                    'recurrency': self.get_rec,
                     'end_date' : 'end_date',
                     'end_type' : 'end_type',
                     'byday':'byday',
@@ -312,37 +312,25 @@ class google_import(import_framework):
 
 
 
-    def get_address_id(self, val):
-        contact = self.xml_id_exist(self.TABLE_ADDRESS, val.get('id'))
-        if contact:
-            return str(contact)
-        return False
-
     def get_contact_mapping(self):
         return {
             'model': 'res.partner',
             'dependencies': [self.TABLE_ADDRESS],
             'map': {
                 'id':'id',
-                'name': 'name',
+                'name': value('company', fallback='name'),
                 'customer': 'customer',
                 'supplier': 'supplier',
-                'address/id': self.get_address_id,
+                'address/id': ref(self.TABLE_ADDRESS, 'id'),
                 }
             }
 
     def get_partner_id(self, val):
         partner_id = False
-        address_pool = self.obj.pool.get('res.partner.address')
-        company_pool = self.obj.pool.get('res.company')
+        company_pool = self.obj.pool.get('res.partner')
         if 'company' in val:
-            cids = company_pool.search(self.cr, self.uid, [('name', '=', val.get('company'))])
-            if cids:
-                records = company_pool.browse(self.cr, self.uid, cids)
-                for rec in records:
-                    if rec.partner_id:
-                        partner_id = rec.partner_id
-            return partner_id
+            partner_ids = company_pool.search(self.cr, self.uid, [('name', '=', val.get('company'))])
+            return partner_ids and partner_ids[0] or False
         contact = self.xml_id_exist(self.TABLE_CONTACT, val.get('id'))
         if contact:
             partner_id = self.get_mapped_id(self.TABLE_CONTACT, val.get('id'))