def database_id_mapper_fun(line): res = to_m2o(PREFIX, line[field]) if res: module, name = res.split('.') rec = connection.get_model('ir.model.data').search_read( [('module', '=', module), ('name', '=', name)], ['res_id']) if rec and rec[0]['res_id']: return str(rec[0]['res_id']) if skip: raise SkippingException("%s not found" % res) return ''
def binary_val(line): path = path_prefix + (line[field] or '') if not os.path.exists(path) or not line[field]: if skip: raise SkippingException("Missing File %s for field %s" % (path, field)) return '' with open(path, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) image_file.close() return encoded_string
def database_id_mapper_fun(line): res = [f(line) for f in fields_mapper if f(line)] if res: res = res[0] module, name = res.split('.') rec = connection.get_model('ir.model.data').search_read( [('module', '=', module), ('name', '=', name)], ['res_id']) if rec and rec[0]['res_id']: return str(rec[0]['res_id']) else: print "import" connection.get_model(model).load(['id', 'name'], [[res, res]], context={ 'tracking_disable': True, 'create_product_variant': True, }) return database_id_mapper_fun(line) if skip: raise SkippingException("%s not found" % res) return ''
def val_fun(line): if not line[field] and not line[fallback_file] and skip: raise SkippingException("Missing Value for %s" % field) value = line[field] or line[fallback_file] or default return postprocess(value)
def val_fun(line): if not line[field] and skip: raise SkippingException("Missing Value for %s" % field) return postprocess(line.get(field, default) or default)
def m2o_fun(line): if skip and not line[field]: raise SkippingException("Missing Value for %s" % field) return to_m2o(PREFIX, line[field], default=default)
def m2o_fun(line): if skip and not mapper(line): raise SkippingException("Missing Value for %s" % mapper(line)) return to_m2o(PREFIX, mapper(line), default=default)