From e3745b8d7b45b1d1ad00f05bd15557fd8001a3e9 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Wed, 25 Oct 2023 00:54:20 +0300 Subject: [PATCH] cleanup --- wms_connector/models/stock_warehouse.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py index 097a757cb7..a9d8e82e65 100644 --- a/wms_connector/models/stock_warehouse.py +++ b/wms_connector/models/stock_warehouse.py @@ -199,23 +199,18 @@ def _deactivate_crons_tasks(self): def refresh_wms_products(self): for rec in self: - prd_with_sync = self.wms_product_sync_ids.product_id + existing_prd = self.wms_product_sync_ids.product_id prd_matching = self.env["product.product"].search( rec.wms_export_product_filter_id and rec.wms_export_product_filter_id._get_eval_domain() or [] ) - to_create = prd_matching - prd_with_sync - for prd in to_create: - self.env["wms.product.sync"].create( - {"product_id": prd.id, "warehouse_id": rec.id} - ) - self.env["wms.product.sync"].search( - [ - ("warehouse_id", "=", rec.id), - ("product_id", "in", (prd_with_sync - prd_matching).ids), - ] - ).unlink() + to_create = prd_matching - existing_prd + to_unlink = existing_prd - prd_matching + self.env["wms.product.sync"].create( + [{"product_id": prd.id, "warehouse_id": rec.id} for prd in to_create] + ) + to_unlink.unlink() def button_open_wms_sync_ids(self): return {