Merge PR #880 into 16.0

Signed-off-by legalsylvain
This commit is contained in:
OCA-git-bot
2024-06-17 09:35:16 +00:00
3 changed files with 21 additions and 0 deletions

View File

@@ -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(
[

View File

@@ -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"

View File

@@ -63,6 +63,21 @@ class SqlFileWizard(models.TransientModel):
% {"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",