1- from odoo import fields , models
1+ from odoo import api , fields , models
22
33
44class OpenSPPAreaImport (models .Model ):
@@ -11,6 +11,12 @@ class OpenSPPAreaImport(models.Model):
1111 help = "Queue jobs related to this area import" ,
1212 )
1313
14+ has_ongoing_jobs = fields .Boolean (
15+ compute = "_compute_has_ongoing_jobs" ,
16+ string = "Has Ongoing Jobs" ,
17+ help = "True if there are any ongoing queue jobs for this model" ,
18+ )
19+
1420 def _compute_job_ids (self ):
1521 """
1622 Compute related queue jobs based on res_id and res_model fields.
@@ -23,3 +29,22 @@ def _compute_job_ids(self):
2329 ]
2430 )
2531 rec .job_ids = jobs
32+
33+ @api .depends ("job_ids" , "job_ids.state" )
34+ def _compute_has_ongoing_jobs (self ):
35+ """
36+ Check if there are any ongoing jobs for the spp.area.import model.
37+ This checks across ALL area import records to prevent concurrent operations.
38+ """
39+ # Check for any ongoing jobs for the entire model
40+ ongoing_jobs_count = self .env ["queue.job" ].search_count (
41+ [
42+ ("res_model" , "=" , "spp.area.import" ),
43+ ("state" , "in" , ["pending" , "enqueued" , "started" ]),
44+ ]
45+ )
46+ has_ongoing = ongoing_jobs_count > 0
47+
48+ # Set the same value for all records
49+ for rec in self :
50+ rec .has_ongoing_jobs = has_ongoing
0 commit comments