From 8946312c6457d45f9ae1e87e25d4a9ead4f69bc1 Mon Sep 17 00:00:00 2001 From: Francois Poizat Date: Wed, 6 Dec 2023 17:12:20 +0100 Subject: [PATCH 1/2] wms_connector: ADD inventory import support --- wms_connector/models/attachment_queue.py | 7 +++++++ .../models/attachment_synchronize_task.py | 9 +++++++++ wms_connector/models/stock_warehouse.py | 14 ++++++++++++++ wms_connector/views/stock_warehouse.xml | 2 ++ 4 files changed, 32 insertions(+) diff --git a/wms_connector/models/attachment_queue.py b/wms_connector/models/attachment_queue.py index 5293e468e5..15f966d99a 100644 --- a/wms_connector/models/attachment_queue.py +++ b/wms_connector/models/attachment_queue.py @@ -6,6 +6,7 @@ WMS_IMPORT_FILETYPES = [ ("wms_reception_confirmed", "WMS Reception confirmed"), ("wms_delivery_confirmed", "WMS Delivery confirmed"), + ("wms_update_inventory", "WMS inventory update"), ] @@ -13,6 +14,9 @@ class AttachmentQueue(models.Model): _inherit = "attachment.queue" file_type = fields.Selection(selection_add=WMS_IMPORT_FILETYPES) + # This seems fishy but we need the warehouse id to allow + # for update inventory + default_warehouse_id = fields.Many2one("stock.warehouse") def _run(self): for filetype in [el[0] for el in WMS_IMPORT_FILETYPES]: @@ -25,3 +29,6 @@ def _run_wms_reception_confirmed(self): def _run_wms_delivery_confirmed(self): raise NotImplementedError + + def _run_wms_update_inventory(self): + raise NotImplementedError diff --git a/wms_connector/models/attachment_synchronize_task.py b/wms_connector/models/attachment_synchronize_task.py index b126352167..db252a943e 100644 --- a/wms_connector/models/attachment_synchronize_task.py +++ b/wms_connector/models/attachment_synchronize_task.py @@ -7,10 +7,19 @@ class AttachmentSynchronizeTask(models.Model): _inherit = "attachment.synchronize.task" + default_warehouse_id = fields.Many2one("stock.warehouse") + file_type = fields.Selection( selection_add=[ ("export", "Export"), ("wms_reception_confirmed", "Reception confirmed"), ("wms_delivery_confirmed", "Delivery confirmed"), + ("wms_update_inventory", "Inventory update"), ] ) + + def _prepare_attachment_vals(self, data, filename): + self.ensure_one() + vals = super()._prepare_attachment_vals(data, filename) + vals["default_warehouse_id"] = self.default_warehouse_id.id + return vals diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index 54f56dd4af..394098a306 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -80,6 +80,15 @@ "name_fragment": "delivery confirmation", "code": "env['stock.warehouse'].browse({}).{}.run_import()", }, + "inventory": { + "fieldname_task": "wms_import_update_inventory_task_id", + "fieldname_cron": "wms_import_update_inventory_cron_id", + "filetype": "wms_update_inventory", + "method_type": "import", + "filepath": "OUT/", + "name_fragment": "Update inventory", + "code": "env['stock.warehouse'].browse({}).{}.run_import()", + }, } @@ -96,11 +105,15 @@ class StockWarehouse(models.Model): wms_import_confirm_delivery_task_id = fields.Many2one( "attachment.synchronize.task", readonly=True ) + wms_import_update_inventory_task_id = fields.Many2one( + "attachment.synchronize.task", readonly=True + ) wms_export_product_cron_id = fields.Many2one("ir.cron", readonly=True) wms_export_picking_in_cron_id = fields.Many2one("ir.cron", readonly=True) 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_import_update_inventory_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") @@ -187,6 +200,7 @@ def _prepare_wms_task_vals( "filepath": filepath, "backend_id": self.env.ref("storage_backend.default_storage_backend").id, "file_type": filetype, + "default_warehouse_id": self.id, } def _prepare_wms_cron_vals(self, code="", name_fragment=""): diff --git a/wms_connector/views/stock_warehouse.xml b/wms_connector/views/stock_warehouse.xml index 61f547f9d4..f106eaab27 100644 --- a/wms_connector/views/stock_warehouse.xml +++ b/wms_connector/views/stock_warehouse.xml @@ -46,6 +46,7 @@ + @@ -53,6 +54,7 @@ + From fc60d25363ad6a6cc9465972dfbbee14b9967756 Mon Sep 17 00:00:00 2001 From: Francois Poizat Date: Thu, 7 Dec 2023 16:04:24 +0100 Subject: [PATCH 2/2] wms_connector: compute default_warehouse_id for inventory in a simpler way --- wms_connector/models/attachment_queue.py | 21 ++++++++++++++++--- .../models/attachment_synchronize_task.py | 8 ------- wms_connector/models/stock_warehouse.py | 1 - 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/wms_connector/models/attachment_queue.py b/wms_connector/models/attachment_queue.py index 15f966d99a..bdbf42a23c 100644 --- a/wms_connector/models/attachment_queue.py +++ b/wms_connector/models/attachment_queue.py @@ -14,9 +14,24 @@ class AttachmentQueue(models.Model): _inherit = "attachment.queue" file_type = fields.Selection(selection_add=WMS_IMPORT_FILETYPES) - # This seems fishy but we need the warehouse id to allow - # for update inventory - default_warehouse_id = fields.Many2one("stock.warehouse") + default_warehouse_id = fields.Many2one( + "stock.warehouse", compute="_compute_default_warehouse", store=True + ) + + def _compute_default_warehouse(self): + for rec in self: + task_queue_prefix = None + if rec.file_type == "wms_reception_confirmed": + task_queue_prefix = "wms_import_picking_in" + elif rec.file_type == "wms_delivery_confirmed": + task_queue_prefix = "wms_import_picking_out" + elif rec.file_type == "wms_update_inventory": + task_queue_prefix = "wms_import_update_inventory" + + if task_queue_prefix is not None: + rec.default_warehouse_id = rec.env["stock.warehouse"].search( + [(f"{task_queue_prefix}_task_id.attachment_ids", "=", rec.id)] + ) def _run(self): for filetype in [el[0] for el in WMS_IMPORT_FILETYPES]: diff --git a/wms_connector/models/attachment_synchronize_task.py b/wms_connector/models/attachment_synchronize_task.py index db252a943e..75470198e9 100644 --- a/wms_connector/models/attachment_synchronize_task.py +++ b/wms_connector/models/attachment_synchronize_task.py @@ -7,8 +7,6 @@ class AttachmentSynchronizeTask(models.Model): _inherit = "attachment.synchronize.task" - default_warehouse_id = fields.Many2one("stock.warehouse") - file_type = fields.Selection( selection_add=[ ("export", "Export"), @@ -17,9 +15,3 @@ class AttachmentSynchronizeTask(models.Model): ("wms_update_inventory", "Inventory update"), ] ) - - def _prepare_attachment_vals(self, data, filename): - self.ensure_one() - vals = super()._prepare_attachment_vals(data, filename) - vals["default_warehouse_id"] = self.default_warehouse_id.id - return vals diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index 394098a306..207052dc1f 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -200,7 +200,6 @@ def _prepare_wms_task_vals( "filepath": filepath, "backend_id": self.env.ref("storage_backend.default_storage_backend").id, "file_type": filetype, - "default_warehouse_id": self.id, } def _prepare_wms_cron_vals(self, code="", name_fragment=""):