From b9d7d8da65129d28ffeee3e1d6d0d91dc7199bac Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Thu, 12 Oct 2023 07:12:58 +0300 Subject: [PATCH] wip --- wms_connector/demo/storage_backend.xml | 11 +++++++ wms_connector/models/attachment_queue.py | 1 + .../models/attachment_synchronize_task.py | 1 + wms_connector/models/ir_cron.py | 1 + wms_connector/models/product_product.py | 3 ++ wms_connector/models/stock_picking.py | 2 +- wms_connector/models/stock_warehouse.py | 1 + wms_connector/tests/__init__.py | 5 ++- wms_connector/tests/common.py | 32 +++++++++++++++++++ wms_connector/tests/model.py | 11 +++++++ wms_connector/tests/test_activate_sync.py | 26 +++++++++++++++ wms_connector/tests/test_export.py | 17 ++++++++++ wms_connector/tests/test_import.py | 13 ++++++++ wms_connector/tests/test_sync.py | 18 ----------- 14 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 wms_connector/demo/storage_backend.xml create mode 100644 wms_connector/tests/common.py create mode 100644 wms_connector/tests/model.py create mode 100644 wms_connector/tests/test_activate_sync.py create mode 100644 wms_connector/tests/test_export.py create mode 100644 wms_connector/tests/test_import.py delete mode 100644 wms_connector/tests/test_sync.py diff --git a/wms_connector/demo/storage_backend.xml b/wms_connector/demo/storage_backend.xml new file mode 100644 index 00000000000..265fa10a05f --- /dev/null +++ b/wms_connector/demo/storage_backend.xml @@ -0,0 +1,11 @@ + + + + + + Demo WMS backend + / + + + diff --git a/wms_connector/models/attachment_queue.py b/wms_connector/models/attachment_queue.py index da23d30068a..0e7d53caffa 100644 --- a/wms_connector/models/attachment_queue.py +++ b/wms_connector/models/attachment_queue.py @@ -25,3 +25,4 @@ def _run_wms_reception_confirmed(self): def _run_wms_delivery_confirmed(self): raise NotImplementedError + diff --git a/wms_connector/models/attachment_synchronize_task.py b/wms_connector/models/attachment_synchronize_task.py index 770676f6f66..5dd31cd4793 100644 --- a/wms_connector/models/attachment_synchronize_task.py +++ b/wms_connector/models/attachment_synchronize_task.py @@ -24,3 +24,4 @@ def scheduler_export(self, model, domain=False): ("delivery_confirmed", "Delivery confirmed"), ] ) + diff --git a/wms_connector/models/ir_cron.py b/wms_connector/models/ir_cron.py index 326fc22f307..074d928087f 100644 --- a/wms_connector/models/ir_cron.py +++ b/wms_connector/models/ir_cron.py @@ -14,3 +14,4 @@ class IrCron(models.Model): warehouse_import_confirm_delivery_ids = fields.One2many( "stock.warehouse", "wms_import_confirm_delivery_cron_id" ) + product_sync_ids = fields.One2many("wms.product.sync", "warehouse_id") diff --git a/wms_connector/models/product_product.py b/wms_connector/models/product_product.py index abfe54d72a2..4472fa2987d 100644 --- a/wms_connector/models/product_product.py +++ b/wms_connector/models/product_product.py @@ -6,3 +6,6 @@ class ProductProduct(models.Model): _inherit = "product.product" + + wms_sync_ids = fields.One2many("wms.product.sync", "product_id") + diff --git a/wms_connector/models/stock_picking.py b/wms_connector/models/stock_picking.py index 32bae48ec7d..9978deda6fb 100644 --- a/wms_connector/models/stock_picking.py +++ b/wms_connector/models/stock_picking.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models -from odoo.addons.wms_connector.pydantic_models.stock_picking import StockPickingExporter + class StockPicking(models.Model): diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index 3e09a99f68e..d010052b02e 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -43,6 +43,7 @@ class StockWarehouse(models.Model): required=True, default=lambda r: r.env.ref("wms_connector.default_empty_filter"), ) + wms_product_sync_ids = fields.One2many("product.product", "warehouse_id") def _inverse_active_wms_sync(self): for rec in self: diff --git a/wms_connector/tests/__init__.py b/wms_connector/tests/__init__.py index 5836fbedb70..a2ede84cbe1 100644 --- a/wms_connector/tests/__init__.py +++ b/wms_connector/tests/__init__.py @@ -1 +1,4 @@ -from . import test_sync +from . import test_activate_sync +from . import test_export_records +from . import test_export_file +from . import test_import diff --git a/wms_connector/tests/common.py b/wms_connector/tests/common.py new file mode 100644 index 00000000000..8f247affa93 --- /dev/null +++ b/wms_connector/tests/common.py @@ -0,0 +1,32 @@ +# Copyright 2023 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase +import uuid +from odoo_test_helper import FakeModelLoader + + +class WmsConnectorCommon(TransactionCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.backend = cls.env.ref("wms_connector.demo_wms_backend") + cls.backend.directory_path = str(uuid.uuid1()) + "/" + # cls.loader = FakeModelLoader(cls.env, cls.__module__) + # cls.loader.backup_registry() + # + # from .model import ResUsers + # + # cls.loader.update_registry((AttachmentSynchronizeTask,)) + + def tearDown(self): + super().tearDown() + files = self.backend.list_files("OUT/") + for f in files: + self.backend.delete("OUT/" + f) + + @classmethod + def tearDownClass(cls): + # cls.loader.restore_registry() + super().tearDownClass() diff --git a/wms_connector/tests/model.py b/wms_connector/tests/model.py new file mode 100644 index 00000000000..667eea2e2bc --- /dev/null +++ b/wms_connector/tests/model.py @@ -0,0 +1,11 @@ +# Copyright 2023 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +# class ResUsers(models.Model): +# _inherit = ["res.users", "synchronize.exportable.mixin", "synchronize.importable.mixin"] +# +# def _prepare_export_data(self): +# diff --git a/wms_connector/tests/test_activate_sync.py b/wms_connector/tests/test_activate_sync.py new file mode 100644 index 00000000000..887393d64ff --- /dev/null +++ b/wms_connector/tests/test_activate_sync.py @@ -0,0 +1,26 @@ +# Copyright 2023 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestActivateSync(TransactionCase): + def setUp(self): + super().setUp() + self.warehouse = self.env.ref("stock.warehouse0") + + def test_active_deactivate_wms_sync(self): + self.warehouse.active_wms_sync = True + for field in ( + "wms_export_cron_id", + "wms_import_confirm_reception_cron_id", + "wms_import_confirm_delivery_cron_id", + ): + self.assertTrue(getattr(self, field)) + self.warehouse.active_wms_sync = False + for field in ( + "wms_export_cron_id", + "wms_import_confirm_reception_cron_id", + "wms_import_confirm_delivery_cron_id", + ): + self.assertFalse(getattr(self, field).active) diff --git a/wms_connector/tests/test_export.py b/wms_connector/tests/test_export.py new file mode 100644 index 00000000000..36a7b83fdc1 --- /dev/null +++ b/wms_connector/tests/test_export.py @@ -0,0 +1,17 @@ +# Copyright 2023 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestExportFile(TransactionCase): + + def setUp(self): + super().setUp() + self.warehouse = self.env.ref("stock.warehouse0") + self.warehouse.active_wms_sync = True + + def test_run_export_cron(self): + self.warehouse.wms_export_cron_id.run() + pass + diff --git a/wms_connector/tests/test_import.py b/wms_connector/tests/test_import.py new file mode 100644 index 00000000000..281fe19f7ec --- /dev/null +++ b/wms_connector/tests/test_import.py @@ -0,0 +1,13 @@ +# Copyright 2023 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestImport(TransactionCase): + + def setUp(self): + super().setUp() + + def test_import_file(self): + pass diff --git a/wms_connector/tests/test_sync.py b/wms_connector/tests/test_sync.py deleted file mode 100644 index da2ba5b1766..00000000000 --- a/wms_connector/tests/test_sync.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2023 Akretion -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo.tests.common import TransactionCase - - -class TestSync(TransactionCase): - def setUp(self): - super().setUp() - self.warehouse = self.env.ref("stock.warehouse0") - - def test_generate_task_cron(self): - self.warehouse.active_wms_sync = True - self.assertTrue(self.warehouse.sync_cron_id) - self.assertTrue(self.warehouse.sync_task_id) - self.warehouse.active_wms_sync = False - self.assertFalse(self.warehouse.sync_cron_id.active) - self.assertFalse(self.warehouse.sync_task_id.active)