From 6e7359902573c23fbd09a6026391a75656a71a7e Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Thu, 12 Oct 2023 16:21:09 +0300 Subject: [PATCH] wip --- wms_connector/__manifest__.py | 2 +- wms_connector/data/cron.xml | 10 ++++++++-- wms_connector/models/attachment_queue.py | 1 - wms_connector/models/attachment_synchronize_task.py | 1 - wms_connector/models/product_product.py | 1 - wms_connector/models/stock_picking.py | 4 ---- wms_connector/models/stock_warehouse.py | 13 ++++++++++--- .../models/synchronize_exportable_mixin.py | 3 +++ wms_connector/models/wms_product_sync.py | 6 +++--- wms_connector/tests/common.py | 8 +++++++- wms_connector/tests/test_export.py | 5 +---- wms_connector/tests/test_import.py | 1 - 12 files changed, 33 insertions(+), 22 deletions(-) diff --git a/wms_connector/__manifest__.py b/wms_connector/__manifest__.py index 1e8f5a38227..f61f820fa16 100644 --- a/wms_connector/__manifest__.py +++ b/wms_connector/__manifest__.py @@ -9,7 +9,7 @@ "license": "AGPL-3", "author": "Akretion,Odoo Community Association (OCA)", "website": "https://www.akretion.com", - "depends": ["stock", "sale", "attachment_synchronize", "pydantic", "extendable"], + "depends": ["stock", "sale", "attachment_synchronize"], "data": [ "security/wms_product_sync.xml", "views/wms_product_sync.xml", diff --git a/wms_connector/data/cron.xml b/wms_connector/data/cron.xml index a62f50ba2e1..ba0f9844551 100644 --- a/wms_connector/data/cron.xml +++ b/wms_connector/data/cron.xml @@ -4,8 +4,14 @@ - - WMS: Errors email alert + + WMS: refresh products + + 1 + days + -1 + code + env["stock.warehouse"].search([("active_wms_sync", "=", True)]).refresh_wms_products() diff --git a/wms_connector/models/attachment_queue.py b/wms_connector/models/attachment_queue.py index 0e7d53caffa..da23d30068a 100644 --- a/wms_connector/models/attachment_queue.py +++ b/wms_connector/models/attachment_queue.py @@ -25,4 +25,3 @@ 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 5dd31cd4793..770676f6f66 100644 --- a/wms_connector/models/attachment_synchronize_task.py +++ b/wms_connector/models/attachment_synchronize_task.py @@ -24,4 +24,3 @@ def scheduler_export(self, model, domain=False): ("delivery_confirmed", "Delivery confirmed"), ] ) - diff --git a/wms_connector/models/product_product.py b/wms_connector/models/product_product.py index 4472fa2987d..134995185d8 100644 --- a/wms_connector/models/product_product.py +++ b/wms_connector/models/product_product.py @@ -8,4 +8,3 @@ 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 9978deda6fb..cf3a791d396 100644 --- a/wms_connector/models/stock_picking.py +++ b/wms_connector/models/stock_picking.py @@ -4,13 +4,9 @@ from odoo import _, api, fields, models - class StockPicking(models.Model): _inherit = ["stock.picking", "synchronize.exportable.mixin"] - def button_create_aq(self): - self.synchronize_export() - def _get_export_name(self): if self.file_creation_mode == "per_record": return self.name + ".csv" diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index d010052b02e..f0290d5105a 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -30,17 +30,14 @@ class StockWarehouse(models.Model): wms_import_confirm_delivery_cron_id = fields.Many2one("ir.cron", readonly=True) wms_product_filter_id = fields.Many2one( "ir.filters", - required=True, default=lambda r: r.env.ref("wms_connector.default_empty_filter"), ) wms_picking_ar_filter_id = fields.Many2one( "ir.filters", - required=True, default=lambda r: r.env.ref("wms_connector.default_empty_filter"), ) wms_picking_prp_filter_id = fields.Many2one( "ir.filters", - required=True, default=lambda r: r.env.ref("wms_connector.default_empty_filter"), ) wms_product_sync_ids = fields.One2many("product.product", "warehouse_id") @@ -104,3 +101,13 @@ def _deactivate_crons_tasks(self): def action_open_flows(self): raise NotImplementedError return {"type": "ir.action"} + + def refresh_wms_products(self): + for rec in self: + rec.wms_product_sync_ids.unlink() + for prd in self.env["product.product"].search( + rec.wms_product_filter_id._get_eval_domain() + ): + self.env["wms.product.sync"].create( + {"product_id": prd.id, "warehouse_id": rec.id} + ) diff --git a/wms_connector/models/synchronize_exportable_mixin.py b/wms_connector/models/synchronize_exportable_mixin.py index 0832da53335..24612810ab7 100644 --- a/wms_connector/models/synchronize_exportable_mixin.py +++ b/wms_connector/models/synchronize_exportable_mixin.py @@ -21,6 +21,9 @@ class SynchronizeExportableMixin(models.AbstractModel): default="per_record", ) + def button_trigger_export(self): + self.synchronize_export() + def synchronize_export(self): if self.file_creation_mode == "per_record": res = self.env["attachment.queue"] diff --git a/wms_connector/models/wms_product_sync.py b/wms_connector/models/wms_product_sync.py index e09efe7013f..56b3c45bc1b 100644 --- a/wms_connector/models/wms_product_sync.py +++ b/wms_connector/models/wms_product_sync.py @@ -9,6 +9,6 @@ class WmsProductSync(models.Model): _name = "wms.product.sync" _description = "Wms Product Sync" - name = fields.Char() - product_id = fields.Many2one("product.product") - warehouse_id = fields.Many2one("stock.warehouse") + name = fields.Char(related="product_id.name") + product_id = fields.Many2one("product.product", required=True) + warehouse_id = fields.Many2one("stock.warehouse", required=True) diff --git a/wms_connector/tests/common.py b/wms_connector/tests/common.py index 8f247affa93..6bb28bcec31 100644 --- a/wms_connector/tests/common.py +++ b/wms_connector/tests/common.py @@ -7,12 +7,12 @@ 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.aq_before = cls.env["attachment.queue"].search([]) # cls.loader = FakeModelLoader(cls.env, cls.__module__) # cls.loader.backup_registry() # @@ -30,3 +30,9 @@ def tearDown(self): def tearDownClass(cls): # cls.loader.restore_registry() super().tearDownClass() + + @classmethod + def assertNewAttachmentQueue(cls): + aq_after = cls.env["attachment.queue"].search([]) + cls.assertEqual(len(aq_after - cls.aq_before), 1) + return aq_after diff --git a/wms_connector/tests/test_export.py b/wms_connector/tests/test_export.py index 36a7b83fdc1..42a0a89971c 100644 --- a/wms_connector/tests/test_export.py +++ b/wms_connector/tests/test_export.py @@ -5,13 +5,10 @@ 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 - + self.warehouse.wms_export_cron_id.method_direct_trigger() diff --git a/wms_connector/tests/test_import.py b/wms_connector/tests/test_import.py index 281fe19f7ec..705ddadd38a 100644 --- a/wms_connector/tests/test_import.py +++ b/wms_connector/tests/test_import.py @@ -5,7 +5,6 @@ class TestImport(TransactionCase): - def setUp(self): super().setUp()