Skip to content

Commit

Permalink
wms_connector: compute default_warehouse_id for inventory in a simple…
Browse files Browse the repository at this point in the history
…r way
  • Loading branch information
FranzPoize committed Dec 7, 2023
1 parent 8946312 commit fc60d25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
21 changes: 18 additions & 3 deletions wms_connector/models/attachment_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
8 changes: 0 additions & 8 deletions wms_connector/models/attachment_synchronize_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
1 change: 0 additions & 1 deletion wms_connector/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=""):
Expand Down

0 comments on commit fc60d25

Please sign in to comment.