From 55b7f58f79f4263d39609757e256f9a80541bc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 18 Oct 2022 13:01:20 +0200 Subject: [PATCH 1/2] Revert "[14.0][IMP] queue_job current company" This reverts commit 309eb5fe55cb5c32ab4f075e619ccf81d46c74f1. --- queue_job/job.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/queue_job/job.py b/queue_job/job.py index ff95f9100a..457df97ecd 100644 --- a/queue_job/job.py +++ b/queue_job/job.py @@ -699,13 +699,7 @@ def db_record(self): @property def func(self): - # We can fill only one company into allowed_company_ids. - # Because if you have many, you can have unexpected records due to ir.rule. - # ir.rule use allowed_company_ids to load every records in many companies. - # But most of the time, a job should be executed on a single company. recordset = self.recordset.with_context(job_uuid=self.uuid) - if self.company_id: - recordset = recordset.with_company(self.company_id) return getattr(recordset, self.method_name) @property From 1ea2d3926e6372ebae2f01dc9e07a13d7191dc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 18 Oct 2022 13:04:31 +0200 Subject: [PATCH 2/2] Update test with proper way to pass company to job --- test_queue_job/models/test_models.py | 2 +- test_queue_job/tests/test_job.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/test_queue_job/models/test_models.py b/test_queue_job/models/test_models.py index f810dba862..573e2380a9 100644 --- a/test_queue_job/models/test_models.py +++ b/test_queue_job/models/test_models.py @@ -40,7 +40,7 @@ class ModelTestQueueJob(models.Model): # to test the context is serialized/deserialized properly @api.model def _job_prepare_context_before_enqueue_keys(self): - return ("tz", "lang") + return ("tz", "lang", "allowed_company_ids") def testing_method(self, *args, **kwargs): """Method used for tests diff --git a/test_queue_job/tests/test_job.py b/test_queue_job/tests/test_job.py index f8253db11a..46f75cc827 100644 --- a/test_queue_job/tests/test_job.py +++ b/test_queue_job/tests/test_job.py @@ -190,7 +190,7 @@ def test_company_simple(self): company = self.env.ref("base.main_company") eta = datetime.now() + timedelta(hours=5) test_job = Job( - self.method, + self.env["test.queue.job"].with_company(company).testing_method, args=("o", "k"), kwargs={"return_context": 1}, priority=15, @@ -198,11 +198,10 @@ def test_company_simple(self): description="My description", ) test_job.worker_pid = 99999 # normally set on "set_start" - test_job.company_id = company.id test_job.store() job_read = Job.load(self.env, test_job.uuid) self.assertEqual(test_job.func.__func__, job_read.func.__func__) - result_ctx = test_job.func(*tuple(test_job.args), **test_job.kwargs) + result_ctx = job_read.func(*tuple(test_job.args), **test_job.kwargs) self.assertEqual(result_ctx.get("allowed_company_ids"), company.ids) def test_company_complex(self): @@ -214,7 +213,7 @@ def test_company_complex(self): self.assertEqual(self.env.user.company_id, company1) eta = datetime.now() + timedelta(hours=5) test_job = Job( - self.method, + self.env["test.queue.job"].with_company(company2).testing_method, args=("o", "k"), kwargs={"return_context": 1}, priority=15, @@ -222,11 +221,10 @@ def test_company_complex(self): description="My description", ) test_job.worker_pid = 99999 # normally set on "set_start" - test_job.company_id = company2.id test_job.store() job_read = Job.load(self.env, test_job.uuid) self.assertEqual(test_job.func.__func__, job_read.func.__func__) - result_ctx = test_job.func(*tuple(test_job.args), **test_job.kwargs) + result_ctx = job_read.func(*tuple(test_job.args), **test_job.kwargs) self.assertEqual(result_ctx.get("allowed_company_ids"), company2.ids) def test_store(self):