From f4c86fb6854af7306c1274175ee23422ebbb1de2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Honor=C3=A9?= Date: Tue, 11 Jun 2024 14:22:56 +0200 Subject: [PATCH] [IMP] shopinvader_cart_expiry: improve job Improve the job in charge of unlink old carts by adding an identity key (to avoid having too much jobs who are doing the same cleaning on the same backend) --- .../migrations/14.0.1.0.3/post-migrate.py | 2 +- shopinvader_cart_expiry/models/shopinvader_backend.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/shopinvader_cart_expiry/migrations/14.0.1.0.3/post-migrate.py b/shopinvader_cart_expiry/migrations/14.0.1.0.3/post-migrate.py index bf16a67391..336feae3a2 100644 --- a/shopinvader_cart_expiry/migrations/14.0.1.0.3/post-migrate.py +++ b/shopinvader_cart_expiry/migrations/14.0.1.0.3/post-migrate.py @@ -16,7 +16,7 @@ def migrate(cr, version): with api.Environment.manage(): env = api.Environment(cr, SUPERUSER_ID, {}) domain = [("cart_expiry_delay", ">", 0)] - for backend in env.search(domain): + for backend in env["shopinvader.backend"].search(domain): backend = backend.with_company(backend.company_id.id).sudo_tech() expiry_date = fields.Datetime.from_string(fields.Datetime.now()) delta_arg = {backend.cart_expiry_delay_unit: backend.cart_expiry_delay} diff --git a/shopinvader_cart_expiry/models/shopinvader_backend.py b/shopinvader_cart_expiry/models/shopinvader_backend.py index 19970c05fe..223d3193ab 100644 --- a/shopinvader_cart_expiry/models/shopinvader_backend.py +++ b/shopinvader_cart_expiry/models/shopinvader_backend.py @@ -35,7 +35,10 @@ def _scheduler_manage_cart_expiry(self, domain=False): domain = expression.AND([domain, [("cart_expiry_delay", ">", 0)]]) for backend in self.search(domain): description = _("Manage cart expired for backend %s") % backend.name - backend.with_delay(description=description).manage_cart_expiry() + backend.with_delay( + description=description, + identity_key="shopinvader_manage_cart_expiry_%s" % (str(backend.id),), + ).manage_cart_expiry() def _get_cart_expiry_delay_domain(self): expiry_date = fields.Datetime.from_string(fields.Datetime.now())