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

[MIG] l10n_uy_reports: Migration to 18.0 #258

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions l10n_uy_reports/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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: [email protected] o a través del servicio Consultas Web ("restantes impuestos")
- Por incidentes informáticos: SAC - Registro de Incidentes
Expand Down
6 changes: 3 additions & 3 deletions l10n_uy_reports/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -22,6 +22,6 @@
'l10n_uy_reports/static/src/components/**/*',
],
},
'auto_install': True,
'installable': False,
'auto_install': ['l10n_uy', 'account_reports'],
'installable': True,
}
1 change: 0 additions & 1 deletion l10n_uy_reports/data/account_financial_report_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<field name="load_more_limit" eval="80"/>
<field name="column_ids">
<record id="l10n_uy_vat_book_report_column_invoice_date" model="account.report.column">
<!-- TODO revisar que realmente es el campo invoice_date y no el campo date -->
<field name="name">Date</field>
<field name="expression_label">date</field>
<field name="figure_type">date</field>
Expand Down
69 changes: 34 additions & 35 deletions l10n_uy_reports/models/l10n_uy_vat_book.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# 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):
return {
'templates': {
'AccountReportFilters': 'l10n_uy_reports.L10nUyReportsFiltersCustomizable',
},
}
parent_config = super()._get_custom_display_config()
parent_config['templates']['AccountReportFilters'] = 'l10n_uy_reports.L10nUyReportsFiltersCustomizable'
return parent_config

def _dynamic_lines_generator(self, report, options, all_column_groups_expression_totals, warnings=None):
# dict of the form {move_id: {column_group_key: {expression_label: value}}}
Expand All @@ -26,17 +24,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
Expand All @@ -63,40 +60,37 @@ def _dynamic_lines_generator(self, report, options, all_column_groups_expression
line = self._create_report_line(report, options, move_info, move_id, number_keys)
lines.append((0, line))
# Single total line if only one type of journal is selected
selected_tax_types = self._vat_book_get_selected_tax_types(options)
if len(selected_tax_types) < 2:
total_line = self._create_report_total_line(report, options, total_values_dict)
lines.append((0, total_line))
if len(self._vat_book_get_selected_tax_types(options)) < 2:
lines.append((0, self._create_report_total_line(report, options, total_values_dict)))

return lines

def _custom_options_initializer(self, report, options, previous_options=None):
def _custom_options_initializer(self, report, options, previous_options):
super()._custom_options_initializer(report, options, previous_options=previous_options)
if previous_options is None:
previous_options = {}

options['uy_vat_book_tax_types_available'] = {
'sale': _('Sales'),
'purchase': _('Purchases'),
'all': _('All'),
options['uy_vat_book_tax_types_available'] = previous_options.get('uy_vat_book_tax_types_available') or {
'sale': {'name': _('Sales'), 'selected': True},
'purchase': {'name': _('Purchases'), 'selected': True},
}
if options.get('_running_export_test'):
# Exporting the file is not allowed for 'all'. When executing the export tests, we hence always select 'sales', to avoid raising.
options['uy_vat_book_tax_type_selected'] = 'sale'
else:
options['uy_vat_book_tax_type_selected'] = previous_options.get('uy_vat_book_tax_type_selected', 'all')
# Exporting the file is not allowed for 'purchase'. When executing the export tests, we hence always select 'sales', to avoid raising.
options['uy_vat_book_tax_types_available']['purchase']['selected'] = False

options['forced_domain'] = [
*options.get('forced_domain', []),
('journal_id.l10n_latam_use_documents', '!=', False),
]

####################################################
# REPORT LINES: CORE
####################################################

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
Expand Down Expand Up @@ -145,5 +139,10 @@ def _create_report_total_line(self, report, options, total_vals):

def _vat_book_get_selected_tax_types(self, options):
# If no particular one is selected, then select them all
selected = options['uy_vat_book_tax_type_selected']
return ['sale', 'purchase'] if selected == 'all' else [selected]
selected_types = [
selected_type_key
for selected_type_key, selected_type_value in options['uy_vat_book_tax_types_available'].items()
if selected_type_value['selected']
]

return selected_types if selected_types else ['sale', 'purchase']
36 changes: 22 additions & 14 deletions l10n_uy_reports/report/account_uy_vat_line.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions l10n_uy_reports/report/account_uy_vat_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
</record>

<record id="view_account_uy_vat_line_tree" model="ir.ui.view">
<field name="name">account.uy.vat.line.tree</field>
<field name="name">account.uy.vat.line.list</field>
<field name="model">account.uy.vat.line</field>
<field name="arch" type="xml">
<tree editable="bottom">
<list editable="bottom">
<field name="date"/>
<field name="move_id"/>
<field name="partner_id"/>
Expand All @@ -46,7 +46,7 @@
<field name="other_taxes" sum="Total"/>
<field name="total" sum="Total"/>
<button name="open_journal_entry" string="Open" type="object" icon="fa-external-link" help="Open journal entry"/>
</tree>
</list>
</field>
</record>

Expand All @@ -70,7 +70,7 @@
<record id="action_account_uy_vat_line" model="ir.actions.act_window">
<field name="name">VAT Summary</field>
<field name="res_model">account.uy.vat.line</field>
<field name="view_mode">pivot,tree</field>
<field name="view_mode">pivot,list</field>
<field name="context">{'search_default_posted': 1, 'time_ranges': {'field': 'date', 'range': 'last_month'}}</field>
</record>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="l10n_uy_reports.L10nUyReportsFilterTaxType">
<Dropdown togglerClass="'btn btn-secondary'">
<t t-set-slot="toggler">
<t t-set="taxSelected" t-value="controller.options.uy_vat_book_tax_type_selected"/>
<Dropdown>
<button class="btn btn-secondary">
<span class="fa fa-filter me-1"/>Tax Type: <t t-out="selectedTaxType"/>
</button>

<span class="fa fa-filter me-1"/>Tax Type: <t t-esc="controller.options.uy_vat_book_tax_types_available[taxSelected]"/>
</t>

<t t-foreach="Object.entries(controller.options.uy_vat_book_tax_types_available)" t-as="taxType" t-key="taxType[0]">
<DropdownItem
class="{ 'selected': (controller.options.uy_vat_book_tax_type_selected == taxType[0]) }"
onSelected="() => this.updateFilter('uy_vat_book_tax_type_selected', taxType[0])"
>
<t t-esc="taxType[1]"/>
</DropdownItem>
<t t-set-slot="content">
<t t-foreach="Object.entries(controller.options.uy_vat_book_tax_types_available)" t-as="taxType" t-key="taxType[0]">
<DropdownItem
class="{ 'selected': taxType[1]['selected'] }"
onSelected="() => this.selectUyVatBookTaxType(taxType[0])"
closingMode="'none'"
>
<t t-esc="taxType[1]['name']"/>
</DropdownItem>
</t>
</t>
</Dropdown>
</t>
Expand Down
27 changes: 27 additions & 0 deletions l10n_uy_reports/static/src/components/uruguayan_report/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { _t } from "@web/core/l10n/translation";
import { patch } from "@web/core/utils/patch";
import { AccountReportFilters } from "@account_reports/components/account_report/filters/filters";

patch(AccountReportFilters.prototype, {
get selectedTaxType() {
const availableTypes = Object.keys(this.controller.options.uy_vat_book_tax_types_available);
const selectedTypes = Object.values(
this.controller.options.uy_vat_book_tax_types_available,
).filter((type) => type.selected);

if (selectedTypes.length === availableTypes.length || selectedTypes.length === 0) {
return _t("All");
}

return selectedTypes.map((type) => type.name).join(", ");
},

selectUyVatBookTaxType(taxType) {
const newUyVatBookTaxTypes = Object.assign(
{},
this.controller.options.uy_vat_book_tax_types_available,
);
newUyVatBookTaxTypes[taxType]["selected"] = !newUyVatBookTaxTypes[taxType]["selected"];
this.filterClicked({ optionKey: "uy_vat_book_tax_types_available", optionValue: newUyVatBookTaxTypes, reload: true});
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="l10n_uy_reports.L10nUyReportsFiltersCustomizable" t-inherit="account_reports.AccountReportFiltersCustomizable">
<t t-name="l10n_uy_reports.L10nUyReportsFiltersCustomizable" t-inherit="account_reports.GenericTaxReportFiltersCustomizable">
<xpath expr="//div[@id='filter_variant']" position="after">
<div class="acc_rep_filter_tax_unit">
<t t-call="l10n_uy_reports.L10nUyReportsFilterTaxType"/>
Expand Down
Loading