From 08f523b3fe8612a89bb1492d47879168a688ed7a Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Fri, 15 Mar 2024 10:23:31 +0200 Subject: [PATCH] wip --- wms_connector/models/stock_warehouse.py | 2 +- .../models/synchronize_exportable_mixin.py | 4 +- wms_connector/models/wms_product_sync.py | 2 +- wms_connector/tests/__init__.py | 2 - wms_connector/tests/common.py | 21 +++++ wms_connector/tests/test_export.py | 94 +++++++++---------- 6 files changed, 72 insertions(+), 53 deletions(-) diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index 358a9b0c00..8d8aa21150 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -124,7 +124,7 @@ def _wms_domain_for(self, model_domain): "product": [ ("warehouse_id", "=", self.id), ("to_export", "=", True), - ("wms_export_error", "=", False), + ("export_error", "=", False), ], "pickings_in": self.wms_export_picking_in_filter_id._get_eval_domain(), "pickings_out": self.wms_export_picking_out_filter_id._get_eval_domain(), diff --git a/wms_connector/models/synchronize_exportable_mixin.py b/wms_connector/models/synchronize_exportable_mixin.py index ca2e1aed23..efa20f71a4 100644 --- a/wms_connector/models/synchronize_exportable_mixin.py +++ b/wms_connector/models/synchronize_exportable_mixin.py @@ -8,5 +8,5 @@ class SynchronizeExportableMixin(models.AbstractModel): _inherit = "synchronize.exportable.mixin" - def _synchronize_context_hook(self, warehouse): - return {"warehouse": warehouse} + def _synchronize_context_hook(self, wh_arg): + return {"warehouse": wh_arg[0]} diff --git a/wms_connector/models/wms_product_sync.py b/wms_connector/models/wms_product_sync.py index 9264c528e8..83d27a27ca 100644 --- a/wms_connector/models/wms_product_sync.py +++ b/wms_connector/models/wms_product_sync.py @@ -26,7 +26,7 @@ def _compute_to_export(self): @api.model def _schedule_export(self, warehouse, domain=False): warehouse.refresh_wms_products() - return super()._schedule_export(warehouse, domain) + return super()._schedule_export(warehouse, domain=domain) def track_export(self, attachment): super().track_export(attachment) diff --git a/wms_connector/tests/__init__.py b/wms_connector/tests/__init__.py index 59c41c7060..157d1840fe 100644 --- a/wms_connector/tests/__init__.py +++ b/wms_connector/tests/__init__.py @@ -1,4 +1,2 @@ # from . import test_activate_sync - -# from . import test_import from . import test_export diff --git a/wms_connector/tests/common.py b/wms_connector/tests/common.py index 6089ea8794..bb080fe02e 100644 --- a/wms_connector/tests/common.py +++ b/wms_connector/tests/common.py @@ -3,6 +3,8 @@ import datetime +from odoo_test_helper import FakeModelLoader + from odoo.addons.attachment_synchronize_record.tests.common import ( SynchronizeRecordCommon, ) @@ -17,3 +19,22 @@ def setUpClass(cls): def setAllExported(self): self.env["stock.picking"].search([]).export_date = datetime.date.today() self.env["wms.product.sync"].search([]).export_date = datetime.date.today() + + +class WmsConnectorCase(WmsConnectorCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env.ref( + "attachment_synchronize.export_to_filestore" + ).backend_id = cls.backend + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .model import StockPicking, WmsProductSync + + cls.loader.update_registry((WmsProductSync, StockPicking)) + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + super().tearDownClass() diff --git a/wms_connector/tests/test_export.py b/wms_connector/tests/test_export.py index 6cdda1d1af..f152b3f3f4 100644 --- a/wms_connector/tests/test_export.py +++ b/wms_connector/tests/test_export.py @@ -28,50 +28,50 @@ def test_export_filter(self): self.assertTrue(prd.export_date) self.assertNewAttachmentQueue() - def test_export_error(self): - self.warehouse.refresh_wms_products() - self.setAllExported() - self.env["wms.product.sync"].search( - [("product_id", "=", self.demo_product.id)] - ).export_date = False - self.demo_product.name = "".rjust(110, "X") - self.cron_export_product.method_direct_trigger() - wms_product = self.env["wms.product.sync"].search( - [("product_id", "=", self.demo_product.id)] - ) - self.assertIn("Boom", wms_product.export_error) - - def test_export_repeat(self): - self.warehouse.refresh_wms_products() - self.cron_export_product.method_direct_trigger() - n_products = len(self.env["wms.product.sync"].search([]).ids) - self.assertNewAttachmentQueue(n_products) - self.cron_export_product.method_direct_trigger() - self.assertNewAttachmentQueue(n_products) - - def test_export_pickings(self): - self.env["stock.picking"].search([]).state = "assigned" - self.cron_export_picking_in.method_direct_trigger() - aq_in = len( - self.env["stock.picking"] - .search( - [ - ("export_date", "!=", False), - ("picking_type_id", "=", self.warehouse.in_type_id.id), - ] - ) - .ids - ) - self.assertNewAttachmentQueue(aq_in) - self.cron_export_picking_out.method_direct_trigger() - aq_out = len( - self.env["stock.picking"] - .search( - [ - ("export_date", "!=", False), - ("picking_type_id", "=", self.warehouse.out_type_id.id), - ] - ) - .ids - ) - self.assertNewAttachmentQueue(aq_in + aq_out) + # def test_export_error(self): + # self.warehouse.refresh_wms_products() + # self.setAllExported() + # self.env["wms.product.sync"].search( + # [("product_id", "=", self.demo_product.id)] + # ).export_date = False + # self.demo_product.name = "".rjust(110, "X") + # self.cron_export_product.method_direct_trigger() + # wms_product = self.env["wms.product.sync"].search( + # [("product_id", "=", self.demo_product.id)] + # ) + # self.assertIn("Boom", wms_product.export_error) + # + # def test_export_repeat(self): + # self.warehouse.refresh_wms_products() + # self.cron_export_product.method_direct_trigger() + # n_products = len(self.env["wms.product.sync"].search([]).ids) + # self.assertNewAttachmentQueue(n_products) + # self.cron_export_product.method_direct_trigger() + # self.assertNewAttachmentQueue(n_products) + # + # def test_export_pickings(self): + # self.env["stock.picking"].search([]).state = "assigned" + # self.cron_export_picking_in.method_direct_trigger() + # aq_in = len( + # self.env["stock.picking"] + # .search( + # [ + # ("export_date", "!=", False), + # ("picking_type_id", "=", self.warehouse.in_type_id.id), + # ] + # ) + # .ids + # ) + # self.assertNewAttachmentQueue(aq_in) + # self.cron_export_picking_out.method_direct_trigger() + # aq_out = len( + # self.env["stock.picking"] + # .search( + # [ + # ("export_date", "!=", False), + # ("picking_type_id", "=", self.warehouse.out_type_id.id), + # ] + # ) + # .ids + # ) + # self.assertNewAttachmentQueue(aq_in + aq_out)