コード例 #1
0
from datetime import datetime
from prefix import *

#STEP 1 : read the needed file(s)
processor = Processor('origin/supplier.csv')

##STEP 2 : Define the mapping for every object to import
mapping = {
    'id': mapper.m2o(SUPPLIER_PREFIX, 'Company_ID'),
    'name': mapper.val('Company_Name'),
    'phone': mapper.val('Phone'),
    'street': mapper.val('address1'),
    'city': mapper.val('city'),
    'zip': mapper.val('zip code'),
    'country_id/id': mapper.map_val('country', country_map),
    'supplier': mapper.const('1'),
    'user_id': mapper.val('Account_Manager'),
}

contact_mapping = {
    'id': mapper.m2o(SUPPLIER_CONTACT_PREFIX, 'Contact Email'),
    'parent_id/id': mapper.m2o(SUPPLIER_PREFIX, 'Company_ID'),
    'email': mapper.val('Contact Email'),
    'name': mapper.concat(' ', 'Contact First Name', 'Contact Last Name'),
    'title/id': mapper.m2o(TITLE_PREFIX, 'Contact Title'),
}

title_map = {
    'id': mapper.m2o(TITLE_PREFIX, 'Contact Title'),
    'name': mapper.val('Contact Title', skip=True),
    'shortcut': mapper.val('Contact Title')
コード例 #2
0
# STEP 2 : Define the mapping for every object to import
mapping = {
    'id': mapper.m2o_map(PARTNER_PREFIX, mapper.val('CODICE')),
    'name': mapper.val('DESCRIZION', skip=True),
    'street': mapper.val('INDIRIZZO'),
    'city': mapper.val('COMUNE'),
    'zip': mapper.val('CAP'),
    'country_id/id': mapper.val('PAESE', postprocess=postprocess_country_id),
    'state_id/id': mapper.val('PROVINCIA', postprocess=postprocess_country_state_id),
    'vat': mapper.val('PARTITA_IV', postprocess=postprocess_vat),
    'phone': mapper.val('TELEFONO1'),
    'email': mapper.val('E_MAIL'),

    # OTHER
    'lang': mapper.val('PAESE', postprocess=postprocess_lang),
    'customer': mapper.const('1'),
    'supplier': mapper.const('1'),

}


# Contatti ulteriori
# 'TELEFONO2'
# 'RIFERIMEN2'
# 'TELEFONO3'
# 'RIFERIMEN3'
# 'NUMERO_FAX'
# 'RIFERIMEN4'
def postprocess_riferimento(val, n):
    return '{}.{}_RIF{}'.format(PARTNER_PREFIX, val, n)
コード例 #3
0
# Print o2o mapping
import pprint

pprint.pprint(processor.get_o2o_mapping())

# STEP 2 : Define the mapping for every object to import
mapping = {
    'id': mapper.m2o(PARTNER_PREFIX, 'Company_ID', skip=True),
    'name': mapper.val('Company_Name', skip=True),
    'phone': mapper.val('Phone'),
    'website': mapper.val('www'),
    'street': mapper.val('address1'),
    'city': mapper.val('city'),
    'zip': mapper.val('zip code'),
    'country_id/id': mapper.map_val('country', country_map),
    'company_type': mapper.const('company'),
    'customer': mapper.bool_val('IsCustomer', ['1'], ['0']),
    'supplier': mapper.bool_val('IsSupplier', ['1'], ['0']),
    'lang': mapper.map_val('Language', lang_map),
    'image': mapper.binary("Image", "origin/img/"),
}

# Step 3: Check data quality (Optional)
processor.check(checker.cell_len_checker(30))
processor.check(checker.id_validity_checker('Company_ID', "COM\d"))
processor.check(checker.line_length_checker(13))
processor.check(checker.line_number_checker(21))

# Step 4: Process data
processor.process(mapping, 'data%sres.partner.csv' % os.sep, {'worker': 2, 'batch_size': 5}, 'set')
コード例 #4
0
tags = ["Tag %s" % i for i in xrange(0, 100)]

header = ['id', 'tags']
data = [[str(i), ','.join(tags[random.randint(0, 99)] for i in xrange(0, 5))]
        for i in xrange(0, 1000)]

mapping = {
    'id': mapper.m2o(PARTNER_PREFIX, 'id'),
    'name': mapper.val('id', postprocess=lambda x: "Partner %s" % x),
    'phone': mapper.val('id', postprocess=lambda x: "0032%s" % (int(x) * 11)),
    'website': mapper.val('id',
                          postprocess=lambda x: "http://website-%s.com" % x),
    'street': mapper.val('id', postprocess=lambda x: "Street %s" % x),
    'city': mapper.val('id', postprocess=lambda x: "City %s" % x),
    'zip': mapper.val('id', postprocess=lambda x: ("%s" % x).zfill(6)),
    'country_id/id': mapper.const('base.be'),
    'company_type': mapper.const('company'),
    'customer': mapper.val('id', postprocess=lambda x: str(int(x) % 2)),
    'supplier': mapper.val('id', postprocess=lambda x: str((int(x) + 1) % 2)),
    'lang': mapper.const('English'),
    'category_id/id': mapper.m2m(TAG_PREFIX, 'tags')
}

tag_mapping = {
    'id': mapper.m2m_id_list(TAG_PREFIX, 'tags'),
    'name': mapper.m2m_value_list('tags'),
    'parent_id/id': mapper.const('base.res_partner_category_0'),
}

processor = transform.Processor(header=header, data=data)
processor.process(tag_mapping,
コード例 #5
0
processor = Processor('origin%scontact.csv' % os.sep)
# Print o2o mapping
import pprint
pprint.pprint(processor.get_o2o_mapping())

# STEP 2 : Define the mapping for every object to import
mapping = {
    'id': mapper.m2o(PARTNER_PREFIX, 'Company_ID', skip=True),
    'name': mapper.val('Company_Name', skip=True),
    'phone': mapper.val('Phone'),
    'website': mapper.val('www'),
    'street': mapper.val('address1'),
    'city': mapper.val('city'),
    'zip': mapper.val('zip code'),
    'country_id/id': mapper.map_val('country', country_map),
    'company_type': mapper.const('company'),
    'customer': mapper.bool_val('IsCustomer', ['1'], ['0']),
    'supplier': mapper.bool_val('IsSupplier', ['1'], ['0']),
    'lang': mapper.map_val('Language', lang_map),
    'image': mapper.binary("Image", "origin/img/"),
}

# Step 3: Check data quality (Optional)
processor.check(checker.cell_len_checker(30))
processor.check(checker.id_validity_checker('Company_ID', "COM\d"))
processor.check(checker.line_length_checker(13))
processor.check(checker.line_number_checker(21))

# Step 4: Process data
processor.process(mapping, 'data%sres.partner.csv' % os.sep, {'worker': 2, 'batch_size': 5}, 'set')
コード例 #6
0
    mapper.m2o_map(CLIENT_PREFIX, mapper.concat('_', 'Client Name',
                                                'zip code')),
    'name':
    mapper.val('Client Name', skip=True),
    'phone':
    mapper.val('Phone'),
    'street':
    mapper.val('address1'),
    'city':
    mapper.val('city'),
    'zip':
    mapper.val('zip code'),
    'country_id/id':
    mapper.map_val('country', country_map),
    'customer':
    mapper.const('1'),
    'lang':
    mapper.map_val('Language', lang_map),
    'image':
    mapper.binary("Image", "origin/img/"),
    'create_uid':
    mapper.val('Create BY'),
    'create_date':
    mapper.val('Create ON',
               postprocess=lambda x: datetime.strptime(x, "%d/%m/%y").strftime(
                   "%Y-%m-%d 00:00:00")),
    'category_id/id':
    mapper.m2m(PARTNER_CATEGORY_PREFIX, 'Tag', 'Fidelity Grade'),
}

tag_mapping = {
コード例 #7
0
script = '0_partner_generated.sh'

tags = ["Tag %s" % i for i in range(0, 100)]

header = ['id', 'tags']
data = [[str(i), ','.join(tags[random.randint(0, 99)] for i in range(0, 5))] for i in range(0, 200)]

mapping = {
    'id': mapper.m2o(PARTNER_PREFIX, 'id'),
    'name': mapper.val('id', postprocess=lambda x: "Partner %s" % x),
    'phone': mapper.val('id', postprocess=lambda x: "0032%s" % (int(x) * 11)),
    'website': mapper.val('id', postprocess=lambda x: "http://website-%s.com" % x),
    'street': mapper.val('id', postprocess=lambda x: "Street %s" % x),
    'city': mapper.val('id', postprocess=lambda x: "City %s" % x),
    'zip': mapper.val('id', postprocess=lambda x: ("%s" % x).zfill(6)),
    'country_id/id': mapper.const('base.be'),
    'company_type': mapper.const('company'),
    'customer': mapper.val('id', postprocess=lambda x: str(int(x) % 2)),
    'supplier': mapper.val('id', postprocess=lambda x: str((int(x) + 1) % 2)),
    'lang': mapper.const('English'),
    'category_id/id': mapper.m2m(TAG_PREFIX, 'tags')
}

tag_mapping = {
    'id': mapper.m2m_id_list(TAG_PREFIX, 'tags'),
    'name': mapper.m2m_value_list('tags'),
    'parent_id/id': mapper.const('base.res_partner_category_0'),
}

processor = transform.Processor(header=header, data=data)
processor.process(tag_mapping, tag_output, {