Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16] sql_export : Add last_run datetime field #880

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sql_export/models/sql_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class SqlExport(models.Model):

use_properties = fields.Boolean(compute="_compute_use_properties")
query_properties_definition = fields.PropertiesDefinition("Query Properties")
last_execution_date = fields.Datetime(readonly=True)
last_execution_uid = fields.Many2one(
"res.users", string="Last execution User", readonly=True
)

encoding = fields.Selection(
[
Expand Down
2 changes: 2 additions & 0 deletions sql_export/views/sql_export_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="last_execution_date" optional="hide" />
<field name="last_execution_uid" optional="hide" />
<button
name="export_sql_query"
string="Execute Query"
Expand Down
15 changes: 15 additions & 0 deletions sql_export/wizard/wizard_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ def export_sql(self):
% {"name": sql_export.name, "date": date, "extension": extension},
}
)
# Bypass ORM to avoid changing the write_date/uid from sql query on a simple
# execution. This also avoid error if user has no update right on the
# sql.export object.
self.env.cr.execute(
"""
UPDATE sql_export
SET last_execution_date = %s, last_execution_uid = %s
WHERE id = %s
""",
(
fields.Datetime.to_string(fields.Datetime.now()),
self.env.user.id,
sql_export.id,
),
)
action = {
"name": "SQL Export",
"type": "ir.actions.act_url",
Expand Down
Loading