Skip to content

Commit 4a1d388

Browse files
committed
[FIX] cetmix_tower_yaml
- Prevent recursive reference loops during export - Add the reference mixin to cx_tower_scheduled_task_cv - Add cx_tower_scheduled_task_cv to init
1 parent 2e7a447 commit 4a1d388

11 files changed

Lines changed: 1093 additions & 93 deletions

cetmix_tower_yaml/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from . import cx_tower_server_log
1616
from . import cx_tower_shortcut
1717
from . import cx_tower_scheduled_task
18+
from . import cx_tower_scheduled_task_cv
1819
from . import cx_tower_file
1920
from . import cx_tower_server
2021
from . import cx_tower_yaml_manifest_template

cetmix_tower_yaml/models/cx_tower_command.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ def _get_fields_for_yaml(self):
3333
"secret_ids",
3434
]
3535
return res
36+
37+
def _get_deferred_m2o_import_fields(self):
38+
"""Return m2o command fields resolved after the main import pass."""
39+
return {
40+
"jet_template_id": "cx.tower.jet.template",
41+
"jet_action_id": "cx.tower.jet.action",
42+
"waypoint_template_id": "cx.tower.jet.waypoint.template",
43+
}

cetmix_tower_yaml/models/cx_tower_jet_template.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ def _get_fields_for_yaml(self):
3030
"scheduled_task_ids",
3131
]
3232
return res
33+
34+
def _get_deferred_x2m_import_fields(self):
35+
"""Return x2m child records resolved after the main import pass."""
36+
return {
37+
"template_requires_ids": {
38+
"child_model": "cx.tower.jet.template.dependency",
39+
"deferred_field": "template_required_id",
40+
"target_model": "cx.tower.jet.template",
41+
}
42+
}

cetmix_tower_yaml/models/cx_tower_jet_waypoint_template.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ def _get_fields_for_yaml(self):
1616
"name",
1717
"sequence",
1818
"access_level",
19+
"jet_template_id",
1920
"plan_create_id",
2021
"plan_arrive_id",
2122
"plan_leave_id",
2223
"plan_delete_id",
2324
"note",
2425
]
2526
return res
27+
28+
def _get_deferred_m2o_import_fields(self):
29+
"""Return m2o waypoint-template fields resolved after import."""
30+
return {
31+
"jet_template_id": "cx.tower.jet.template",
32+
}

cetmix_tower_yaml/models/cx_tower_plan.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ def _get_fields_for_yaml(self):
2121
"line_ids",
2222
]
2323
return res
24+
25+
def _get_deferred_x2m_import_fields(self):
26+
"""Defer plan lines whose command is not resolvable during nested import.
27+
28+
Deep YAML (e.g. a command's waypoint inlines a jet template whose plans
29+
reference that same command) creates a forward reference: plan lines are
30+
prepared before the command exists in the database. Queue those lines
31+
and create them after the main import pass when ``command_id`` can be
32+
resolved.
33+
"""
34+
return {
35+
"line_ids": {
36+
"child_model": "cx.tower.plan.line",
37+
"deferred_field": "command_id",
38+
"target_model": "cx.tower.command",
39+
}
40+
}

cetmix_tower_yaml/models/cx_tower_scheduled_task.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ def _get_fields_for_yaml(self):
2929
"custom_variable_value_ids",
3030
]
3131
return res
32+
33+
def _get_deferred_x2m_import_fields(self):
34+
"""Return scheduled-task child records resolved after import."""
35+
return {
36+
"custom_variable_value_ids": {
37+
"child_model": "cx.tower.scheduled.task.cv",
38+
"deferred_field": "variable_value_id",
39+
"target_model": "cx.tower.variable.value",
40+
"skip_empty": True,
41+
}
42+
}

cetmix_tower_yaml/models/cx_tower_scheduled_task_cv.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,32 @@
55

66
class CxTowerScheduledTaskCv(models.Model):
77
_name = "cx.tower.scheduled.task.cv"
8-
_inherit = ["cx.tower.scheduled.task.cv", "cx.tower.yaml.mixin"]
8+
_inherit = [
9+
"cx.tower.scheduled.task.cv",
10+
"cx.tower.yaml.mixin",
11+
"cx.tower.reference.mixin",
12+
]
913

1014
def _get_fields_for_yaml(self):
1115
res = super()._get_fields_for_yaml()
1216
res += ["variable_value_id"]
1317
return res
18+
19+
def _post_process_yaml_dict_values(self, values):
20+
"""Populate required child fields from the linked variable value."""
21+
res = super()._post_process_yaml_dict_values(values)
22+
variable_value_id = res.get("variable_value_id")
23+
if variable_value_id:
24+
variable_value = self.env["cx.tower.variable.value"].browse(
25+
variable_value_id
26+
)
27+
if variable_value.exists():
28+
res.update(
29+
{
30+
"name": variable_value.name,
31+
"variable_id": variable_value.variable_id.id,
32+
"option_id": variable_value.option_id.id or False,
33+
"value_char": variable_value.value_char,
34+
}
35+
)
36+
return res

0 commit comments

Comments
 (0)