Skip to content

Commit

Permalink
[15.0] connector-interfaces: remove settings, fix test cases bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 committed Oct 30, 2023
1 parent e452bd1 commit f1be8b8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 45 deletions.
45 changes: 3 additions & 42 deletions connector_importer/models/import_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ class ImportType(models.Model):
description = fields.Text()
key = fields.Char(required=True, help="Unique mnemonic identifier", copy=False)
options = fields.Text(help="YAML configuration")
settings = fields.Text(
string="Legacy Settings",
required=False,
help="""
# comment me
product.template::template.importer.component.name
product.product::product.importer.component.name
# another one
product.supplierinfo::supplierinfo.importer.component.name
""",
)
use_job = fields.Boolean(
help=(
"For each importer used in the settings, one job will be spawned. "
Expand All @@ -96,7 +85,7 @@ class ImportType(models.Model):
def _check_options(self):
no_options = self.browse()
for rec in self:
if not rec.options and not rec.settings:
if not rec.options:
no_options.append(rec)
# TODO: validate yaml schema (maybe w/ Cerberus?)
if no_options:
Expand All @@ -107,14 +96,11 @@ def _check_options(self):
)

def _load_options(self):
return yaml.safe_load(self.options or "") or []
return yaml.safe_load(self.options or "")

def available_importers(self):
self.ensure_one()
if self.settings:
for item in self._legacy_available_importers():
yield item
options = self._load_options()
options = self._load_options() and [self._load_options()] or []
for line in options:
is_last_importer = False
if line == options[-1]:
Expand Down Expand Up @@ -143,31 +129,6 @@ def _make_importer_info(self, line, is_last_importer=True):
},
}

# TODO: trash it for v14
def _legacy_available_importers(self):
for item in self.available_models():
yield self._make_importer_info(
{"model": item[0], "importer": item[1]}, is_last_importer=item[2]
)

def available_models(self):
"""Retrieve available import models and their importers.
Parse `settings` and yield a tuple
`(model, importer, is_last_importer)`.
"""
_logger.warning("DEPRECATED legacy settings: move to JSON settings.")
self.ensure_one()
lines = self.settings.strip().splitlines()
for _line in lines:
line = _line.strip()
if line and not line.startswith("#"):
model_name, importer = line.split("::")
is_last_importer = False
if _line == lines[-1]:
is_last_importer = True
yield (model_name.strip(), importer.strip(), is_last_importer)

def copy_data(self, default=None):
res = super().copy_data(default)
for data, rec in zip(res, self):
Expand Down
3 changes: 2 additions & 1 deletion connector_importer/tests/test_event_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import mock
from unittest import mock

from odoo_test_helper import FakeModelLoader

from odoo.tools import mute_logger
Expand Down
2 changes: 1 addition & 1 deletion connector_importer/tests/test_recordset_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import mock
from unittest import mock

from odoo.tools import mute_logger

Expand Down
3 changes: 2 additions & 1 deletion connector_importer/tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


import mock
from unittest import mock

from odoo_test_helper import FakeModelLoader

from .common import BaseTestCase
Expand Down

0 comments on commit f1be8b8

Please sign in to comment.