Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
      • Get a Tailored Demo
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +32 2 290 34 90
    • Get a Tailored Demo
  • Pricing
  • Help
  1. APPS
  2. Connector
  3. Connector Importer v 18.0
  4. Sales Conditions FAQ

Connector Importer

by Camptocamp https://github.com/OCA/connector-interfaces , Odoo Community Association (OCA) https://github.com/OCA/connector-interfaces
Odoo
v 18.0 Third Party 185
Download for v 18.0 Deploy on Odoo.sh
Apps purchases are linked to your Odoo account, please sign in or sign up first.
Availability
Odoo Online
Odoo.sh
On Premise
Odoo Apps Dependencies Discuss (mail)
Community Apps Dependencies Show
• Connector
• Job Queue
• Components
• Components Events
Lines of code 8119
Technical Name connector_importer
LicenseAGPL-3
Websitehttps://github.com/OCA/connector-interfaces
Versions 12.0 13.0 14.0 15.0 18.0
You bought this module and need support? Click here!
Odoo Community Association

Connector Importer

Beta License: AGPL-3 OCA/connector-interfaces Translate me on Weblate Try me on Runboat

This module allows to import / update records from files using the connector framework and job queue.

To run an import you need at least:

  • a backend, hosts the global configuration of the import.
  • a recordset, hosts the configuration of the import for specific models and source
  • a source, provides the data to import
  • an import type, describes which models you want to import and how to import them

Table of contents

  • Configuration
    • Import type
    • The importer
    • The mapper
    • The record_handler
    • Translations
  • Known issues / Roadmap
  • Bug Tracker
  • Credits
    • Authors
    • Contributors
    • Other credits
    • Maintainers

Configuration

Import type

Import types are the main configuration of the import. They describe which models you want to import and how to import them.

Exaple of configuration:

<record id="import_type_product_product_all_in_one" model="import.type">
    <field name="name">Import Product - all in one</field>
    <field name="key">product_product_all_in_one</field>
    <field name="options">

- model: product.product
    options:
        importer:
            odoo_unique_key: barcode
        mapper:
            name: product.product.mapper

- model: res.partner
    options:
        importer:
            odoo_unique_key: name
        override_existing: false
        mapper:
            name: importer.mapper.dynamic
            source_key_prefix: supplier.
            source_key_whitelist: supplier.name
            default_keys:
                supplier_rank: 1

- model: product.supplierinfo
    options:
        importer:
            odoo_unique_key: name
        mapper:
            name: product.supplierinfo.mapper
            source_key_prefix: supplier.

    </field>

</record>

In this example we have 3 models to import one after the other using the same source file:

  • product.product
  • res.partner
  • product.supplierinfo

The import will run in the order of the configuration: first product.product, then res.partner and finally product.supplierinfo. For each model we have a configuration that describes how to import the data. With the options key we can define the configuration of the import for each component: importer, mapper, record_handler, tracking_handler.

The are 4 main components in the import configuration:

  • importer
  • mapper
  • record_handler
  • tracking_handler

Each of them is responsible for a specific part of the import.

The importer

importer is the main component that will import the data. It will use the mapper to map the data from the source to the destination model. If no name is defined the importer will use the default importer for the model which is capable of importing any model. Most of the time you don’t need a specific importer.

As the importer is the main component of the import if you want to customize it you’ll have to declare it at an higher level, next to the options key:

- model: product.product
    importer:
        name: product.product.importer
    options:
        mapper:
            name: product.product.mapper

The importer accepts the following options:

  • odoo_unique_key: the field that will be used to find the record in Odoo. If the record is found it will be updated, otherwise it will be created.

    NOTE: the value in the column declared as odoo_unique_key will be treated as xid only if the name of the column is ìd or if it starts with xid::.

  • break_on_error: if set to True the import will stop if an error occurs. Default is False.

  • override_existing: if set to True the existing records will be updated. Default is True.

  • translation_key_sep: the separator used to split the translation key. Default is :. See below for information about translation keys.

  • translation_use_regional_lang: if set to True the importer will use the regional language, eg: fr_CH vs fr.

  • ctx: a dictionary of values to inject in the context of the import.

  • write_only: if set to True the importer will not create new records, it will only update existing ones. Default is False.

The mapper

The mapper is the component that will map the data from the source to the destination model.

The most flexible mapper is the importer.mapper.dynamic that will map the data based on the model introspection and some options that you can define. The dynamic mapper accepts the following options:

  • name: the name of the mapper to use. If no name is defined the default mapper for the model will be used.
  • source_key_prefix: a prefix to add to the source key. This is useful when you want to map the same source key to different destination fields.
  • source_key_whitelist: a list of source keys to import. If not defined all the keys will be imported.
  • source_key_blacklist: a list of source keys to exclude from the import.
  • source_key_rename: a dictionary of source keys to rename. The key is the source key and the value is the new key.
  • default_keys: a dictionary of default values to set on the destination record. The key is the field name and the value is the default value.
  • translation_keys: a list of keys that will be used to translate the data. See below for information about translation keys.
  • required_keys: a list of keys that are required. If one of the keys is missing the record will be skipped. Please refer to the documentation of the mapper to see advanced options.

Considering the example above:

- model: product.product
    options:
        mapper:
            name: importer.mapper.dynamic
            source_key_prefix: supplier.
            source_key_whitelist: supplier.name
            default_keys:
                supplier_rank: 1

The mapper will:

  • import only keys starting with supplier. ignoring the rest
  • import only the key supplier.name
  • set the default value of supplier_rank to 1

The record_handler

The record handler is the component that will handle the record create or update in Odoo. This component is responsible for:

  • finding the record in Odoo
  • creating the record if not found
  • updating the record if found
  • handling the translations

If no name is defined the importer will use the default record handler for the model which is capable of handling any model. If you want to customize the record handler you’ll have to declare it at an higher level, next to the options key:

- model: product.product
    options:
        record_handler:
            name: product.product.record_handler

To find the record in Odoo the record handler will use the odoo_unique_key if defined in the importer otherwise it will fallback to the matching domain. See below.

The record handler accepts the following options:

  • name: the name of the record handler to use. If no name is defined the default record handler for the model will be used.

  • match_domain: a domain to match the record in Odoo. When no odoo_unique_key is provided by the importer you must provide a match_domain.

    This key accepts a snippet returning a domain. The snippet will be evaluated in the context of the import and will receive:

    • orig_values: the values from the source

    • values: values computed by the mapper for the record

    • env

    • user

    • datetime

    • dateutil

    • time

    • ref_id: a function to get a record ID from a reference

    • ref: a function to get a record from a reference

      Example:

      match_domain: |
          [('name', '=', values.get('name'))]
      
  • must_generate_xmlid: if set to True the importer will generate an XML ID for the record. Default is True if the unique key is an xmlid.

  • skip_fields_unchanged: if set to True the importer will skip the fields that are unchanged. Default is False.

Translations

The importer can translate the data using the translation keys. The translation keys are a list of keys (column) that will be handled as translatable. Whenever a key is found in the translation keys the importer will look for a column with the same name suffixed by the language code (eg: name:fr_CH). If the column is found the importer will translate the data using the language code as context.

Known issues / Roadmap

  • with the import of standard Odoo CSV files, a concurrency error occurs when updating the report_data of import_recordset table (from the importer: self._do_report() -> self.recordset.set_report(…)). The job is automatically retried a second time (without concurrency errors). For small files it’s not a big issue, but for files with a huge amount of lines it takes time to process them two times.
  • move generic functions from utils.mapper_utils to the connector module
  • unit tests for record handler and tracker
  • add more test coverage for mapper utils and dynamic mapper
  • consider making dynamic mapper the default one
  • control how to generate xid (eg: from a specicic field with key must_generate_xmlid_from_key)
  • add manual control for backend_to_rel mappers
  • refactor source to be a specific m2o to ease mgmt instead of a generic relation

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Camptocamp

Contributors

Simone Orsi (Camptocamp) for the original implementation.

Other contributors include:

  • Guewen Baconnier (Camptocamp)
  • Mykhailo Panarin (Camptocamp)
  • Sébastien Alix (Camptocamp)
  • Thien Vo (Trobz)

Other credits

The migration of this module from 16.0 to 18.0 was financially supported by Camptocamp.

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainer:

simahawk

This module is part of the OCA/connector-interfaces project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with