Skip to content

Commit

Permalink
Merge PR #880 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Jun 17, 2024
2 parents eee5fd4 + c23d9e1 commit 9f34f48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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

0 comments on commit 9f34f48

Please sign in to comment.