Skip to content

Commit 29f4cac

Browse files
committed
[IMP] hide buttons dynamically
1 parent 1600a33 commit 29f4cac

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

spp_base_common/models/area_import.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import fields, models
1+
from odoo import api, fields, models
22

33

44
class 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

spp_base_common/views/area_import_view.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
55
<field name="model">spp.area.import</field>
66
<field name="inherit_id" ref="spp_area_base.view_spparea_import_form" />
77
<field name="arch" type="xml">
8+
<!-- Add has_ongoing_jobs field for button visibility control -->
9+
<xpath expr="//field[@name='locked']" position="after">
10+
<field name="has_ongoing_jobs" invisible="1" />
11+
</xpath>
12+
13+
<!-- Modify Parse button to check for ongoing jobs -->
14+
<xpath expr="//button[@name='parse_excel_to_json']" position="attributes">
15+
<attribute name="invisible">state not in ('New', 'Uploaded') or has_ongoing_jobs</attribute>
16+
</xpath>
17+
18+
<!-- Modify Import button to check for ongoing jobs -->
19+
<xpath expr="//button[@name='import_data']" position="attributes">
20+
<attribute name="invisible">state not in ('New', 'Parsed') or has_ongoing_jobs</attribute>
21+
</xpath>
22+
23+
<!-- Modify Save to Area button to check for ongoing jobs -->
24+
<xpath expr="//button[@name='save_to_area']" position="attributes">
25+
<attribute name="invisible">state != 'Validated' or has_ongoing_jobs</attribute>
26+
</xpath>
27+
28+
<!-- Modify Validate Data button to check for ongoing jobs -->
29+
<xpath expr="//button[@name='validate_raw_data']" position="attributes">
30+
<attribute name="invisible">state != 'Imported' or has_ongoing_jobs</attribute>
31+
</xpath>
32+
833
<xpath expr="//page[@name='json_data']" position="after">
934
<page string="Queue Jobs" name="queue_jobs" invisible="not job_ids">
1035
<field name="job_ids" nolabel="1" readonly="1">

0 commit comments

Comments
 (0)