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 = { 'id': mapper.m2o(TITLE_PREFIX, 'Contact Title'), 'name': mapper.val('Contact Title', skip=True),
# 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)) 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')
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')
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': 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'), }