Skip to content

Commit 7d0eeea

Browse files
bosdbosd
authored andcommitted
feat(transform): Make Processor migration-aware
This commit completes the refactoring to support migration workflows with separate source and destination databases. The `Processor` class in `transform.py` has been updated to correctly handle the new `'config'` key in the `params` dictionary. - The `Processor.__init__` method now accepts and stores a `config_file` argument, which is used as a fallback for backward compatibility. - The `write_to_file` method now checks for a `'config'` key in the parameters for each file it writes. If present, this configuration is used to generate the `odoo-data-flow import` command in the final shell script. This ensures that when a transformation script specifies a destination config, the resulting `load.sh` script will correctly target the destination database, completing the migration-aware workflow.
1 parent f31818b commit 7d0eeea

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/odoo_data_flow/lib/transform.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Processor:
4949
def __init__(
5050
self,
5151
filename: Optional[str] = None,
52+
config_file: Optional[str] = None, # Added for fallback
5253
separator: str = ";",
5354
encoding: str = "utf-8",
5455
header: Optional[list[str]] = None,
@@ -66,6 +67,9 @@ def __init__(
6667
6768
Args:
6869
filename: The path to the source CSV or XML file.
70+
config_file: Path to the Odoo connection configuration file. Used as a
71+
fallback for operations that require a DB connection if
72+
no specific config is provided later.
6973
separator: The column delimiter for CSV files.
7074
encoding: The character encoding of the source file.
7175
header: A list of strings for the header row (for in-memory data).
@@ -74,6 +78,7 @@ def __init__(
7478
**kwargs: Catches other arguments, primarily for XML processing.
7579
"""
7680
self.file_to_write: OrderedDict[str, dict[str, Any]] = OrderedDict()
81+
self.config_file = config_file
7782
self.header: list[str]
7883
self.data: list[list[Any]]
7984

@@ -280,6 +285,9 @@ def write_to_file(
280285
init = not append
281286
for _, info in self.file_to_write.items():
282287
info_copy = info.copy()
288+
# NEW: Use the config from params if available,
289+
# otherwise use the processor's default
290+
info_copy["config"] = info.get("config") or self.config_file
283291
info_copy.update(
284292
{
285293
"model": info.get("model", "auto"),

0 commit comments

Comments
 (0)