From 6923c08a592ee4c81625f5276a4babf3aa5d384c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 23 Nov 2023 06:25:52 +0100 Subject: [PATCH] wms_connector: improve code - do not add storage_backend_id on warehouse, to avoid extra complexity when using server env - add explicit method_type and filepath --- wms_connector/models/stock_warehouse.py | 33 +++++++++---------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index c8015c267c..54f56dd4af 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -32,6 +32,8 @@ "fieldname_task": "wms_export_task_id", "fieldname_cron": "wms_export_product_cron_id", "filetype": "export", + "method_type": "export", + "filepath": "IN/", "name_fragment": "export products", "code": "wh = env['stock.warehouse'].browse({})\n" "wh.refresh_wms_products()\n" @@ -42,6 +44,8 @@ "fieldname_task": "wms_export_task_id", "fieldname_cron": "wms_export_picking_in_cron_id", "filetype": "export", + "method_type": "export", + "filepath": "IN/", "name_fragment": "export pickings in", "code": "wh = env['stock.warehouse'].browse({})\n" "env['stock.picking'].with_context(attachment_task=wh.{})._schedule_export(wh," @@ -51,6 +55,8 @@ "fieldname_task": "wms_export_task_id", "fieldname_cron": "wms_export_picking_out_cron_id", "filetype": "export", + "method_type": "export", + "filepath": "IN/", "name_fragment": "export pickings out", "code": "wh = env['stock.warehouse'].browse({})\n" "env['stock.picking'].with_context(attachment_task=wh.{})._schedule_export(wh," @@ -95,24 +101,11 @@ class StockWarehouse(models.Model): wms_export_picking_out_cron_id = fields.Many2one("ir.cron", readonly=True) wms_import_confirm_reception_cron_id = fields.Many2one("ir.cron", readonly=True) wms_import_confirm_delivery_cron_id = fields.Many2one("ir.cron", readonly=True) - wms_export_product_filter_id = fields.Many2one( - "ir.filters", - ) - wms_export_picking_in_filter_id = fields.Many2one( - "ir.filters", - ) - wms_export_picking_out_filter_id = fields.Many2one( - "ir.filters", - ) + wms_export_product_filter_id = fields.Many2one("ir.filters") + wms_export_picking_in_filter_id = fields.Many2one("ir.filters") + wms_export_picking_out_filter_id = fields.Many2one("ir.filters") wms_product_sync_ids = fields.One2many("wms.product.sync", "warehouse_id") - def _default_storage_backend(self): - return self.env.ref("storage_backend.default_storage_backend").id - - storage_backend_id = fields.Many2one( - "storage.backend", default=_default_storage_backend - ) - def _wms_domain_for(self, model_domain): domains = { "product": [ @@ -149,10 +142,8 @@ def _activate_tasks(self): self._prepare_wms_task_vals( mappings["filetype"], mappings["name_fragment"], - mappings["method_type"] - if "method_type" in mappings - else "export", - mappings["filepath"] if "filepath" in mappings else None, + mappings["method_type"], + mappings["filepath"], ) ) @@ -194,7 +185,7 @@ def _prepare_wms_task_vals( "name": "WMS task for {} {}".format(self.name, name_fragment), "method_type": method_type, "filepath": filepath, - "backend_id": self.storage_backend_id.id, + "backend_id": self.env.ref("storage_backend.default_storage_backend").id, "file_type": filetype, }