Pattern for import or export
Project description
Overview
This 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.
Features
Key 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 ID
One2many and Many2many support: create or update for example invoice lines with a syntax that is very readable and easy to update
As 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 export
Table of contents
Configuration
Install another module that supports a specific file type
Use the Patterns menu to configure your import/export formats
Usage
Configuring a pattern
First you have to define a pattern:
Go on the Import/Export->Patterns menu
Create your pattern with fields to export
You can refer to the examples in demo data.
Exporting
Open the tree view of any model and tick some record selection boxes.
In the sidebar, click on the “Export with Pattern” button
Select 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.
Importing
You 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” button
Select the pattern that you used to generate the export, 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 menu
Select the Pattern that you want to use
Click on the “Import” button
Example
Here is an example of a simple update on product.product: Existing record:
id: 10
name: “Product 1”
default_code: “PRD1”
The generated export will look like:
id |
name |
default_code |
---|---|---|
10 |
Product 1 |
PRD1 |
Updated file
id |
name |
default_code |
---|---|---|
10 |
Product 1-bis |
PRD1B |
After 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): 22
name (seller): Partner 1
price: 10
The generated export should be like
id |
name |
default_code |
seller_ids|1|id |
seller_ids|1|price |
---|---|---|---|---|
10 |
Product 1 |
PRD1 |
22 |
10 |
Let’s say “ref” is a unique-constrained Char field. For the seller, instead of using its id, let’s use its ref.
id |
name |
default_code |
seller_ids|1|ref#key |
seller_ids|1|price |
---|---|---|---|---|
10 |
Product 1 |
PRD1 |
partner1-ref |
10 |
So this #key means that Odoo should search for a res.partner where 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.
id |
name |
default_code#key |
seller_ids|1|ref#key |
seller_ids|1|price |
---|---|---|---|---|
Product 1 |
PRD1 |
partner1-ref |
10 |
Odoo will search the product with the matching default_code and update it.
Technically
Add a new export format
Inherit the ir.exports model.
Add your new file format in the selection field export_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 / Roadmap
Unticking the “Use tab” boolean should clear the previously selected tab_filter_id
Changing a line’s field should clear the previously selected tab_filter_id
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 smashing it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
Credits
Contributors
Chafique 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>
Maintainers
This module is part of the shopinvader/pattern-import-export project on GitHub.
You are welcome to contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file odoo12_addon_pattern_import_export-12.0.6.2.0-py3-none-any.whl
.
File metadata
- Download URL: odoo12_addon_pattern_import_export-12.0.6.2.0-py3-none-any.whl
- Upload date:
- Size: 54.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 533a7d265a679ea6851682da35b97825cfc4d8bd8f968c7fe687456a9b89a0a7 |
|
MD5 | 840c09ca36fdf00343563d157f3b317a |
|
BLAKE2b-256 | 9b6985695c1590e2de348770d1cee813ad2efa8f456a6dd8192b272661cc6b3a |