From 14666c8c5bfda3aefa57fdc2c53d1c2890b657d0 Mon Sep 17 00:00:00 2001 From: ntsirintanis Date: Mon, 6 Feb 2023 16:34:30 +0100 Subject: [PATCH] [MIG] base_external_system: Migration to 16.0 --- .pre-commit-config.yaml | 2 +- base_external_system/__manifest__.py | 2 +- .../models/external_system.py | 19 ++++++++++++------- .../models/external_system_adapter.py | 15 +++++++++------ base_external_system/tests/common.py | 3 +-- .../odoo/addons/base_external_system | 1 + setup/base_external_system/setup.py | 6 ++++++ 7 files changed, 31 insertions(+), 17 deletions(-) create mode 120000 setup/base_external_system/odoo/addons/base_external_system create mode 100644 setup/base_external_system/setup.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c62ce9e5..4d07ee61 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -101,7 +101,7 @@ repos: - id: pyupgrade args: ["--keep-percent-format"] - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort name: isort except __init__.py diff --git a/base_external_system/__manifest__.py b/base_external_system/__manifest__.py index 90081ec1..b51d6e7c 100644 --- a/base_external_system/__manifest__.py +++ b/base_external_system/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Base External System", "summary": "Data models allowing for connection to external systems.", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Base", "website": "https://github.com/OCA/server-backend", "author": "LasLabs, " "Odoo Community Association (OCA)", diff --git a/base_external_system/models/external_system.py b/base_external_system/models/external_system.py index d0a1b5e1..e2d79435 100644 --- a/base_external_system/models/external_system.py +++ b/base_external_system/models/external_system.py @@ -104,14 +104,19 @@ class ExternalSystem(models.Model): with self.interface.client() as client: yield client - @api.model - def create(self, vals): + @api.model_create_multi + def create(self, vals_list): """Create the interface for the record and assign to ``interface``.""" - record = super(ExternalSystem, self).create(vals) - if not self.env.context.get("no_create_interface"): - interface = self.env[vals["system_type"]].create({"system_id": record.id}) - record.interface = interface - return record + records = self.browse([]) + for vals in vals_list: + record = super(ExternalSystem, self).create(vals) + if not self.env.context.get("no_create_interface"): + interface = self.env[vals["system_type"]].create( + {"system_id": record.id} + ) + record.interface = interface + records += record + return records def action_test_connection(self): """Test the connection to the external system.""" diff --git a/base_external_system/models/external_system_adapter.py b/base_external_system/models/external_system_adapter.py index a1781267..8bf09958 100644 --- a/base_external_system/models/external_system_adapter.py +++ b/base_external_system/models/external_system_adapter.py @@ -65,10 +65,13 @@ class ExternalSystemAdapter(models.AbstractModel): """ raise UserError(_("The connection was a success.")) - @api.model - def create(self, vals): + @api.model_create_multi + def create(self, vals_list): context_self = self.with_context(no_create_interface=True) - vals.update({"system_type": self._name}) - record = super(ExternalSystemAdapter, context_self).create(vals) - record.system_id.interface = record - return record + records = self.browse([]) + for vals in vals_list: + vals.update({"system_type": self._name}) + record = super(ExternalSystemAdapter, context_self).create(vals) + record.system_id.interface = record + records += record + return records diff --git a/base_external_system/tests/common.py b/base_external_system/tests/common.py index e02e6513..e56d2ed8 100644 --- a/base_external_system/tests/common.py +++ b/base_external_system/tests/common.py @@ -2,8 +2,7 @@ # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). from contextlib import contextmanager - -from mock import MagicMock +from unittest.mock import MagicMock from odoo.tests.common import TransactionCase diff --git a/setup/base_external_system/odoo/addons/base_external_system b/setup/base_external_system/odoo/addons/base_external_system new file mode 120000 index 00000000..6740d6a6 --- /dev/null +++ b/setup/base_external_system/odoo/addons/base_external_system @@ -0,0 +1 @@ +../../../../base_external_system \ No newline at end of file diff --git a/setup/base_external_system/setup.py b/setup/base_external_system/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/base_external_system/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)