Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Oct 20, 2023
1 parent 40fae00 commit 2228880
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 11 additions & 3 deletions wms_connector/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,20 @@ def action_open_flows(self):

def refresh_wms_products(self):
for rec in self:
rec.wms_product_sync_ids.unlink()
for prd in self.env["product.product"].search(
prd_with_sync = 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()
20 changes: 20 additions & 0 deletions wms_connector/tests/test_activate_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ def test_wms_product_sync_created_filter(self):
1,
len(self.env["wms.product.sync"].search([])),
)

def test_wms_product_sync_updates(self):
self.warehouse.active_wms_sync = True
match_unlink, match_keep, nomatch_match = self.env["product.product"].search(
[], limit=3
)
self.warehouse.wms_export_product_filter_id.domain = (
'[("id", "in", {})]'.format((match_unlink + match_keep).ids)
)
self.warehouse.refresh_wms_products()
self.assertEqual(
self.warehouse.wms_product_sync_ids.product_id, (match_unlink + match_keep)
)
self.warehouse.wms_export_product_filter_id.domain = (
'[("id", "in", {})]'.format((match_keep + nomatch_match).ids)
)
self.warehouse.refresh_wms_products()
self.assertEqual(
self.warehouse.wms_product_sync_ids.product_id, match_keep + nomatch_match
)

0 comments on commit 2228880

Please sign in to comment.