From 5a99a748ca748f2689e3d42419f786931195966b Mon Sep 17 00:00:00 2001 From: docker-odoo Date: Thu, 31 Oct 2024 14:56:20 +0000 Subject: [PATCH] [MIG] l10n_uy_reports: Migration to 18.0 --- l10n_uy_reports/README.rst | 6 +-- l10n_uy_reports/__manifest__.py | 4 +- .../data/account_financial_report_data.xml | 1 - l10n_uy_reports/models/l10n_uy_vat_book.py | 24 ++++----- l10n_uy_reports/report/account_uy_vat_line.py | 36 +++++++------ .../report/account_uy_vat_line_views.xml | 8 +-- l10n_uy_reports/wizards/form_report_wiz.py | 50 +++++++++---------- 7 files changed, 67 insertions(+), 62 deletions(-) diff --git a/l10n_uy_reports/README.rst b/l10n_uy_reports/README.rst index 488f4c96..c6f8b9cf 100644 --- a/l10n_uy_reports/README.rst +++ b/l10n_uy_reports/README.rst @@ -14,8 +14,8 @@ Uruguay - Accounting Reports ============================ -* Agrega la posibilidad de ver/exportar xls con el libro de IVA Compras/Ventas Uruguayo, esto en el menu "Tax Reports" -* Agrega el menu Resumen de IVA para uruguay, reporte que se puee usar para analizar los datos de facturacióneed +* Agrega la posibilidad de ver/exportar xls con el libro de IVA Compras/Ventas Uruguayo en el menu "Tax Return" +* Agrega el menú Resumen de IVA para Uruguay, reporte que se puede usar para analizar los datos de facturación * Nuevo asistente que permite generar los archivos TXT para presentar el Formulario 2/181 (hasta el momento solo repota impuestos de iva compra/venta). Instructivos: https://www.gub.uy/direccion-general-impositiva/comunicacion/publicaciones/instructivo-para-confeccion-presentacion-declaraciones-aplicacion-beta y https://www.gub.uy/direccion-general-impositiva/comunicacion/publicaciones/informacion-sobre-formulario-2181 @@ -25,7 +25,7 @@ Detalle de implementacion * Detalle completo aplicativo B https://www.gub.uy/direccion-general-impositiva/politicas-y-gestion/aplicacion-beta-version-990 * Especificacion de formularios https://www.gub.uy/direccion-general-impositiva/comunicacion/publicaciones/instructivo-para-confeccion-presentacion-declaraciones-beta * Agentes de Informacion https://www.gub.uy/direccion-general-impositiva/sites/direccion-general-impositiva/files/documentos/publicaciones/Agentes%20de%20informaci%C3%B3n.%20Cuadro%20formulario%202181_1.pdf -* Reference contacts: +* Contactos de referencia: - Telefónicas: 1344 opción 5 (21344 desde el interior del país). - Correo electrónico: dacontri@dgi.gub.uy o a través del servicio Consultas Web ("restantes impuestos") - Por incidentes informáticos: SAC - Registro de Incidentes diff --git a/l10n_uy_reports/__manifest__.py b/l10n_uy_reports/__manifest__.py index 82ca8c78..38b0d9aa 100644 --- a/l10n_uy_reports/__manifest__.py +++ b/l10n_uy_reports/__manifest__.py @@ -1,7 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. { 'name': 'Uruguay - Accounting Reports', - 'version': "17.0.1.0.0", + 'version': "18.0.1.0.0", 'author': 'ADHOC SA', 'license': 'LGPL-3', 'category': 'Localization', @@ -23,5 +23,5 @@ ], }, 'auto_install': True, - 'installable': False, + 'installable': True, } diff --git a/l10n_uy_reports/data/account_financial_report_data.xml b/l10n_uy_reports/data/account_financial_report_data.xml index dd8e23e8..7baeeaa4 100644 --- a/l10n_uy_reports/data/account_financial_report_data.xml +++ b/l10n_uy_reports/data/account_financial_report_data.xml @@ -14,7 +14,6 @@ - Date date date diff --git a/l10n_uy_reports/models/l10n_uy_vat_book.py b/l10n_uy_reports/models/l10n_uy_vat_book.py index e0649be8..99eb0177 100644 --- a/l10n_uy_reports/models/l10n_uy_vat_book.py +++ b/l10n_uy_reports/models/l10n_uy_vat_book.py @@ -1,10 +1,10 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import models, _ - +from odoo.tools import SQL class UruguayanReportCustomHandler(models.AbstractModel): _name = 'l10n_uy.tax.report.handler' - _inherit = 'account.generic.tax.report.handler' + _inherit = 'account.tax.report.handler' _description = 'Uruguayan Report Custom Handler' def _get_custom_display_config(self): @@ -26,17 +26,16 @@ def _dynamic_lines_generator(self, report, options, all_column_groups_expression # Build full query query_list = [] - full_query_params = [] - for column_group_key, column_group_options in report._split_options_per_column_group(options).items(): - query, params = self._build_query(report, column_group_options, column_group_key) - query_list.append(f"({query})") - full_query_params += params + options_per_col_group = report._split_options_per_column_group(options) + for column_group_key, column_group_options in options_per_col_group.items(): + query = self._build_query(report, column_group_options, column_group_key) + query_list.append(SQL("(%s)", query)) # Set defaults here since the results of the query for this column_group_key might be empty total_values_dict.setdefault(column_group_key, dict.fromkeys(number_keys, 0.0)) - full_query = " UNION ALL ".join(query_list) - self._cr.execute(full_query, full_query_params) + full_query = SQL(" UNION ALL ").join(query_list) + self._cr.execute(full_query) results = self._cr.dictfetchall() for result in results: # Iterate over these results in order to fill the move_info_dict dictionary @@ -91,12 +90,11 @@ def _custom_options_initializer(self, report, options, previous_options=None): #################################################### def _build_query(self, report, options, column_group_key): - tables, where_clause, where_params = report._query_get(options, 'strict_range') + query = report._get_report_query(options, 'strict_range') - where_clause = f"AND {where_clause}" tax_types = tuple(self._vat_book_get_selected_tax_types(options)) - - return self.env['account.uy.vat.line']._uy_vat_line_build_query(tables, where_clause, where_params, column_group_key, tax_types) + + return self.env['account.uy.vat.line']._uy_vat_line_build_query(query.from_clause, query.where_clause, column_group_key, tax_types) def _create_report_line(self, report, options, move_vals, move_id, number_values): """ Create a standard (non total) line for the report diff --git a/l10n_uy_reports/report/account_uy_vat_line.py b/l10n_uy_reports/report/account_uy_vat_line.py index f3a89ca5..d4efcb33 100644 --- a/l10n_uy_reports/report/account_uy_vat_line.py +++ b/l10n_uy_reports/report/account_uy_vat_line.py @@ -1,5 +1,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models, tools +from odoo.tools import SQL class AccountUyVatLine(models.Model): @@ -57,24 +58,26 @@ def init(self): # we use tax_ids for base amount instead of tax_base_amount for two reasons: # * zero taxes do not create any aml line so we can't get base for them with tax_base_amount # * we use same method as in odoo tax report to avoid any possible discrepancy with the computed tax_base_amount - query, params = self._uy_vat_line_build_query() - sql = f"""CREATE or REPLACE VIEW account_uy_vat_line as ({query})""" - cr.execute(sql, params) + query = self._uy_vat_line_build_query() + sql = SQL("""CREATE or REPLACE VIEW account_uy_vat_line as (%s)""", query) + cr.execute(sql) @api.model - def _uy_vat_line_build_query(self, tables='account_move_line', where_clause='', where_params=None, + def _uy_vat_line_build_query(self, table_references=None, search_condition=None, column_group_key='', tax_types=('sale', 'purchase')): """Returns the SQL Select query fetching account_move_lines info in order to build the pivot view for the VAT summary. This method is also meant to be used outside this model, which is the reason why it gives the opportunity to provide a few parameters, for which the defaults are used in this model. The query is used to build the VAT book report""" - if where_params is None: - where_params = [] + if table_references is None: + table_references = SQL('account_move_line') + search_condition = SQL('AND (%s)', search_condition) if search_condition else SQL() - query = f""" + query = SQL( + """ SELECT - %s AS column_group_key, + %(column_group_key)s AS column_group_key, account_move.id, (CASE WHEN lit.l10n_uy_dgi_code = '2' THEN rp.vat ELSE NULL END) AS rut, account_move.name as move_name, @@ -98,7 +101,7 @@ def _uy_vat_line_build_query(self, tables='account_move_line', where_clause='', SUM(CASE WHEN nt.amount not in (22.0, 10.0, 0.0) AND nt.l10n_uy_tax_category = 'vat' THEN account_move_line.balance ELSE 0 END) AS other_taxes, SUM(account_move_line.balance) AS total FROM - {tables} + %(table_references)s JOIN account_move ON account_move_line.move_id = account_move.id LEFT JOIN @@ -116,11 +119,16 @@ def _uy_vat_line_build_query(self, tables='account_move_line', where_clause='', WHERE (account_move_line.tax_line_id is not NULL OR bt.amount IN (22.0, 10.0, 0.0) AND bt.l10n_uy_tax_category = 'vat') AND account_move.move_type IN ('out_invoice', 'in_invoice', 'out_refund', 'in_refund') - AND (nt.type_tax_use in %s OR bt.type_tax_use in %s) - {where_clause} + AND (nt.type_tax_use in %(tax_types)s OR bt.type_tax_use in %(tax_types)s) + %(search_condition)s GROUP BY account_move.id, rp.id, lit.id, tax_type ORDER BY - account_move.date, account_move.name""" - - return query, [column_group_key, tax_types, tax_types, *where_params] + account_move.invoice_date, account_move.name + """, + column_group_key=column_group_key, + table_references=table_references, + tax_types=tax_types, + search_condition=search_condition, + ) + return query diff --git a/l10n_uy_reports/report/account_uy_vat_line_views.xml b/l10n_uy_reports/report/account_uy_vat_line_views.xml index 8c497f5f..9b0db298 100644 --- a/l10n_uy_reports/report/account_uy_vat_line_views.xml +++ b/l10n_uy_reports/report/account_uy_vat_line_views.xml @@ -31,10 +31,10 @@ - account.uy.vat.line.tree + account.uy.vat.line.list account.uy.vat.line - + @@ -46,7 +46,7 @@