# -*- 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 = {
from odoo_csv_tools.lib import transform 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') }
'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)
'U.S': 'base.us', '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)
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')
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 = {
if len(sys.argv) == 2: 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 = {
# -*- 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}",
# -*- 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 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', {})
# -*- coding: utf-8 -*- from odoo_csv_tools.lib import mapper from odoo_csv_tools.lib.transform import ProductProcessorV10 from prefix import * context = {'create_product_product': True, 'tracking_disable': True} #STEP 1 : read the needed file(s) processor = ProductProcessorV10('origin/product.csv', 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', {'model': 'product.category'}, 'set') processor.process(categ_map, 'data/product.category.csv', {}, 'set') #STEP 3 : Product Template mapping template_map = { 'id': mapper.m2o(TEMPLATE_PREFIX, 'ref'), 'categ_id/id': mapper.m2o(CATEGORY_PREFIX, 'Sub Category'), 'standard_price': mapper.num('cost'),