Package: odoo14-addon-pattern-import-export
OverviewThis module extends the import/export capabilities of Odoo.Patterns are simply a type of ir.exports model, so you can define them with the native Odoo widget to define export lists.This module only create a common data structure. Other modules will be used to add specific file type support like excel and csv.FeaturesKey matching: instead of always using IDs, match keys to unique-constrained fields, for example update a product by
specifying its product_code instead of its database ID or external IDOne2many and Many2many support: create or update for example invoice lines with a syntax that is very readable and easy to updateAs long as you respect the appropriate format and field names, you are free to add/remove/rename columns, even if they
are not in the initial Pattern used for the exportTable of contentsConfigurationUsageConfigurationInstall another module that supports a specific file typeUse the Patterns menu to configure your import/export formatsUsageConfiguring a patternFirst you have to define a pattern:Go on the Import/Export->Patterns menuCreate your pattern with fields to exportYou can refer to the examples in demo data.ExportingOpen the tree view of any model and tick some record selection boxes.In the sidebar, click on the “Export with Pattern” buttonSelect the pattern that you wish to use, click export and download the generated file.A “Pattern file” is created, and its job along with it. Depending on the success or failure of the job,
you will receive a red/green notification on your window.ImportingYou have two options:Open the tree view of any model and tick some record selection boxes (for this step, these don’t matter, we only just want to show the sidebar).In the sidebar, click on the “Import with Pattern” buttonSelect a pattern, upload your file and click import.A “Pattern file” is created, and its job along with it. Depending on the success or failure of the job, you
will receive a red/green notification on your window. You can check the details in the appropriate Import/Export menu.Or:Access the Import wizard through the Import/Export menuSelect a patternClick on the “Import” buttonImport syntaxOne of the strength of pattern_import_export module is the ability to
reference records by natural keys (business keys) instead of technical keys (xmlid or database id).One or more columns can be the natural key of the record to find and update or to create a new record.
Each column in the natural key has to be suffixed by “#key”.One or more columns can be used as foreign keys can be accessed with “|” syntax.  (for instance on partner: country_id|code )ExampleHere is an example of a simple update onproduct.product:
Existing record:id: 10name: “Product 1”default_code: “PRD1”The generated export will look like:idnamedefault_code10Product 1PRD1Updated fileidnamedefault_code10Product 1-bisPRD1BAfter import, our record will have been updated:xml id: “__export__.product1”name: “Product 1-bis”default_code: “PRD1B”Now, let’s update some relational fields. Here is some more of our starting data:seller_ids:id (of the seller_id which is a res.partner): 22name (seller): Partner 1price: 10The generated export should be likeidnamedefault_codeseller_ids|1|idseller_ids|1|price10Product 1PRD12210Let’s say “ref” is a unique-constrained Char field. For the seller, instead of using its id, let’s use its ref.idnamedefault_codeseller_ids|1|ref#keyseller_ids|1|price10Product 1PRD1partner1-ref10So this#keymeans that Odoo should search for ares.partnerwhere the ref matches the cell value.Lets take another example, instead of using the id, we want to use the product’s default_code as key.idnamedefault_code#keyseller_ids|1|ref#keyseller_ids|1|priceProduct 1PRD1partner1-ref10Odoo will search the product with the matchingdefault_codeand update it.TechnicallyAdd a new export formatInherit their.exportsmodel.Add your new file format in the selection fieldexport_format;Implements functions_export_with_record_<format>and_read_import_data_<format>.Please take care of iterators (yield) to avoid loading full file into the system memory.Known issues / RoadmapUnticking the “Use tab” boolean should clear the previously selected tab_filter_idChanging a line’s field should clear the previously selected tab_filter_idBug TrackerBugs are tracked onGitHub 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 welcomedfeedback.Do not contact contributors directly about support or help with technical issues.CreditsAuthorsAkretionContributorsChafique Delli <chafique.delli@akretion.com>Sébastien Beau <sebastien.beau@akretion.com>François Honoré (ACSONE SA/NV) <francois.honore@acsone.eu>Kevin Khao <kevin.khao@akretion.com>Raphaël Reverdy <raphael.reverdy@akretion.com>MaintainersThis module is part of theshopinvader/pattern-import-exportproject on GitHub.You are welcome to contribute.