Skip to content

Commit 8e26a40

Browse files
bosdbosd
authored andcommitted
📝(importing): Document migration-aware Processor workflow
Updates the `importing_data.md` guide to reflect the new functionality for handling data migrations between separate source and destination databases. The documentation now explains: - The new optional `config_file` parameter in the `Processor` constructor, which is used for reading metadata from a source database. - The new `'config'` key in the `params` dictionary of the `process()` method, which is used to specify the destination database for the generated import script. - A new "Full Example for a Data Migration" section has been added to clearly demonstrate the recommended workflow. This ensures that users can correctly leverage the new migration-aware features of the library.
1 parent 7d0eeea commit 8e26a40

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

docs/guides/importing_data.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ processor = Processor(
139139
The constructor takes the following arguments:
140140

141141
* **`filename` (str)**: The path to the CSV or XML file you want to transform.
142+
* **`config_file` (str, optional)**: Path to the Odoo connection configuration file. This is used for operations that need to read metadata from the source database (e.g., when using `--verify-fields`).
142143
* **`separator` (str, optional)**: The column separator for CSV files. Defaults to `;`.
143144
* **`preprocess` (function, optional)**: A function to modify the raw data _before_ mapping begins. See the [Data Transformations Guide](./data_transformations.md) for details.
144145
* **`xml_root_tag` (str, optional)**: Required argument for processing XML files. See the [Advanced usage Guide](./advanced_usage.md) for details.
@@ -199,6 +200,7 @@ The `params` dictionary allows you to control the behavior of the import client
199200

200201
| `params` Key | `odoo-data-flow import` Option | Description |
201202
| ------------ | ------------------------------ | ----------------------------------------------------------------------------------------------------------------- |
203+
| `config` | `--config` | **For Migrations**. Path to the destination config file. Overrides the `config_file` from the Processor for the final import script. |
202204
| `model` | `--model` | **Optional**. The technical name of the Odoo model (e.g., `sale.order`). If you omit this, the tool infers it from the filename. |
203205
| `context` | `--context` | An Odoo context dictionary string. Essential for disabling mail threads, etc. (e.g., `"{'tracking_disable': True}"`) |
204206
| `worker` | `--worker` | The number of parallel processes to use for the import. |
@@ -216,14 +218,15 @@ processor.write_to_file("load_my_data.sh")
216218

217219
This method takes a single argument: the path where the `load.sh` script should be saved. It automatically uses the `filename_out` and `params` you provided to the `process()` method to construct the correct commands.
218220

219-
## Full Example
221+
## Full Example for a Data Migration
220222

221223
Here is a complete `transform.py` script that ties everything together.
222224

223225
```{code-block} python
224226
:caption: transform.py
225227
from odoo_data_flow.lib.transform import Processor
226228
from odoo_data_flow.lib import mapper
229+
from files import * # Imports source_config_file and destination_config_file
227230
228231
# 1. Define the mapping rules
229232
sales_order_mapping = {
@@ -234,15 +237,21 @@ sales_order_mapping = {
234237
}
235238
236239
# 2. Define the parameters for the load script
240+
# Note that we specify the destination config file here.
237241
import_params = {
238242
'model': 'sale.order',
243+
'config': destination_config_file, # <-- USES DESTINATION CONFIG
239244
'context': "{'tracking_disable': True, 'mail_notrack': True}",
240245
'worker': 4,
241246
'size': 500
242247
}
243248
244-
# 3. Initialize the processor
245-
processor = Processor('origin/sales_orders.csv', separator=',')
249+
# 3. Initialize the processor using the SOURCE config file
250+
processor = Processor(
251+
filename=src_sales_orders.csv,
252+
config_file=source_config_file, # <-- USES SOURCE CONFIG
253+
separator=','
254+
)
246255
247256
# 4. Run the transformation
248257
processor.process(
@@ -251,7 +260,7 @@ processor.process(
251260
params=import_params
252261
)
253262
254-
# 5. Generate the final script
263+
# 5. Generate the final script. This will now use the destination config.
255264
processor.write_to_file("load_sales_orders.sh")
256265
257266
print("Transformation complete.")

0 commit comments

Comments
 (0)