From 1ceb2407654e6daf8588cf1ee632e3f28dc1cab5 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Thu, 14 Mar 2024 21:32:56 +0200 Subject: [PATCH 1/5] wip --- wms_connector/__manifest__.py | 6 +- wms_connector/demo/fs_storage.xml | 12 -- wms_connector/models/__init__.py | 1 - wms_connector/models/stock_picking.py | 4 +- wms_connector/models/stock_warehouse.py | 4 +- .../models/synchronize_exportable_mixin.py | 104 +----------------- .../models/synchronize_importable_mixin.py | 22 ---- wms_connector/tests/common.py | 47 +------- wms_connector/tests/test_export.py | 16 +-- wms_connector/views/stock_picking.xml | 18 +-- wms_connector/views/wms_product_sync.xml | 8 +- 11 files changed, 37 insertions(+), 205 deletions(-) delete mode 100644 wms_connector/demo/fs_storage.xml delete mode 100644 wms_connector/models/synchronize_importable_mixin.py diff --git a/wms_connector/__manifest__.py b/wms_connector/__manifest__.py index 9e98ded6e9..06397c9411 100644 --- a/wms_connector/__manifest__.py +++ b/wms_connector/__manifest__.py @@ -9,14 +9,12 @@ "license": "AGPL-3", "author": "Akretion,Odoo Community Association (OCA)", "website": "https://github.com/OCA/wms", - "depends": ["stock", "sale", "attachment_synchronize"], + "depends": ["stock", "sale", "attachment_synchronize_record"], "data": [ "security/wms_product_sync.xml", "views/wms_product_sync.xml", "views/stock_picking.xml", "views/stock_warehouse.xml", ], - "demo": [ - "demo/fs_storage.xml", - ], + "demo": [], } diff --git a/wms_connector/demo/fs_storage.xml b/wms_connector/demo/fs_storage.xml deleted file mode 100644 index 55804823e0..0000000000 --- a/wms_connector/demo/fs_storage.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Demo WMS backend - odoofs - demo_wms_storage - - - diff --git a/wms_connector/models/__init__.py b/wms_connector/models/__init__.py index d7bb20402a..b820da3735 100644 --- a/wms_connector/models/__init__.py +++ b/wms_connector/models/__init__.py @@ -1,5 +1,4 @@ from . import attachment_synchronize_task -from . import synchronize_importable_mixin from . import synchronize_exportable_mixin from . import stock_warehouse from . import product_product diff --git a/wms_connector/models/stock_picking.py b/wms_connector/models/stock_picking.py index da0e68e936..5d59d6ad2c 100644 --- a/wms_connector/models/stock_picking.py +++ b/wms_connector/models/stock_picking.py @@ -17,7 +17,7 @@ class StockPicking(models.Model): ) def _get_wms_export_task(self): - return self.picking_type_id.warehouse_id.sudo().wms_export_task_id + return self.picking_type_id.warehouse_id.sudo().export_task_id def _compute_wms_sync_cancel_supported(self): self.wms_sync_cancel_supported = False @@ -41,7 +41,7 @@ def action_cancel(self): for record in self.filtered(lambda p: p.state != "cancel"): if ( not self._context.get("skip_wms_cancel_check") - and record.wms_export_date + and record.export_date and not record.wms_sync_cancel_supported ): raise UserError( diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index e2cbf4e14a..358a9b0c00 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -21,9 +21,9 @@ } FILTER_DOMAINS = { "wms_export_product_filter_id": "[]", - "wms_export_picking_in_filter_id": '[("wms_export_date", "=", False),' + "wms_export_picking_in_filter_id": '[("export_date", "=", False),' ' ("picking_type_id", "=", {}), ("state", "=", "assigned")]', - "wms_export_picking_out_filter_id": '[("wms_export_date", "=", False),' + "wms_export_picking_out_filter_id": '[("export_date", "=", False),' ' ("picking_type_id", "=", {}), ("state", "=", "assigned")]', } diff --git a/wms_connector/models/synchronize_exportable_mixin.py b/wms_connector/models/synchronize_exportable_mixin.py index e7b892af61..ca2e1aed23 100644 --- a/wms_connector/models/synchronize_exportable_mixin.py +++ b/wms_connector/models/synchronize_exportable_mixin.py @@ -1,108 +1,12 @@ # Copyright 2023 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import base64 -import csv -import datetime -from io import StringIO -from odoo import api, fields, models -from odoo.tools import config +from odoo import models class SynchronizeExportableMixin(models.AbstractModel): - _name = "synchronize.exportable.mixin" - _description = "Synchronizable export mixin" + _inherit = "synchronize.exportable.mixin" - wms_export_date = fields.Datetime(readonly=True) - wms_export_attachment_id = fields.Many2one( - "attachment.queue", index=True, readonly=True - ) - wms_export_error = fields.Char(readonly=True, index=True) - - @property - def record_per_file(self): - return 1 - - def button_trigger_export(self): - self.synchronize_export(raise_error=True) - - def _get_export_data(self, raise_error=False): - data = [] - records = self.browse() - sequence = 0 - for rec in self: - try: - with self._cr.savepoint(): - data += rec._prepare_export_data(sequence) - records |= rec - rec.wms_export_error = None - sequence += 1 - except Exception as e: - if raise_error: - raise - if "pdb" in config.get("dev_mode"): - raise - rec.wms_export_error = str(e) - continue - if len(records) >= self.record_per_file: - yield records, data - data = [] - records = self.browse() - sequence = 0 - if len(records): - yield records, data - - def synchronize_export(self, raise_error=False): - attachments = self.env["attachment.queue"] - for records, data in self._get_export_data(raise_error=raise_error): - vals = records._format_to_exportfile(data) - attachment = self.env["attachment.queue"].create(vals) - records.track_export(attachment) - attachments |= attachment - return attachments - - def track_export(self, attachment): - self.wms_export_date = datetime.datetime.now() - self.wms_export_attachment_id = attachment - - def _prepare_export_data(self, idx) -> list: - raise NotImplementedError - - def _get_wms_export_task(self): - raise NotImplementedError - - # TODO cleanup this code - # We should just have a method that return the data - # and a generic one that return the vals - def _format_to_exportfile(self, data): - return self._format_to_exportfile_csv(data) - - def _format_to_exportfile_csv(self, data): - csv_file = StringIO() - delimiter = self.env.context.get("csv_delimiter") or ";" - writer = csv.DictWriter( - csv_file, fieldnames=data[0].keys(), delimiter=delimiter - ) - for row in data: - writer.writerow(row) - csv_file.seek(0) - task = self._get_wms_export_task() - return { - "name": self._get_export_name(), - "datas": base64.b64encode(csv_file.getvalue().encode("utf-8")), - "task_id": task.id, - "file_type": task.file_type, - } - - def _get_export_name(self): - raise NotImplementedError - - @api.model - def _schedule_export(self, warehouse, domain=False): - if not domain: - domain = [] - recs = self.search(domain) - if not recs: - return self.env["attachment.queue"] - return recs.with_context(warehouse=warehouse).synchronize_export() + def _synchronize_context_hook(self, warehouse): + return {"warehouse": warehouse} diff --git a/wms_connector/models/synchronize_importable_mixin.py b/wms_connector/models/synchronize_importable_mixin.py deleted file mode 100644 index 63fd93385b..0000000000 --- a/wms_connector/models/synchronize_importable_mixin.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2023 Akretion -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -import datetime - -from odoo import fields, models - - -class SynchronizeImportableMixin(models.AbstractModel): - _name = "synchronize.importable.mixin" - _description = "Synchronizable import mixin" - - import_date = fields.Date() - import_file_id = fields.Many2one("attachment.queue") - - def track_model_import(self, attachment_queue): - self.write( - { - "import_date": datetime.datetime.now(), - "import_file_id": attachment_queue.id, - } - ) diff --git a/wms_connector/tests/common.py b/wms_connector/tests/common.py index 19d083eadb..6089ea8794 100644 --- a/wms_connector/tests/common.py +++ b/wms_connector/tests/common.py @@ -2,53 +2,18 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import datetime -import uuid -from odoo_test_helper import FakeModelLoader +from odoo.addons.attachment_synchronize_record.tests.common import ( + SynchronizeRecordCommon, +) -from odoo.addons.attachment_synchronize.tests.common import SyncCommon - - -class WmsConnectorCommon(SyncCommon): - # pylint: disable=W8106 - def setUp(self): - super().setUp() +class WmsConnectorCommon(SynchronizeRecordCommon): @classmethod def setUpClass(cls): super().setUpClass() - cls.backend = cls.env.ref("wms_connector.demo_wms_storage") - cls.backend.directory_path = str(uuid.uuid1()) + "/" - cls.aq_before = cls.env["attachment.queue"].search([]) cls.warehouse = cls.env.ref("stock.warehouse0") - def assertNewAttachmentQueue(self, n=1): - aq_after = self.env["attachment.queue"].search([]) - self.assertEqual(len(aq_after - self.aq_before), n) - return aq_after - def setAllExported(self): - self.env["stock.picking"].search([]).wms_export_date = datetime.date.today() - self.env["wms.product.sync"].search([]).wms_export_date = datetime.date.today() - - -class WmsConnectorCase(WmsConnectorCommon): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.loader = FakeModelLoader(cls.env, cls.__module__) - cls.loader.backup_registry() - from .model import StockPicking, WmsProductSync - - cls.loader.update_registry( - ( - WmsProductSync, - StockPicking, - ) - ) - cls.setUpComponent() - - @classmethod - def tearDownClass(cls): - cls.loader.restore_registry() - super().tearDownClass() + self.env["stock.picking"].search([]).export_date = datetime.date.today() + self.env["wms.product.sync"].search([]).export_date = datetime.date.today() diff --git a/wms_connector/tests/test_export.py b/wms_connector/tests/test_export.py index 8b46cf3d6f..6cdda1d1af 100644 --- a/wms_connector/tests/test_export.py +++ b/wms_connector/tests/test_export.py @@ -1,14 +1,14 @@ # Copyright 2023 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from .common import WmsConnectorCase +from .common import WmsConnectorCommon FN_EXPORT_VALS = ( "odoo.addons.wms_connector.tests.model.WmsProductSync._prepare_export_data" ) -class TestExportFile(WmsConnectorCase): +class TestExportFile(WmsConnectorCommon): def setUp(self): super().setUp() self.warehouse.active_wms_sync = True @@ -23,9 +23,9 @@ def test_export_filter(self): prd = self.env["wms.product.sync"].search( [("product_id", "=", self.demo_product.id)] ) - prd.wms_export_date = False + prd.export_date = False self.cron_export_product.method_direct_trigger() - self.assertTrue(prd.wms_export_date) + self.assertTrue(prd.export_date) self.assertNewAttachmentQueue() def test_export_error(self): @@ -33,13 +33,13 @@ def test_export_error(self): self.setAllExported() self.env["wms.product.sync"].search( [("product_id", "=", self.demo_product.id)] - ).wms_export_date = False + ).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.wms_export_error) + self.assertIn("Boom", wms_product.export_error) def test_export_repeat(self): self.warehouse.refresh_wms_products() @@ -56,7 +56,7 @@ def test_export_pickings(self): self.env["stock.picking"] .search( [ - ("wms_export_date", "!=", False), + ("export_date", "!=", False), ("picking_type_id", "=", self.warehouse.in_type_id.id), ] ) @@ -68,7 +68,7 @@ def test_export_pickings(self): self.env["stock.picking"] .search( [ - ("wms_export_date", "!=", False), + ("export_date", "!=", False), ("picking_type_id", "=", self.warehouse.out_type_id.id), ] ) diff --git a/wms_connector/views/stock_picking.xml b/wms_connector/views/stock_picking.xml index 4e2a7e0bf2..780e9e76c5 100644 --- a/wms_connector/views/stock_picking.xml +++ b/wms_connector/views/stock_picking.xml @@ -16,7 +16,7 @@ attrs="{'invisible': [ '|', '|', - ('wms_export_date', '!=', False), + ('export_date', '!=', False), ('is_wms_exportable', '=', False), ('state', 'in', ('cancel', 'done', 'draft')), ]}" @@ -28,7 +28,7 @@ groups="stock.group_stock_manager" attrs="{'invisible': [ '|', - ('wms_export_date', '=', False), + ('export_date', '=', False), ('state', '=', 'cancel'), ]}" confirm="Before cancelling, ensure that your have cancelled the picking in the @@ -37,24 +37,24 @@
@@ -69,7 +69,7 @@
@@ -80,7 +80,7 @@ - + diff --git a/wms_connector/views/wms_product_sync.xml b/wms_connector/views/wms_product_sync.xml index 894db5761d..f25175d715 100644 --- a/wms_connector/views/wms_product_sync.xml +++ b/wms_connector/views/wms_product_sync.xml @@ -18,10 +18,10 @@ - + - + @@ -36,8 +36,8 @@ - - + + From 08f523b3fe8612a89bb1492d47879168a688ed7a Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Fri, 15 Mar 2024 10:23:31 +0200 Subject: [PATCH 2/5] 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) From a8716357e534bb8165d4ad9e3483671f80177dab Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Mon, 18 Mar 2024 14:46:45 +0200 Subject: [PATCH 3/5] wip --- wms_connector/tests/__init__.py | 2 +- wms_connector/tests/common.py | 1 + wms_connector/tests/model.py | 10 ++- wms_connector/tests/test_activate_sync.py | 16 ++-- wms_connector/tests/test_export.py | 102 +++++++++++----------- 5 files changed, 70 insertions(+), 61 deletions(-) diff --git a/wms_connector/tests/__init__.py b/wms_connector/tests/__init__.py index 157d1840fe..9cf8313f9d 100644 --- a/wms_connector/tests/__init__.py +++ b/wms_connector/tests/__init__.py @@ -1,2 +1,2 @@ -# from . import test_activate_sync +from . import test_activate_sync from . import test_export diff --git a/wms_connector/tests/common.py b/wms_connector/tests/common.py index bb080fe02e..b58d7d3149 100644 --- a/wms_connector/tests/common.py +++ b/wms_connector/tests/common.py @@ -19,6 +19,7 @@ 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() + self.env["wms.product.sync"].search([]).to_export = False class WmsConnectorCase(WmsConnectorCommon): diff --git a/wms_connector/tests/model.py b/wms_connector/tests/model.py index 5927d349c7..a4f7c7e982 100644 --- a/wms_connector/tests/model.py +++ b/wms_connector/tests/model.py @@ -7,7 +7,7 @@ class WmsProductSync(models.Model): _inherit = ["wms.product.sync"] - def _prepare_export_data(self): + def _prepare_export_data(self, _): res = [] for rec in self: res += [ @@ -20,11 +20,14 @@ def _prepare_export_data(self): def _get_export_name(self): return self.name + def _get_export_task(self): + return self.warehouse_id.wms_export_task_id + class StockPicking(models.Model): _inherit = "stock.picking" - def _prepare_export_data(self): + def _prepare_export_data(self, _): return [ { "name": rec.name, @@ -34,3 +37,6 @@ def _prepare_export_data(self): def _get_export_name(self): return self.name + + def _get_export_task(self): + return self.location_id.warehouse_id.wms_export_task_id diff --git a/wms_connector/tests/test_activate_sync.py b/wms_connector/tests/test_activate_sync.py index 677c0bf4e5..ed7208b5cf 100644 --- a/wms_connector/tests/test_activate_sync.py +++ b/wms_connector/tests/test_activate_sync.py @@ -1,10 +1,10 @@ # Copyright 2023 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo.tests.common import SavepointCase +from odoo.tests.common import TransactionCase -class TestActivateSync(SavepointCase): +class TestActivateSync(TransactionCase): def setUp(self): super().setUp() self.warehouse = self.env.ref("stock.warehouse0") @@ -12,16 +12,16 @@ def setUp(self): 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", + "wms_export_product_cron_id", + "wms_export_picking_in_cron_id", + "wms_export_picking_out_cron_id", ): self.assertTrue(getattr(self.warehouse, 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", + "wms_export_product_cron_id", + "wms_export_picking_in_cron_id", + "wms_export_picking_out_cron_id", ): self.assertFalse(getattr(self.warehouse, field).active) diff --git a/wms_connector/tests/test_export.py b/wms_connector/tests/test_export.py index f152b3f3f4..e82423402e 100644 --- a/wms_connector/tests/test_export.py +++ b/wms_connector/tests/test_export.py @@ -1,17 +1,18 @@ # Copyright 2023 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from .common import WmsConnectorCommon +from .common import WmsConnectorCase FN_EXPORT_VALS = ( "odoo.addons.wms_connector.tests.model.WmsProductSync._prepare_export_data" ) -class TestExportFile(WmsConnectorCommon): +class TestExportFile(WmsConnectorCase): def setUp(self): super().setUp() self.warehouse.active_wms_sync = True + self.warehouse.wms_export_task_id.backend_id = self.backend self.cron_export_product = self.warehouse.wms_export_product_cron_id self.cron_export_picking_in = self.warehouse.wms_export_picking_in_cron_id self.cron_export_picking_out = self.warehouse.wms_export_picking_out_cron_id @@ -23,55 +24,56 @@ def test_export_filter(self): prd = self.env["wms.product.sync"].search( [("product_id", "=", self.demo_product.id)] ) - prd.export_date = False + prd.to_export = True self.cron_export_product.method_direct_trigger() 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)] + ).to_export = True + 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.setAllExported() + self.env["stock.picking"].search( + [ + ("picking_type_id", "=", self.warehouse.in_type_id.id), + ] + )[0:2].export_date = False + 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(2) + self.env["stock.picking"].search( + [ + ("picking_type_id", "=", self.warehouse.out_type_id.id), + ] + )[0:2].export_date = False + self.cron_export_picking_out.method_direct_trigger() + self.assertNewAttachmentQueue(4) From 07863b3dcd770fa54fb5c6844887128658d2c778 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Wed, 14 Aug 2024 10:18:21 +0300 Subject: [PATCH 4/5] FIX naming of _get_export_task --- wms_connector/models/stock_picking.py | 2 +- wms_connector/models/wms_product_sync.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wms_connector/models/stock_picking.py b/wms_connector/models/stock_picking.py index 5d59d6ad2c..f831e316f1 100644 --- a/wms_connector/models/stock_picking.py +++ b/wms_connector/models/stock_picking.py @@ -16,7 +16,7 @@ class StockPicking(models.Model): compute="_compute_wms_sync_cancel_supported" ) - def _get_wms_export_task(self): + def _get_export_task(self): return self.picking_type_id.warehouse_id.sudo().export_task_id def _compute_wms_sync_cancel_supported(self): diff --git a/wms_connector/models/wms_product_sync.py b/wms_connector/models/wms_product_sync.py index 83d27a27ca..f299331362 100644 --- a/wms_connector/models/wms_product_sync.py +++ b/wms_connector/models/wms_product_sync.py @@ -32,5 +32,5 @@ def track_export(self, attachment): super().track_export(attachment) self.to_export = False - def _get_wms_export_task(self): + def _get_export_task(self): return self.warehouse_id.sudo().wms_export_task_id From b5dee4e249a8a17cfba9db024c1147c2c55bcf0d Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Wed, 14 Aug 2024 10:38:34 +0300 Subject: [PATCH 5/5] FIX field name --- wms_connector/models/stock_picking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wms_connector/models/stock_picking.py b/wms_connector/models/stock_picking.py index f831e316f1..13ad89f9df 100644 --- a/wms_connector/models/stock_picking.py +++ b/wms_connector/models/stock_picking.py @@ -17,7 +17,7 @@ class StockPicking(models.Model): ) def _get_export_task(self): - return self.picking_type_id.warehouse_id.sudo().export_task_id + return self.picking_type_id.warehouse_id.sudo().wms_export_task_id def _compute_wms_sync_cancel_supported(self): self.wms_sync_cancel_supported = False