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=""):