Skip to content

Commit

Permalink
wms_connector: improve code
Browse files Browse the repository at this point in the history
- do not add storage_backend_id on warehouse, to avoid extra complexity when using server env
- add explicit method_type and filepath
  • Loading branch information
sebastienbeau committed Nov 23, 2023
1 parent 179ea42 commit 6923c08
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions wms_connector/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,"
Expand All @@ -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,"
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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"],
)
)

Expand Down Expand Up @@ -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,
}

Expand Down

0 comments on commit 6923c08

Please sign in to comment.