diff --git a/argocd_deployer/models/application.py b/argocd_deployer/models/application.py
index 0f87a13..b7d8531 100644
--- a/argocd_deployer/models/application.py
+++ b/argocd_deployer/models/application.py
@@ -45,7 +45,9 @@ class Application(models.Model):
application_set_id = fields.Many2one(
"argocd.application.set",
)
- is_deployed = fields.Boolean(compute="_compute_is_deployed")
+ is_deployed = fields.Boolean(
+ compute="_compute_is_deployed", search="_search_is_deployed"
+ )
is_application_set_deployed = fields.Boolean(
string="Is App. Set deployed", related="application_set_id.is_deployed"
)
@@ -98,6 +100,28 @@ def _compute_is_deployed(self):
)
app.is_deployed = os.path.isfile(path)
+ def _search_is_deployed(self, operator, value):
+ if operator not in ["=", "!="]:
+ raise NotImplementedError("Operator not supported. Use '=' or '!='.")
+ if not isinstance(value, bool):
+ raise NotImplementedError("Value must be boolean")
+
+ # TODO: When there are many apps, this will be pretty slow. If so,
+ # may need to come up with a better search method.
+ if operator == "=" and value or operator == "!=" and not value:
+ apps = (
+ self.env["argocd.application"]
+ .search([])
+ .filtered(lambda a: a.is_deployed)
+ )
+ else:
+ apps = (
+ self.env["argocd.application"]
+ .search([])
+ .filtered(lambda a: not a.is_deployed)
+ )
+ return [("id", "in", apps.ids)]
+
def _render_description(self):
self.ensure_one()
return self.env["ir.qweb"]._render(
diff --git a/argocd_deployer/tests/test_application.py b/argocd_deployer/tests/test_application.py
index 5944fb7..a02f9e8 100644
--- a/argocd_deployer/tests/test_application.py
+++ b/argocd_deployer/tests/test_application.py
@@ -100,3 +100,36 @@ def test_immediate_destroy(self):
mock_repository, "Removed `test-set`", ["application_set.yaml"]
)
mock_remote.push.assert_called_once()
+
+ def test_search_is_deployed(self):
+ app2 = self.env["argocd.application"].create(
+ {
+ "name": "myapp2",
+ "template_id": self.env.ref(
+ "argocd_deployer.demo_curq_basis_application_template"
+ ).id,
+ "tag_ids": [
+ self.env.ref(
+ "argocd_deployer.demo_matomo_server_application_tag"
+ ).id,
+ ],
+ }
+ )
+ result = self.env["argocd.application"].search([("is_deployed", "=", False)])
+ self.assertEqual(self.app | app2, result)
+ result = self.env["argocd.application"].search([("is_deployed", "!=", True)])
+ self.assertEqual(self.app | app2, result)
+
+ with patch(
+ "odoo.addons.argocd_deployer.models.application.Application.is_deployed",
+ return_value=True,
+ ):
+ result = self.env["argocd.application"].search([("is_deployed", "=", True)])
+ self.assertEqual(self.app | app2, result)
+ result = self.env["argocd.application"].search(
+ [("is_deployed", "!=", False)]
+ )
+ self.assertEqual(self.app | app2, result)
+
+ with self.assertRaisesRegex(NotImplementedError, "Operator not supported."):
+ self.env["argocd.application"].search([("is_deployed", "in", [True])])
diff --git a/argocd_deployer/views/application_view.xml b/argocd_deployer/views/application_view.xml
index f95dc28..9f9384b 100644
--- a/argocd_deployer/views/application_view.xml
+++ b/argocd_deployer/views/application_view.xml
@@ -95,6 +95,16 @@
+
+ argocd.application
+
+
+
+
+
+
+
+
argocd.application