Skip to content
Open
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
100 changes: 100 additions & 0 deletions sql_export_delta/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
==========================
SQL Export (delta support)
==========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9494034b2f072b0d68ca3c3736ce6176299e3fede3f85b06ae004461e90f8431
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/18.0/sql_export_delta
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-sql_export_delta
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of ``sql_export`` to allow you to
only export changes between export runs.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

1. Go to an export in draft mode
2. Check the flag 'Delta'

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20sql_export_delta%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Hunki Enterprises BV

Contributors
------------

- Holger Brunn <mail@hunki-enterprises.com>
(https://hunki-enterprises.com)
- Therp BV info@therp.nl (https://therp.nl)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
:target: https://github.com/hbrunn
:alt: hbrunn

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-hbrunn|

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/18.0/sql_export_delta>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions sql_export_delta/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import wizards
from .hooks import uninstall_hook
21 changes: 21 additions & 0 deletions sql_export_delta/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

{
"name": "SQL Export (delta support)",
"summary": "Support exporting only the changes from last export",
"version": "18.0.1.0.0",
"development_status": "Alpha",
"category": "Extra Tools",
"website": "https://github.com/OCA/reporting-engine",
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
"maintainers": ["hbrunn"],
"license": "AGPL-3",
"uninstall_hook": "uninstall_hook",
"depends": [
"sql_export",
],
"data": [
"views/sql_export.xml",
],
}
7 changes: 7 additions & 0 deletions sql_export_delta/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2024 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)


def uninstall_hook(env):
for export in env["sql.export"].search([]):
export._export_delta_cleanup(keep_last=False)
43 changes: 43 additions & 0 deletions sql_export_delta/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sql_export_delta
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-11-08 11:06+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.6.2\n"

#. module: sql_export_delta
#: model:ir.model,name:sql_export_delta.model_sql_file_wizard
msgid "Allow the user to save the file with sql request's data"
msgstr "Consente all'utente di salvare il file con i dati della richiesta SQL"

#. module: sql_export_delta
#: model:ir.model.fields,field_description:sql_export_delta.field_sql_export__export_delta
msgid "Delta"
msgstr "Differenza"

#. module: sql_export_delta
#: model:ir.model,name:sql_export_delta.model_sql_export
msgid "SQL export"
msgstr "Esporta SQL"

#. module: sql_export_delta
#: model:ir.model.fields,help:sql_export_delta.field_sql_export__export_delta
msgid ""
"With this checked, the full result of the query will be stored as table in "
"the database, but the file generated will only contain rows not existing in "
"the n-1st export"
msgstr ""
"Se questa opzione è selezionata, il risultato completo della query verrà "
"memorizzato come tabella nel database, ma il file generato conterrà solo "
"righe non esistenti nell'esportazione n-1"
37 changes: 37 additions & 0 deletions sql_export_delta/i18n/sql_export_delta.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sql_export_delta
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sql_export_delta
#: model:ir.model,name:sql_export_delta.model_sql_file_wizard
msgid "Allow the user to save the file with sql request's data"
msgstr ""

#. module: sql_export_delta
#: model:ir.model.fields,field_description:sql_export_delta.field_sql_export__export_delta
msgid "Delta"
msgstr ""

#. module: sql_export_delta
#: model:ir.model,name:sql_export_delta.model_sql_export
msgid "SQL export"
msgstr ""

#. module: sql_export_delta
#: model:ir.model.fields,help:sql_export_delta.field_sql_export__export_delta
msgid ""
"With this checked, the full result of the query will be stored as table in "
"the database, but the file generated will only contain rows not existing in "
"the n-1st export"
msgstr ""
1 change: 1 addition & 0 deletions sql_export_delta/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sql_export
98 changes: 98 additions & 0 deletions sql_export_delta/models/sql_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2024 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

from psycopg2.sql import SQL, Identifier

from odoo import fields, models


class SqlExport(models.Model):
_inherit = "sql.export"

export_delta = fields.Boolean(
string="Delta",
help="With this checked, the full result of the query "
"will be stored as table in the database, but the file generated will "
"only contain rows not existing in the n-1st export",
)

def write(self, vals):
"""Delete previous results when we change the query"""
if "query" in vals:
for this in self:
this._export_delta_cleanup(keep_last=False)
return super().write(vals)

def _execute_sql_request(
self,
params=None,
mode="fetchall",
rollback=True,
view_name=False,
copy_options="CSV HEADER DELIMITER ';'",
header=False,
):
delta_id = self.env.context.get("export_delta_id")

if delta_id:
original_query = self.env.cr.mogrify(self.query, params).decode("utf-8")
result_table = self._export_delta_table_name(delta_id)
table_query = SQL(
"WITH result as ({0}) SELECT * INTO TABLE {1} FROM result"
).format(SQL(original_query), Identifier(result_table))
previous_result_table = self._export_delta_existing_tables()[-1:]
if previous_result_table:
result_query = SQL("SELECT * FROM {0} EXCEPT SELECT * FROM {1}").format(
Identifier(result_table),
Identifier(previous_result_table[0]),
)
else:
result_query = SQL("SELECT * FROM {0}").format(Identifier(result_table))
self.env.cr.execute(table_query)
# inject new query in cache for super to use
self._cache["query"] = result_query
result = super()._execute_sql_request(
params=None,
mode=mode,
rollback=rollback,
view_name=view_name,
copy_options=copy_options,
header=header,
)
self.invalidate_recordset(["query"])
self._export_delta_cleanup(keep_last=True)
else:
result = super()._execute_sql_request(
params=params,
mode=mode,
rollback=rollback,
view_name=view_name,
copy_options=copy_options,
header=header,
)

return result

def _export_delta_table_name(self, identifier):
"""
Return the name of a table to store data for delta export, must end with
{identifier}
"""
return f"sql_export_delta_{self.id}_{identifier}"

def _export_delta_existing_tables(self):
"""Return all table names used for storing data for delta export"""
self.env.cr.execute(
"SELECT table_name FROM information_schema.tables WHERE table_name LIKE %s",
(self._export_delta_table_name("%"),),
)
return sorted(
[name for (name,) in self.env.cr.fetchall()],
key=lambda name: int(name[len(self._export_delta_table_name("")) :]),
)

def _export_delta_cleanup(self, keep_last=True):
"""Delete tables storing data for delta export"""
table_names = self._export_delta_existing_tables()[: -1 if keep_last else None]
for table_name in table_names:
self.env.cr.execute(SQL("DROP TABLE {0}").format(Identifier(table_name)))
3 changes: 3 additions & 0 deletions sql_export_delta/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions sql_export_delta/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To configure this module, you need to:

1. Go to an export in draft mode
2. Check the flag 'Delta'
2 changes: 2 additions & 0 deletions sql_export_delta/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Holger Brunn \<mail@hunki-enterprises.com> (https://hunki-enterprises.com)
- Therp BV <info@therp.nl> (https://therp.nl)
1 change: 1 addition & 0 deletions sql_export_delta/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module extends the functionality of ``sql_export`` to allow you to only export changes between export runs.
Binary file added sql_export_delta/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading