[MERGE] import_base
bzr revid: tfr@openerp.com-20110712142747-3ndn5uy106w09j07
This commit is contained in:
@@ -49,7 +49,6 @@ class import_framework(Thread):
|
||||
#TODO don't use context to pass credential parameters
|
||||
def __init__(self, obj, cr, uid, instance_name, module_name, email_to_notify=False, context=None):
|
||||
Thread.__init__(self)
|
||||
#change this value to set another default field for unique ID in the external table
|
||||
self.external_id_field = 'id'
|
||||
self.obj = obj
|
||||
self.cr = cr
|
||||
@@ -59,8 +58,7 @@ class import_framework(Thread):
|
||||
self.context = context or {}
|
||||
self.email = email_to_notify
|
||||
self.table_list = []
|
||||
self.initialize()
|
||||
|
||||
|
||||
"""
|
||||
Abstract Method to be implemented in
|
||||
the real instance
|
||||
@@ -317,6 +315,7 @@ class import_framework(Thread):
|
||||
xml_ref = self.mapped_id_if_exist(model, domain_search, table, name)
|
||||
fields.append('id')
|
||||
data.append(xml_id)
|
||||
|
||||
obj.import_data(self.cr, self.uid, fields, [data], mode='update', current_module=self.module_name, noupdate=True, context=self.context)
|
||||
return xml_ref or xml_id
|
||||
|
||||
@@ -361,6 +360,7 @@ class import_framework(Thread):
|
||||
self.data_started = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self.cr = pooler.get_db(self.cr.dbname).cursor()
|
||||
try:
|
||||
self.initialize()
|
||||
result = []
|
||||
imported = set() #to invoid importing 2 times the sames modules
|
||||
for table in self.table_list:
|
||||
@@ -401,6 +401,7 @@ class import_framework(Thread):
|
||||
def _send_notification_email(self, result):
|
||||
if not self.email:
|
||||
return False
|
||||
|
||||
tools.email_send(
|
||||
'import@module.openerp',
|
||||
self.email,
|
||||
@@ -451,15 +452,20 @@ class import_framework(Thread):
|
||||
def run_test(self):
|
||||
back_get_data = self.get_data
|
||||
back_get_link = self.get_link
|
||||
back_init = self.initialize
|
||||
self.get_data = self.get_data_test
|
||||
self.get_link = self.get_link_test
|
||||
self.initialize = self.intialize_test
|
||||
self.run()
|
||||
self.get_data = back_get_data
|
||||
self.get_link = back_get_link
|
||||
|
||||
self.initialize = back_init
|
||||
|
||||
def get_data_test(self, table):
|
||||
return [{}]
|
||||
|
||||
def get_link_test(self, from_table, ids, to_table):
|
||||
return {}
|
||||
|
||||
def intialize_test(self):
|
||||
pass
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import tools
|
||||
|
||||
class mapper(object):
|
||||
"""
|
||||
@@ -50,14 +50,13 @@ class concat(mapper):
|
||||
Use : contact('field_name1', 'field_name2', delimiter='_')
|
||||
concat value of fields using the delimiter, delimiter is optional
|
||||
and by default is a space
|
||||
|
||||
"""
|
||||
def __init__(self, *arg, **delimiter):
|
||||
self.arg = arg
|
||||
self.delimiter = delimiter and delimiter.get('delimiter', ' ') or ' '
|
||||
|
||||
def __call__(self, external_values):
|
||||
return self.delimiter.join(map(lambda x : str(external_values.get(x,'')), self.arg))
|
||||
return self.delimiter.join(map(lambda x : tools.ustr(external_values.get(x,'')), self.arg))
|
||||
|
||||
class ppconcat(mapper):
|
||||
"""
|
||||
@@ -71,7 +70,7 @@ class ppconcat(mapper):
|
||||
self.delimiter = delimiter and delimiter.get('delimiter', ' ') or '\n\n'
|
||||
|
||||
def __call__(self, external_values):
|
||||
return self.delimiter.join(map(lambda x : x + ": " + str(external_values.get(x,'')), self.arg))
|
||||
return self.delimiter.join(map(lambda x : x + ": " + tools.ustr(external_values.get(x,'')), self.arg))
|
||||
|
||||
class const(mapper):
|
||||
"""
|
||||
@@ -105,6 +104,7 @@ class value(mapper):
|
||||
val = external_values.get(self.fallback, self.default)
|
||||
return val
|
||||
|
||||
|
||||
class map_val(mapper):
|
||||
"""
|
||||
Use : map_val(external_field, val_mapping)
|
||||
|
||||
Reference in New Issue
Block a user