# -*- coding: utf-8 -*- from odoo_csv_tools.lib import mapper from odoo_csv_tools.lib.transform import Processor 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 = {
return 'IT{}'.format(val) if val[:2] == 'IT': if len(val) == 13 and val[:3].isdigit(): return val.upper() if val[:2] in ('GB', 'EE', 'LT'): return val return '' # STEP 1 : read the needed file(s) processor = Processor('../data/NOMIN.CSV', conf_file=CONNECTION_FILE, delimiter=",") # 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'),
import random PARTNER_PREFIX = 'partner_generated' TAG_PREFIX = 'partner_tag' output = 'data/res.partner.generated.csv' tag_output = 'data/res.partner.category.csv' script = '0_partner_generated.sh' 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 = {
'NL': 'base.nl', } PARTNER_PREFIX = "TEST_PARTNER" # STEP 1 : read the needed file(s) 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))
PRODUCT_PREFIX = "PRODUCT_PRODUCT" CATEGORY_PREFIX = "PRODUCT_CATEGORY" ATTRIBUTE_PREFIX = "PRODUCT_ATTRIBUTE" ATTRIBUTE_VALUE_PREFIX = "PRODUCT_ATTRIBUTE_VALUE" ATTRIBUTE_LINE_PREFIX = "PRODUCT_ATTRIBUTE_LINE" context = {'create_product_variant': True, 'tracking_disable': True} #STEP 1 : read the needed file(s) processor = ProductProcessorV10('origin%sproduct.csv' % os.sep, delimiter=',') #STEP 2 : Category and Parent Category categ_parent_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('categoy'), } categ_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'Sub Category'), 'parent_id/id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('Sub Category'), } processor.process(categ_parent_map, 'data%sproduct.category.parent.csv' % os.sep, { 'worker': 1, 'batch_size': 5, 'model': 'product.category' }, 'set') processor.process(categ_map, 'data%sproduct.category.csv' % os.sep, {
TEMPLATE_PREFIX = "PRODUCT_TEMPLATE" PRODUCT_PREFIX = "PRODUCT_PRODUCT" CATEGORY_PREFIX = "PRODUCT_CATEGORY" ATTRIBUTE_PREFIX = "PRODUCT_ATTRIBUTE" ATTRIBUTE_VALUE_PREFIX = "PRODUCT_ATTRIBUTE_VALUE" # Define the context that will be used context = {'create_product_variant': True, 'tracking_disable': True} # STEP 1 : read the needed file(s) processor = ProductProcessorV9('origin%sproduct.csv' % os.sep, delimiter=',') # STEP 2 : Category and Parent Category categ_parent_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('categoy'), } categ_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'Sub Category'), 'parent_id/id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('Sub Category'), } processor.process(categ_parent_map, 'data%sproduct.category.parent.csv' % os.sep, { 'worker': 1, 'batch_size': 5, 'model': 'product.category' }, 'set') processor.process(categ_map, 'data%sproduct.category.csv' % os.sep, {
PRODUCT_PREFIX = "PRODUCT_PRODUCT" CATEGORY_PREFIX = "PRODUCT_CATEGORY" ATTRIBUTE_PREFIX = "PRODUCT_ATTRIBUTE" ATTRIBUTE_VALUE_PREFIX = "PRODUCT_ATTRIBUTE_VALUE" ATTRIBUTE_LINE_PREFIX = "PRODUCT_ATTRIBUTE_LINE" context = {'create_product_variant': True, 'tracking_disable': True} # STEP 1 : read the needed file(s) processor = ProductProcessorV10('origin%sproduct.csv' % os.sep, delimiter=',') # STEP 2 : Category and Parent Category categ_parent_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('categoy'), } categ_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'Sub Category'), 'parent_id/id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('Sub Category'), } processor.process(categ_parent_map, 'data%sproduct.category.parent.csv' % os.sep, {'worker': 1, 'batch_size': 5, 'model': 'product.category'}, 'set') processor.process(categ_map, 'data%sproduct.category.csv' % os.sep, {'worker': 1, 'batch_size': 20}, 'set') # STEP 3 : Product Template mapping template_map = { 'id': mapper.m2o(TEMPLATE_PREFIX, 'ref'),
'US': 'base.us', 'NL': 'base.nl', } PARTNER_PREFIX = "TEST_PARTNER" # STEP 1 : read the needed file(s) 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))
TEMPLATE_PREFIX = "PRODUCT_TEMPLATE" PRODUCT_PREFIX = "PRODUCT_PRODUCT" CATEGORY_PREFIX = "PRODUCT_CATEGORY" ATTRIBUTE_PREFIX = "PRODUCT_ATTRIBUTE" ATTRIBUTE_VALUE_PREFIX = "PRODUCT_ATTRIBUTE_VALUE" # Define the context that will be used context = {'create_product_variant': True, 'tracking_disable': True} # STEP 1 : read the needed file(s) processor = ProductProcessorV9('origin%sproduct.csv' % os.sep, delimiter=',') # STEP 2 : Category and Parent Category categ_parent_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('categoy'), } categ_map = { 'id': mapper.m2o(CATEGORY_PREFIX, 'Sub Category'), 'parent_id/id': mapper.m2o(CATEGORY_PREFIX, 'categoy'), 'name': mapper.val('Sub Category'), } processor.process(categ_parent_map, 'data%sproduct.category.parent.csv' % os.sep, {'worker': 1, 'batch_size': 5, 'model': 'product.category'}, 'set') processor.process(categ_map, 'data%sproduct.category.csv' % os.sep, {'worker': 1, 'batch_size': 20}, 'set') # STEP 3 : Product Template mapping template_map = { 'id': mapper.m2o(TEMPLATE_PREFIX, 'ref'),
from odoo_csv_tools.lib import mapper from odoo_csv_tools.lib.transform import Processor from datetime import datetime processor = Processor('client_file.csv', delimiter=';') res_partner_mapping = { 'id': mapper.m2o_map('my_import_res_partner', mapper.concat('_', 'Firstname', 'Lastname', 'Birthdate')), 'name': mapper.concat(' ', 'Firstname', 'Lastname'), 'birthdate': mapper.val('Birthdate', postprocess=lambda x: datetime.strptime(x, "%d/%m/%y").strftime( "%Y-%m-%d 00:00:00")), } processor.process( res_partner_mapping, 'res.partner.csv', { 'model': 'res.partner', 'context': "{'tracking_disable': True}", 'worker': 2, 'batch_size': 20 }) processor.write_to_file("res_partner.sh", python_exe='', path='')
import os from odoo_csv_tools.lib import mapper from odoo_csv_tools.lib.transform import Processor from datetime import datetime from prefix import * #STEP 1 : read the needed file(s) processor = Processor('origin%scontact.csv' % os.sep) ##STEP 2 : Define the mapping for every object to import mapping = { 'id': 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':
EXEC = sys.argv[1] PARTNER_PREFIX = 'partner_generated' TAG_PREFIX = 'partner_tag' output = 'data/res.partner.generated.csv' tag_output = 'data/res.partner.category.csv' 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'),
# -*- coding: utf-8 -*- from odoo_csv_tools.lib import mapper from odoo_csv_tools.lib.transform import Processor from datetime import datetime processor = Processor('client_file.csv', delimiter=";") res_partner_mapping = { 'id': mapper.m2o( 'my_import_res_partner', mapper.concat('_', 'name', 'Birthdate', 'phone', 'email', 'website')), 'name': mapper.val('id', postprocess=lambda x: "Partner %s" % x), 'birthdate': mapper.val('Birthdate', postprocess=lambda x: datetime.strftime(x, "%d/%m/%y").strftime( "%Y-%m-%d 00:00:))")), 'phone': mapper.val('phone', postprocess=lambda x: "855%s" % (int(x) * 10)), 'email': mapper.val('email', postprocess=lambda x: "Email %s" % x), 'website': mapper.val('website', postprocess=lambda x: "website %s" % x) } processor.process( res_partner_mapping, 'res.partner.csv', { 'model': 'res.partner', 'context': "{'tracking_disable': True}",
from datetime import datetime from prefix import SUPPLIER_PREFIX, MESSAGE_PREFIX, SUPPLIER_CONTACT_PREFIX #STEP 1 : read the needed file(s) processor = Processor('origin/message.csv') ##STEP 2 : Define the mapping for every object to import mapping = { 'id': mapper.m2o_map(MESSAGE_PREFIX, mapper.concat("_", 'Company_ID', 'Date')), 'res_external_id': mapper.m2o(SUPPLIER_PREFIX, 'Company_ID'), 'author_id/id': mapper.m2o(SUPPLIER_CONTACT_PREFIX, 'from'), 'email_from': mapper.val('from'), 'subject': mapper.val('subject'), 'body': mapper.val('body'), 'date': mapper.val('Date', postprocess=lambda x: datetime.strptime(x, "%d/%m/%y %H:%M:%S"). strftime("%Y-%m-%d %H:%M:%S")), } #Step 4: Process data processor.process(mapping, 'data/mail.message.csv', {}) #Step 5: Define output and import parameter processor.write_to_file("3_supplier_message.sh", python_exe='', path='')