Skip to content

Commit

Permalink
Merge PR #928 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Sep 2, 2024
2 parents c3f636d + fdec587 commit 6db1306
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions bi_sql_editor/models/bi_sql_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

@api.model
def _instanciate(self, model_data):
""" Return a class for the custom model given by
parameters ``model_data``. """
"""Return a class for the custom model given by
parameters ``model_data``."""

# This monkey patch is meant to avoid create/search tables for those
# materialized views. Doing "super" doesn't work.
class CustomModel(models.Model):
Expand Down Expand Up @@ -281,6 +282,8 @@ def unlink(self):
"If you want to delete them, first set them to draft."
)
)
# Remove Scheduled Actions, as they were not removed in `button_set_draft`
self.mapped("cron_id").unlink()
return super(BiSQLView, self).unlink()

def copy(self, default=None):
Expand Down Expand Up @@ -310,9 +313,13 @@ def button_create_sql_view_and_model(self):
sql_view._create_index()

if sql_view.is_materialized:
sql_view.cron_id = (
self.env["ir.cron"].create(sql_view._prepare_cron()).id
)
# Create Cron only if it has not been created yet, otherwise unarchive it
if sql_view.cron_id and not sql_view.cron_id.active:
sql_view.cron_id.write({"active": True})
else:
sql_view.cron_id = (
self.env["ir.cron"].create(sql_view._prepare_cron()).id
)
sql_view.state = "model_valid"

def button_set_draft(self):
Expand All @@ -324,7 +331,7 @@ def button_set_draft(self):
sql_view.pivot_view_id.unlink()
sql_view.search_view_id.unlink()
if sql_view.cron_id:
sql_view.cron_id.unlink()
sql_view.cron_id.write({"active": False})

if sql_view.state in ("model_valid", "ui_valid"):
# Drop SQL View (and indexes by cascade)
Expand Down

0 comments on commit 6db1306

Please sign in to comment.