From d8b95d5e511aafec5526ebe3bc407a7edce079b7 Mon Sep 17 00:00:00 2001 From: Nicolas Mac Rouillon Date: Fri, 6 Sep 2024 09:10:19 -0300 Subject: [PATCH 01/21] [IMP] OCA openupgrade_framework uses --- base/17.0.0.0/pre-0-model-checks.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 base/17.0.0.0/pre-0-model-checks.py diff --git a/base/17.0.0.0/pre-0-model-checks.py b/base/17.0.0.0/pre-0-model-checks.py new file mode 100644 index 0000000..0ced762 --- /dev/null +++ b/base/17.0.0.0/pre-0-model-checks.py @@ -0,0 +1,25 @@ +from odoo import api, models + +from odoo.addons.base.models.ir_model import ( + IrModelSelection, +) + + +def _process_ondelete(self): + """Don't break on missing models when deleting their selection fields""" + to_process = self.browse([]) + for selection in self: + try: + self.env[selection.field_id.model] # pylint: disable=pointless-statement + to_process += selection + except KeyError: + continue + return IrModelSelection._process_ondelete._original_method(to_process) + + +_process_ondelete._original_method = IrModelSelection._process_ondelete +IrModelSelection._process_ondelete = _process_ondelete + + +def migrate(env, version): + pass From 7d996e81a0e8635f66f5c2ec25b9c26cd655f16a Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Wed, 21 Aug 2024 13:48:57 -0300 Subject: [PATCH 02/21] [ADD] l10n_uy_edi: migration scripts --- l10n_uy_edi/17.0.0.0/pre-migration.py | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 l10n_uy_edi/17.0.0.0/pre-migration.py diff --git a/l10n_uy_edi/17.0.0.0/pre-migration.py b/l10n_uy_edi/17.0.0.0/pre-migration.py new file mode 100644 index 0000000..3f4abc8 --- /dev/null +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -0,0 +1,57 @@ +from openupgradelib import openupgrade +import logging +_logger = logging.getLogger(__name__) + + +_table_renames = [ + ('account_move', 'account_move_bu'), + ('l10n.uy.adenda', 'l10n_uy_edi.addenda'), +] + +_field_renames = [ + ('account.move', 'account_move', 'l10n_uy_cfe_state', 'l10n_uy_edi_cfe_state'), + ('account.move', 'account_move', 'l10n_uy_cfe_file', 'l10n_uy_edi_xml_attachment_id'), + ('account.move', 'account_move', 'l10n_uy_cfe_pdf', 'invoice_pdf_report_file'), + ('account.move', 'account_move', 'l10n_uy_cfe_sale_mod', 'l10n_uy_edi_cfe_sale_mode'), + ('account.move', 'account_move', 'l10n_uy_cfe_transport_route', 'l10n_uy_edi_cfe_transport_route'), + + ('account.journal', 'account_journal', 'l10n_uy_type', 'l10n_uy_edi_type'), + + ('res.company', 'res_company', 'l10n_uy_ucfe_env', 'l10n_uy_edi_ucfe_env'), + ('res.company', 'res_company', 'l10n_uy_ucfe_password', 'l10n_uy_edi_ucfe_password'), + ('res.company', 'res_company', 'l10n_uy_ucfe_commerce_code', 'l10n_uy_edi_ucfe_commerce_code'), + ('res.company', 'res_company', 'l10n_uy_ucfe_terminal_code', 'l10n_uy_edi_ucfe_terminal_code'), + ('res.company', 'res_company', 'l10n_uy_dgi_house_code', 'l10n_uy_edi_branch_code'), + ('res.company', 'res_company', 'l10n_uy_adenda_ids', 'l10n_uy_edi_addenda_ids'), + + +@openupgrade.migrate() +def migrate(env, version): + # backup de columnas que nos interesan antes de que se borren + _logger.debug('Running migrate script for l10n_uy_edi') + + # Popular nueva tabla con datos en el account move + openupgrade.logged_query(env.cr, """ + INSERT INTO l10n_uy_edi_document (name, move_id, state, uuid, attachment_id, message) + SELECT + name as name, + id as move_id, + l10n_uy_cfe_state as state, + l10n_uy_cfe_uuid as uuid, + l10n_uy_cfe_file as attachment_id, + l10n_uy_ucfe_msg as message, + FROM account_move move + WHERE move.journal_id.l10n_uy_edi_type == 'electronic' + """) + # TODO + # attachment_file → campo binary. no existe ¿Cómo popular? + # request_datetime (campo requerido, dejar valor por defecto para los viejos?) + + # Agregar relacion entre tabla edi document y move. campo 'l10n_uy_edi_document_id' + openupgrade.logged_query(env.cr, """ + UPDATE account_move move + SET + l10n_uy_edi_document_id = edi.id + FROM l10n_uy_edi_document AS edi + WHERE edi.move_id == move.id' + """) From 74c870a4afa39073a42d7139a2b8b1b2c7d58e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Scarafia?= Date: Wed, 21 Aug 2024 15:12:28 -0300 Subject: [PATCH 03/21] [REF] --- l10n_uy/17.0.0.0/pre-migration.py | 17 ++++++ l10n_uy_edi/17.0.0.0/post-migration.py | 67 ++++++++++++++++++++++++ l10n_uy_edi/17.0.0.0/pre-migration.py | 72 ++++++++++++++++---------- 3 files changed, 130 insertions(+), 26 deletions(-) create mode 100644 l10n_uy/17.0.0.0/pre-migration.py create mode 100644 l10n_uy_edi/17.0.0.0/post-migration.py diff --git a/l10n_uy/17.0.0.0/pre-migration.py b/l10n_uy/17.0.0.0/pre-migration.py new file mode 100644 index 0000000..f6fe315 --- /dev/null +++ b/l10n_uy/17.0.0.0/pre-migration.py @@ -0,0 +1,17 @@ +from openupgradelib import openupgrade +import logging +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + + # TODO hacer los rename + _xmlid_renames = [ + ('l10n_uy.tax_group_vat_22', 'l10n_uy.[COMPLETAR]'), + ... + ('l10n_uy.adenda_exoneracion_impuesto_renta', 'l10n_uy_edi_ux.adenda_exoneracion_impuesto_renta'), + ... + ] + + openupgrade.rename_xmlids(env.cr, _xmlid_renames) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py new file mode 100644 index 0000000..0112eb6 --- /dev/null +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -0,0 +1,67 @@ +from openupgradelib import openupgrade +import logging +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + # Popular nueva tabla con datos en el account move + openupgrade.logged_query(env.cr, """ + INSERT INTO l10n_uy_edi_document (name, move_id, state, uuid, attachment_id, message) + SELECT + name as name, + id as move_id, + l10n_uy_cfe_state_bu as state, + l10n_uy_cfe_uuid_bu as uuid, + l10n_uy_ucfe_msg_bu as message + FROM account_move move + WHERE move.journal_id.l10n_uy_edi_type == 'electronic' + """) + + # l10n_uy_cfe_file_bu as attachment_id, + # TODO + # attachment_file → campo binary. no existe ¿Cómo popular? + # request_datetime (campo requerido, dejar valor por defecto para los viejos?) + + # Agregar relacion entre tabla edi document y move. campo 'l10n_uy_edi_document_id' + openupgrade.logged_query(env.cr, """ + UPDATE account_move move + SET + l10n_uy_edi_document_id = edi.id + FROM l10n_uy_edi_document AS edi + WHERE edi.move_id == move.id + """) + + # convertimos nuestro "l10n_uy_cfe_file_bu" m2o a ir.attachment a un campo binary "attachment_file" + for move in electronic_move_with_l10n_uy_cfe_file_bu: + move.l10n_uy_cfe_file_bu.write({ + 'res_id': move.l10n_uy_edi_document_id.id, + # lo del name podria ser evitable + 'name': move.l10n_uy_edi_document_id._get_xml_attachment_name(), + 'res_model': 'l10n_uy_edi.document', + 'res_field': 'attachment_file', + }) + + # TODO implementar + # logged_query + # insert into adendas SELECT + # name as name, + # select l10n_uy_additional_info_bu from account_move where l10n_uy_additional_info_bu is not null + + # TODO implementar para este caso de partners tmb l10n_uy_additional_info + # logged_query + # insert into adendas SELECT + # name as name, + # select l10n_uy_additional_info_bu from account_move where l10n_uy_additional_info_bu is not null + + env[res.company].search(l10n_uy_edi_ucfe_env = False).l10n_uy_edi_ucfe_env = 'demo' + env[adenda].search(name like '{').is_legend = True + + # update account_tax set l10n_uy_tax_category = bla from tax_group where + # tax.tax_group_id = tax_group.id + # and l10n_uy_tax_category_bu is not null + + + env.ref('l10n_uy_edi.ir_cron_get_ucfe_notif').unlink() + # lo re-creamos + env.ref('l10n_uy_edi.ir_cron_get_vendor_bills_received').unlink() diff --git a/l10n_uy_edi/17.0.0.0/pre-migration.py b/l10n_uy_edi/17.0.0.0/pre-migration.py index 3f4abc8..8e9205e 100644 --- a/l10n_uy_edi/17.0.0.0/pre-migration.py +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -3,11 +3,29 @@ _logger = logging.getLogger(__name__) +# adenda viene de l10n_uy_account pero ahora esta en l10n_uy_edi, no deberia haber problemas de que lo hagamos todo aca +# porque el borrado de lo que no va odoo lo hace al final _table_renames = [ - ('account_move', 'account_move_bu'), + ('l10n_uy_adenda', 'l10n_uy_edi_addenda'), +] + +_model_renames = [ ('l10n.uy.adenda', 'l10n_uy_edi.addenda'), ] +_column_copy = { + 'account_move': [ + ('l10n_uy_cfe_state', 'l10n_uy_cfe_state_bu', None), + ('l10n_uy_cfe_uuid', 'l10n_uy_cfe_uuid_bu', None), + ('l10n_uy_cfe_file', 'l10n_uy_cfe_file_bu', None), + ('l10n_uy_ucfe_msg', 'l10n_uy_ucfe_msg_bu', None), + ('l10n_uy_additional_info', 'l10n_uy_additional_info_bu', None), + ], + 'account_tax_group': [ + ('l10n_uy_vat_code', 'l10n_uy_vat_code_bu', None), + ], +} + _field_renames = [ ('account.move', 'account_move', 'l10n_uy_cfe_state', 'l10n_uy_edi_cfe_state'), ('account.move', 'account_move', 'l10n_uy_cfe_file', 'l10n_uy_edi_xml_attachment_id'), @@ -24,34 +42,36 @@ ('res.company', 'res_company', 'l10n_uy_dgi_house_code', 'l10n_uy_edi_branch_code'), ('res.company', 'res_company', 'l10n_uy_adenda_ids', 'l10n_uy_edi_addenda_ids'), + ('l10n_uy_edi.addenda', 'l10n_uy_edi_addenda', 'legend_type', 'type'), +] + @openupgrade.migrate() def migrate(env, version): # backup de columnas que nos interesan antes de que se borren _logger.debug('Running migrate script for l10n_uy_edi') - # Popular nueva tabla con datos en el account move - openupgrade.logged_query(env.cr, """ - INSERT INTO l10n_uy_edi_document (name, move_id, state, uuid, attachment_id, message) - SELECT - name as name, - id as move_id, - l10n_uy_cfe_state as state, - l10n_uy_cfe_uuid as uuid, - l10n_uy_cfe_file as attachment_id, - l10n_uy_ucfe_msg as message, - FROM account_move move - WHERE move.journal_id.l10n_uy_edi_type == 'electronic' - """) - # TODO - # attachment_file → campo binary. no existe ¿Cómo popular? - # request_datetime (campo requerido, dejar valor por defecto para los viejos?) - - # Agregar relacion entre tabla edi document y move. campo 'l10n_uy_edi_document_id' - openupgrade.logged_query(env.cr, """ - UPDATE account_move move - SET - l10n_uy_edi_document_id = edi.id - FROM l10n_uy_edi_document AS edi - WHERE edi.move_id == move.id' - """) + openupgrade.rename_models(env.cr, _model_renames) + + for old_table, new_table in _table_renames: + if openupgrade.table_exists(env.cr, old_table): + openupgrade.rename_tables(env.cr, [(old_table, new_table)]) + + openupgrade.copy_columns(env.cr, _column_copy) + + openupgrade.rename_fields(env, _field_renames) + + # TODO implementar algo asi (los que se tienen que limpiar dejarlos en null) + openupgrade.logged_query(env.cr, "query") + # update account_move set state = xml_error where not_apply + # Quitamos opciones opciones + # Lo que era 'xml_error', 'connection_error', 'ucfe_error' ahora sería "error" + # Lo que era 'not_apply', 'draft_cfe' poner vacio + + # TODO implementar query de actualizar esto, tal vez en post vaya bien? + # legend_type → type + # Cambiaron opciones + # 'emisor' →"issuer" + # 'receptor' → "receiver" + # 'comprobante' → "cfe_doc" + # 'adenda' → "addenda" From f98e474248da460497767fe36c5096b98c3aa604 Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Tue, 3 Sep 2024 11:36:24 -0300 Subject: [PATCH 04/21] [REF] l10n_uy, l10n_uy: cambios en el pre-migration.py de l10n_uy y en el post de l10n_uy_edi --- l10n_uy/17.0.0.0/pre-migration.py | 6 +-- l10n_uy_edi/17.0.0.0/post-migration.py | 63 +++++++++++++++++++++++++- l10n_uy_edi/17.0.0.0/pre-migration.py | 4 +- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/l10n_uy/17.0.0.0/pre-migration.py b/l10n_uy/17.0.0.0/pre-migration.py index f6fe315..eb691ff 100644 --- a/l10n_uy/17.0.0.0/pre-migration.py +++ b/l10n_uy/17.0.0.0/pre-migration.py @@ -8,10 +8,10 @@ def migrate(env, version): # TODO hacer los rename _xmlid_renames = [ - ('l10n_uy.tax_group_vat_22', 'l10n_uy.[COMPLETAR]'), - ... + ('l10n_uy.tax_group_vat_22', 'l10n_uy.tax_group_iva_22'), + ('l10n_uy.tax_group_vat_10', 'l10n_uy.tax_group_iva_10'), + ('l10n_uy.tax_group_vat_exempt', 'l10n_uy.tax_group_exenton'), ('l10n_uy.adenda_exoneracion_impuesto_renta', 'l10n_uy_edi_ux.adenda_exoneracion_impuesto_renta'), - ... ] openupgrade.rename_xmlids(env.cr, _xmlid_renames) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 0112eb6..0f9a25e 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -32,6 +32,65 @@ def migrate(env, version): WHERE edi.move_id == move.id """) + # update account_move set state = xml_error where not_apply + # Quitamos opciones opciones + # Lo que era 'xml_error', 'connection_error', 'ucfe_error' ahora sería "error" + # Lo que era 'not_apply', 'draft_cfe' poner vacio + openupgrade.logged_query(env.cr, """ + UPDATE account_move + SET + l10n_uy_edi_cfe_state = 'error' + FROM account_move + WHERE l10n_uy_cfe_state_bu IN ('xml_error', 'connection_error', 'ucfe_error'); + """) + + openupgrade.logged_query(env.cr, """ + UPDATE account_move + SET + l10n_uy_edi_cfe_state = Null + FROM account_move + WHERE l10n_uy_cfe_state_bu IN ('not_apply', 'draft_cfe'); + """) + + # TODO implementar query de actualizar esto, tal vez en post vaya bien? + # legend_type → type + # Cambiaron opciones + # 'emisor' →"issuer" + # 'receptor' → "receiver" + # 'comprobante' → "cfe_doc" + # 'adenda' → "addenda" + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'issuer' + FROM l10n_uy_edi_addenda + WHERE type = 'emisor' + """) + + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'receiver' + FROM l10n_uy_edi_addenda + WHERE type = 'receptor' + """) + + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'cfe_doc' + FROM l10n_uy_edi_addenda + WHERE type = 'comprobante' + """) + + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'addenda' + FROM l10n_uy_edi_addenda + WHERE type = 'adenda' + """) + # convertimos nuestro "l10n_uy_cfe_file_bu" m2o a ir.attachment a un campo binary "attachment_file" for move in electronic_move_with_l10n_uy_cfe_file_bu: move.l10n_uy_cfe_file_bu.write({ @@ -54,8 +113,8 @@ def migrate(env, version): # name as name, # select l10n_uy_additional_info_bu from account_move where l10n_uy_additional_info_bu is not null - env[res.company].search(l10n_uy_edi_ucfe_env = False).l10n_uy_edi_ucfe_env = 'demo' - env[adenda].search(name like '{').is_legend = True + env['res.company'].search(l10n_uy_edi_ucfe_env = False).l10n_uy_edi_ucfe_env = 'demo' + env['l10n_uy_edi.addenda'].search(name like '{').is_legend = True # update account_tax set l10n_uy_tax_category = bla from tax_group where # tax.tax_group_id = tax_group.id diff --git a/l10n_uy_edi/17.0.0.0/pre-migration.py b/l10n_uy_edi/17.0.0.0/pre-migration.py index 8e9205e..bb5d3a2 100644 --- a/l10n_uy_edi/17.0.0.0/pre-migration.py +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -20,6 +20,7 @@ ('l10n_uy_cfe_file', 'l10n_uy_cfe_file_bu', None), ('l10n_uy_ucfe_msg', 'l10n_uy_ucfe_msg_bu', None), ('l10n_uy_additional_info', 'l10n_uy_additional_info_bu', None), + ('l10n_uy_cfe_pdf', 'l10n_uy_cfe_pdf_bu', None), ], 'account_tax_group': [ ('l10n_uy_vat_code', 'l10n_uy_vat_code_bu', None), @@ -29,7 +30,6 @@ _field_renames = [ ('account.move', 'account_move', 'l10n_uy_cfe_state', 'l10n_uy_edi_cfe_state'), ('account.move', 'account_move', 'l10n_uy_cfe_file', 'l10n_uy_edi_xml_attachment_id'), - ('account.move', 'account_move', 'l10n_uy_cfe_pdf', 'invoice_pdf_report_file'), ('account.move', 'account_move', 'l10n_uy_cfe_sale_mod', 'l10n_uy_edi_cfe_sale_mode'), ('account.move', 'account_move', 'l10n_uy_cfe_transport_route', 'l10n_uy_edi_cfe_transport_route'), @@ -62,7 +62,7 @@ def migrate(env, version): openupgrade.rename_fields(env, _field_renames) # TODO implementar algo asi (los que se tienen que limpiar dejarlos en null) - openupgrade.logged_query(env.cr, "query") + # openupgrade.logged_query(env.cr, query) # update account_move set state = xml_error where not_apply # Quitamos opciones opciones # Lo que era 'xml_error', 'connection_error', 'ucfe_error' ahora sería "error" From 9634c4b69d4effecd1e3cec1be4a9d66a7098504 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Tue, 17 Sep 2024 12:53:40 -0300 Subject: [PATCH 05/21] Agrego columnas de infor adicional de los partners y productos para las querys posteriores --- l10n_uy_edi/17.0.0.0/pre-migration.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/pre-migration.py b/l10n_uy_edi/17.0.0.0/pre-migration.py index bb5d3a2..501c215 100644 --- a/l10n_uy_edi/17.0.0.0/pre-migration.py +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -25,6 +25,12 @@ 'account_tax_group': [ ('l10n_uy_vat_code', 'l10n_uy_vat_code_bu', None), ], + 'product_product' : [ + ('l10n_uy_additional_info', 'l10n_uy_additional_info_pro_bu', None), + ], + 'res_partner' : [ + ('l10n_uy_additional_info', 'l10n_uy_additional_info_part_bu', None), + ] } _field_renames = [ @@ -60,18 +66,3 @@ def migrate(env, version): openupgrade.copy_columns(env.cr, _column_copy) openupgrade.rename_fields(env, _field_renames) - - # TODO implementar algo asi (los que se tienen que limpiar dejarlos en null) - # openupgrade.logged_query(env.cr, query) - # update account_move set state = xml_error where not_apply - # Quitamos opciones opciones - # Lo que era 'xml_error', 'connection_error', 'ucfe_error' ahora sería "error" - # Lo que era 'not_apply', 'draft_cfe' poner vacio - - # TODO implementar query de actualizar esto, tal vez en post vaya bien? - # legend_type → type - # Cambiaron opciones - # 'emisor' →"issuer" - # 'receptor' → "receiver" - # 'comprobante' → "cfe_doc" - # 'adenda' → "addenda" From 5c50456afc4ada116dd56f5e3574fd360763759f Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Tue, 17 Sep 2024 13:54:27 -0300 Subject: [PATCH 06/21] Error en querys de addendas --- l10n_uy_edi/17.0.0.0/post-migration.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 0f9a25e..b5a055f 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -63,7 +63,6 @@ def migrate(env, version): UPDATE l10n_uy_edi_addenda SET type = 'issuer' - FROM l10n_uy_edi_addenda WHERE type = 'emisor' """) @@ -71,7 +70,6 @@ def migrate(env, version): UPDATE l10n_uy_edi_addenda SET type = 'receiver' - FROM l10n_uy_edi_addenda WHERE type = 'receptor' """) @@ -79,7 +77,6 @@ def migrate(env, version): UPDATE l10n_uy_edi_addenda SET type = 'cfe_doc' - FROM l10n_uy_edi_addenda WHERE type = 'comprobante' """) @@ -87,7 +84,6 @@ def migrate(env, version): UPDATE l10n_uy_edi_addenda SET type = 'addenda' - FROM l10n_uy_edi_addenda WHERE type = 'adenda' """) From d52248ed7116bcfb69e8316869e6cabee6a37fac Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Tue, 17 Sep 2024 14:10:44 -0300 Subject: [PATCH 07/21] Limpio los comentarios y los TODO que ya se realizaron --- l10n_uy_edi/17.0.0.0/post-migration.py | 36 +++----------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index b5a055f..0075bf8 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -32,15 +32,11 @@ def migrate(env, version): WHERE edi.move_id == move.id """) - # update account_move set state = xml_error where not_apply - # Quitamos opciones opciones - # Lo que era 'xml_error', 'connection_error', 'ucfe_error' ahora sería "error" - # Lo que era 'not_apply', 'draft_cfe' poner vacio + #Actualizamos los select de los estados del cfe openupgrade.logged_query(env.cr, """ UPDATE account_move SET l10n_uy_edi_cfe_state = 'error' - FROM account_move WHERE l10n_uy_cfe_state_bu IN ('xml_error', 'connection_error', 'ucfe_error'); """) @@ -48,17 +44,10 @@ def migrate(env, version): UPDATE account_move SET l10n_uy_edi_cfe_state = Null - FROM account_move WHERE l10n_uy_cfe_state_bu IN ('not_apply', 'draft_cfe'); """) - # TODO implementar query de actualizar esto, tal vez en post vaya bien? - # legend_type → type - # Cambiaron opciones - # 'emisor' →"issuer" - # 'receptor' → "receiver" - # 'comprobante' → "cfe_doc" - # 'adenda' → "addenda" + #Cambiamos los type de addendas openupgrade.logged_query(env.cr, """ UPDATE l10n_uy_edi_addenda SET @@ -97,25 +86,8 @@ def migrate(env, version): 'res_field': 'attachment_file', }) - # TODO implementar - # logged_query - # insert into adendas SELECT - # name as name, - # select l10n_uy_additional_info_bu from account_move where l10n_uy_additional_info_bu is not null - - # TODO implementar para este caso de partners tmb l10n_uy_additional_info - # logged_query - # insert into adendas SELECT - # name as name, - # select l10n_uy_additional_info_bu from account_move where l10n_uy_additional_info_bu is not null - - env['res.company'].search(l10n_uy_edi_ucfe_env = False).l10n_uy_edi_ucfe_env = 'demo' - env['l10n_uy_edi.addenda'].search(name like '{').is_legend = True - - # update account_tax set l10n_uy_tax_category = bla from tax_group where - # tax.tax_group_id = tax_group.id - # and l10n_uy_tax_category_bu is not null - + env['res.company'].search([('l10n_uy_edi_ucfe_env', '=', False)]).l10n_uy_edi_ucfe_env = 'demo' + env['l10n_uy_edi.addenda'].search([('content', 'like', '{%}')]).is_legend = True env.ref('l10n_uy_edi.ir_cron_get_ucfe_notif').unlink() # lo re-creamos From 17d07239a361a2f7151e7ddee20b3c753e56dd2d Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Tue, 17 Sep 2024 15:20:28 -0300 Subject: [PATCH 08/21] Test y cambios en las tablas para generar y vincular los attachment --- l10n_uy_edi/17.0.0.0/post-migration.py | 34 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 0075bf8..87ccd49 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -5,18 +5,34 @@ @openupgrade.migrate() def migrate(env, version): + # Popular nueva tabla con datos en el account move openupgrade.logged_query(env.cr, """ - INSERT INTO l10n_uy_edi_document (name, move_id, state, uuid, attachment_id, message) - SELECT - name as name, - id as move_id, - l10n_uy_cfe_state_bu as state, - l10n_uy_cfe_uuid_bu as uuid, - l10n_uy_ucfe_msg_bu as message - FROM account_move move - WHERE move.journal_id.l10n_uy_edi_type == 'electronic' + INSERT INTO l10n_uy_edi_document (move_id, state, uuid, message, request_datetime) + SELECT + move.id as move_id, + move.l10n_uy_cfe_state_bu as state, + move.l10n_uy_cfe_uuid_bu as uuid, + move.l10n_uy_ucfe_msg_bu as message, + TO_TIMESTAMP(TO_CHAR(NOW(), 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') as request_datetime + FROM account_move move + JOIN account_journal journal ON move.journal_id = journal.id + WHERE journal.l10n_uy_edi_type = 'electronic' AND move.l10n_uy_cfe_state_bu NOTNULL + """) + + openupgrade.logged_query(env.cr, """ + UPDATE ir_attachment SET + res_id = subc.edi_id, + res_model = 'l10n_uy_edi.document', + res_field = 'attachment_file' + FROM (SELECT edi_doc.id AS edi_id, edi_doc.move_id from l10n_uy_edi_document edi_doc JOIN account_move ON account_move.id = edi_doc.move_id) as subc + WHERE subc.move_id = res_id AND name like '%.xml'; """) + + for rec in env['l10n_uy_edi.document'].search([]): + datas = env['ir.attachment'].search([('res_id', '=', rec.id), ('res_model', '=', 'l10n_uy_edi.document')]).datas + if datas: + rec.attachment_file = datas # l10n_uy_cfe_file_bu as attachment_id, # TODO From c9fff99d7656b1f3e5ce3cdad31fb085ef2dba52 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Tue, 17 Sep 2024 15:36:31 -0300 Subject: [PATCH 09/21] Testeo de querys adenda y limpieza de codigo --- l10n_uy_edi/17.0.0.0/post-migration.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 87ccd49..44f462d 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -5,7 +5,6 @@ @openupgrade.migrate() def migrate(env, version): - # Popular nueva tabla con datos en el account move openupgrade.logged_query(env.cr, """ INSERT INTO l10n_uy_edi_document (move_id, state, uuid, message, request_datetime) @@ -34,11 +33,6 @@ def migrate(env, version): if datas: rec.attachment_file = datas - # l10n_uy_cfe_file_bu as attachment_id, - # TODO - # attachment_file → campo binary. no existe ¿Cómo popular? - # request_datetime (campo requerido, dejar valor por defecto para los viejos?) - # Agregar relacion entre tabla edi document y move. campo 'l10n_uy_edi_document_id' openupgrade.logged_query(env.cr, """ UPDATE account_move move @@ -48,7 +42,7 @@ def migrate(env, version): WHERE edi.move_id == move.id """) - #Actualizamos los select de los estados del cfe + # Actualizamos los select de los estados del cfe openupgrade.logged_query(env.cr, """ UPDATE account_move SET @@ -63,7 +57,7 @@ def migrate(env, version): WHERE l10n_uy_cfe_state_bu IN ('not_apply', 'draft_cfe'); """) - #Cambiamos los type de addendas + # Cambios en las addendas openupgrade.logged_query(env.cr, """ UPDATE l10n_uy_edi_addenda SET @@ -92,19 +86,12 @@ def migrate(env, version): WHERE type = 'adenda' """) - # convertimos nuestro "l10n_uy_cfe_file_bu" m2o a ir.attachment a un campo binary "attachment_file" - for move in electronic_move_with_l10n_uy_cfe_file_bu: - move.l10n_uy_cfe_file_bu.write({ - 'res_id': move.l10n_uy_edi_document_id.id, - # lo del name podria ser evitable - 'name': move.l10n_uy_edi_document_id._get_xml_attachment_name(), - 'res_model': 'l10n_uy_edi.document', - 'res_field': 'attachment_file', - }) + env['l10n_uy_edi.addenda'].search([('content', 'like', '{%}')]).is_legend = True + # Seteamos los ambientes env['res.company'].search([('l10n_uy_edi_ucfe_env', '=', False)]).l10n_uy_edi_ucfe_env = 'demo' - env['l10n_uy_edi.addenda'].search([('content', 'like', '{%}')]).is_legend = True + + # Los re-creamos env.ref('l10n_uy_edi.ir_cron_get_ucfe_notif').unlink() - # lo re-creamos env.ref('l10n_uy_edi.ir_cron_get_vendor_bills_received').unlink() From a7f5dc9d7a1dafc91d683e810edccbf4b979b410 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Tue, 17 Sep 2024 17:04:09 -0300 Subject: [PATCH 10/21] Creamos los registros de las adendas desde los partners y productos, testeamos las querys de impuestos --- l10n_uy_edi/17.0.0.0/post-migration.py | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 44f462d..666108c 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -86,8 +86,66 @@ def migrate(env, version): WHERE type = 'adenda' """) + #TODO opcional: vincular las adendas con las facturas + openupgrade.logged_query(env.cr, """ + INSERT INTO l10n_uy_edi_addenda (name, type, content, company_id) + SELECT + move.l10n_uy_additional_info_bu AS name, + 'cfe_doc' AS type, + move.l10n_uy_additional_info_bu AS content, + move.company_id AS company_id + FROM account_move move + WHERE move.l10n_uy_additional_info_bu NOTNULL + """) + + openupgrade.logged_query(env.cr, """ + INSERT INTO l10n_uy_edi_addenda (name, type, content) + SELECT + product.l10n_uy_additional_info_pro_bu AS name, + 'item' AS type, + product.l10n_uy_additional_info_pro_bu AS content + -- product.product_tmpl_id.company_id AS company_id + FROM product_product product + WHERE product.l10n_uy_additional_info_pro_bu NOTNULL + """) + + openupgrade.logged_query(env.cr, """ + INSERT INTO l10n_uy_edi_addenda (name, type, content, company_id) + SELECT + partner.l10n_uy_additional_info_part_bu AS name, + 'receiver' AS type, + partner.l10n_uy_additional_info_part_bu AS content, + partner.company_id AS company_id + FROM res_partner partner + WHERE partner.l10n_uy_additional_info_part_bu NOTNULL + """) + env['l10n_uy_edi.addenda'].search([('content', 'like', '{%}')]).is_legend = True + # Impuestos TERMINAR + # openupgrade.logged_query(env.cr, """ + # UPDATE account_tax SET + # l10n_uy_tax_category = 'vat' + # FROM + # (SELECT ARRAY_AGG(tax.id) AS tax_ids + # FROM account_tax_group AS tax_group + # INNER JOIN account_tax AS tax + # ON tax_group.id = tax.tax_group_id + # WHERE tax_group.l10n_uy_vat_code_bu NOTNULL) as subc + # WHERE account_tax.id IN subc.tax_ids + # """) + + # query= f""" + # SELECT tax.id + # FROM account_tax_group AS tax_group + # INNER JOIN account_tax AS tax + # ON tax_group.id = tax.tax_group_id + # WHERE tax_group.l10n_uy_vat_code_bu NOTNULL + # """ + # env._cr.execute(query) + # tax_ids = [tax.get('id') for tax in env._cr.dictfetchall()] + # env['account.tax'].browse(tax_ids).write({'l10n_uy_tax_category': 'vat'}) + # Seteamos los ambientes env['res.company'].search([('l10n_uy_edi_ucfe_env', '=', False)]).l10n_uy_edi_ucfe_env = 'demo' From 0994ec4a1fd86878bd49e6ee856d733a0afb23a4 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Wed, 18 Sep 2024 15:53:05 -0300 Subject: [PATCH 11/21] Terminamos de corregir los seteos de impuestos --- l10n_uy_edi/17.0.0.0/post-migration.py | 34 +++++++++----------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 666108c..a57d622 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -122,29 +122,17 @@ def migrate(env, version): env['l10n_uy_edi.addenda'].search([('content', 'like', '{%}')]).is_legend = True - # Impuestos TERMINAR - # openupgrade.logged_query(env.cr, """ - # UPDATE account_tax SET - # l10n_uy_tax_category = 'vat' - # FROM - # (SELECT ARRAY_AGG(tax.id) AS tax_ids - # FROM account_tax_group AS tax_group - # INNER JOIN account_tax AS tax - # ON tax_group.id = tax.tax_group_id - # WHERE tax_group.l10n_uy_vat_code_bu NOTNULL) as subc - # WHERE account_tax.id IN subc.tax_ids - # """) - - # query= f""" - # SELECT tax.id - # FROM account_tax_group AS tax_group - # INNER JOIN account_tax AS tax - # ON tax_group.id = tax.tax_group_id - # WHERE tax_group.l10n_uy_vat_code_bu NOTNULL - # """ - # env._cr.execute(query) - # tax_ids = [tax.get('id') for tax in env._cr.dictfetchall()] - # env['account.tax'].browse(tax_ids).write({'l10n_uy_tax_category': 'vat'}) + #Impuestos + query= f""" + SELECT tax.id + FROM account_tax_group AS tax_group + INNER JOIN account_tax AS tax + ON tax_group.id = tax.tax_group_id + WHERE tax_group.l10n_uy_vat_code_bu NOTNULL + """ + env.cr.execute(query) + tax_ids = [tax.get('id') for tax in env.cr.dictfetchall()] + env['account.tax'].browse(tax_ids).write({'l10n_uy_tax_category': 'vat'}) # Seteamos los ambientes env['res.company'].search([('l10n_uy_edi_ucfe_env', '=', False)]).l10n_uy_edi_ucfe_env = 'demo' From d390f45d4af37e9892bb2c4389ef21eccfad0d82 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Tue, 24 Sep 2024 15:44:32 -0300 Subject: [PATCH 12/21] Cambiamos nombre de carpeta para que lo tome el request que tenemos en adhoc, agregamos algunos loggers --- l10n_uy/17.0.0.0/pre-migration.py | 2 +- l10n_uy_edi/{17.0.0.0 => 17.0.1.0}/post-migration.py | 1 + l10n_uy_edi/{17.0.0.0 => 17.0.1.0}/pre-migration.py | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename l10n_uy_edi/{17.0.0.0 => 17.0.1.0}/post-migration.py (98%) rename l10n_uy_edi/{17.0.0.0 => 17.0.1.0}/pre-migration.py (100%) diff --git a/l10n_uy/17.0.0.0/pre-migration.py b/l10n_uy/17.0.0.0/pre-migration.py index eb691ff..1cbc877 100644 --- a/l10n_uy/17.0.0.0/pre-migration.py +++ b/l10n_uy/17.0.0.0/pre-migration.py @@ -5,7 +5,7 @@ @openupgrade.migrate() def migrate(env, version): - + _logger.debug('Running pre-migrate script for l10n_uy') # TODO hacer los rename _xmlid_renames = [ ('l10n_uy.tax_group_vat_22', 'l10n_uy.tax_group_iva_22'), diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.1.0/post-migration.py similarity index 98% rename from l10n_uy_edi/17.0.0.0/post-migration.py rename to l10n_uy_edi/17.0.1.0/post-migration.py index a57d622..999c1ba 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.1.0/post-migration.py @@ -5,6 +5,7 @@ @openupgrade.migrate() def migrate(env, version): + _logger.debug('Running post-migrate script for l10n_uy_edi') # Popular nueva tabla con datos en el account move openupgrade.logged_query(env.cr, """ INSERT INTO l10n_uy_edi_document (move_id, state, uuid, message, request_datetime) diff --git a/l10n_uy_edi/17.0.0.0/pre-migration.py b/l10n_uy_edi/17.0.1.0/pre-migration.py similarity index 100% rename from l10n_uy_edi/17.0.0.0/pre-migration.py rename to l10n_uy_edi/17.0.1.0/pre-migration.py From 0c2b62bf6aa7e04ddf22cff8f90f123b8a59c8a6 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Wed, 25 Sep 2024 12:39:29 -0300 Subject: [PATCH 13/21] Rollback del cambio de version en la carpeta de l10n_uy_edi mas cambio en los loggers --- l10n_uy/17.0.0.0/pre-migration.py | 2 +- l10n_uy_edi/{17.0.1.0 => 17.0.0.0}/post-migration.py | 9 ++++++++- l10n_uy_edi/{17.0.1.0 => 17.0.0.0}/pre-migration.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) rename l10n_uy_edi/{17.0.1.0 => 17.0.0.0}/post-migration.py (95%) rename l10n_uy_edi/{17.0.1.0 => 17.0.0.0}/pre-migration.py (97%) diff --git a/l10n_uy/17.0.0.0/pre-migration.py b/l10n_uy/17.0.0.0/pre-migration.py index 1cbc877..f86565f 100644 --- a/l10n_uy/17.0.0.0/pre-migration.py +++ b/l10n_uy/17.0.0.0/pre-migration.py @@ -5,7 +5,7 @@ @openupgrade.migrate() def migrate(env, version): - _logger.debug('Running pre-migrate script for l10n_uy') + _logger.info('Running pre-migrate script for l10n_uy') # TODO hacer los rename _xmlid_renames = [ ('l10n_uy.tax_group_vat_22', 'l10n_uy.tax_group_iva_22'), diff --git a/l10n_uy_edi/17.0.1.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py similarity index 95% rename from l10n_uy_edi/17.0.1.0/post-migration.py rename to l10n_uy_edi/17.0.0.0/post-migration.py index 999c1ba..3fbe61c 100644 --- a/l10n_uy_edi/17.0.1.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -5,7 +5,7 @@ @openupgrade.migrate() def migrate(env, version): - _logger.debug('Running post-migrate script for l10n_uy_edi') + _logger.info('Running post-migrate script for l10n_uy_edi') # Popular nueva tabla con datos en el account move openupgrade.logged_query(env.cr, """ INSERT INTO l10n_uy_edi_document (move_id, state, uuid, message, request_datetime) @@ -43,6 +43,13 @@ def migrate(env, version): WHERE edi.move_id == move.id """) + openupgrade.logged_query(env.cr, """ + UPDATE account_journal + SET + l10n_uy_edi_type = 'manual' + WHERE l10n_uy_edi_type = 'preprinted' + """) + # Actualizamos los select de los estados del cfe openupgrade.logged_query(env.cr, """ UPDATE account_move diff --git a/l10n_uy_edi/17.0.1.0/pre-migration.py b/l10n_uy_edi/17.0.0.0/pre-migration.py similarity index 97% rename from l10n_uy_edi/17.0.1.0/pre-migration.py rename to l10n_uy_edi/17.0.0.0/pre-migration.py index 501c215..20c4c3f 100644 --- a/l10n_uy_edi/17.0.1.0/pre-migration.py +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -55,7 +55,7 @@ @openupgrade.migrate() def migrate(env, version): # backup de columnas que nos interesan antes de que se borren - _logger.debug('Running migrate script for l10n_uy_edi') + _logger.info('Running migrate script for l10n_uy_edi') openupgrade.rename_models(env.cr, _model_renames) From 5a910c99d3a201ce401d561b30b53cfd9aac65d8 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Mon, 21 Oct 2024 09:38:58 -0300 Subject: [PATCH 14/21] Corregimos la query --- l10n_uy_edi/17.0.0.0/post-migration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 3fbe61c..5349ebb 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -40,7 +40,7 @@ def migrate(env, version): SET l10n_uy_edi_document_id = edi.id FROM l10n_uy_edi_document AS edi - WHERE edi.move_id == move.id + WHERE edi.move_id = move.id """) openupgrade.logged_query(env.cr, """ From 4d276e8aa34ef3c0bff39953ccb6a6b0f9bb3837 Mon Sep 17 00:00:00 2001 From: Maximiliano Mezzavilla Date: Fri, 25 Oct 2024 09:21:22 -0300 Subject: [PATCH 15/21] Hacemos un check para evitar el piedrazo --- l10n_uy_edi/17.0.0.0/post-migration.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index 5349ebb..e48fc36 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -147,5 +147,8 @@ def migrate(env, version): # Los re-creamos - env.ref('l10n_uy_edi.ir_cron_get_ucfe_notif').unlink() - env.ref('l10n_uy_edi.ir_cron_get_vendor_bills_received').unlink() + cron_ucfe_notif = env.ref('l10n_uy_edi.ir_cron_get_ucfe_notif', raise_if_not_found=False) + cron_vendor_bills_received = env.ref('l10n_uy_edi.ir_cron_get_vendor_bills_received', raise_if_not_found=False) + + cron_ucfe_notif.unlink() if cron_ucfe_notif else False + cron_vendor_bills_received.unlink() if cron_vendor_bills_received else False From 899fd885895ad52b83cb1750a726ecb1f48d8e8c Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Fri, 22 Nov 2024 17:03:20 -0300 Subject: [PATCH 16/21] [FIX] l10n_uy_edi: missing rename fields Fiels on res.company. Are the ones that store the data to connect both test and prod environment --- l10n_uy_edi/17.0.0.0/pre-migration.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/l10n_uy_edi/17.0.0.0/pre-migration.py b/l10n_uy_edi/17.0.0.0/pre-migration.py index 20c4c3f..e0aa4a8 100644 --- a/l10n_uy_edi/17.0.0.0/pre-migration.py +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -47,6 +47,8 @@ ('res.company', 'res_company', 'l10n_uy_ucfe_terminal_code', 'l10n_uy_edi_ucfe_terminal_code'), ('res.company', 'res_company', 'l10n_uy_dgi_house_code', 'l10n_uy_edi_branch_code'), ('res.company', 'res_company', 'l10n_uy_adenda_ids', 'l10n_uy_edi_addenda_ids'), + ('res.company', 'res_company', 'l10n_uy_ucfe_prod_env', 'l10n_uy_edi_ucfe_prod_env'), + ('res.company', 'res_company', 'l10n_uy_ucfe_test_env', 'l10n_uy_edi_ucfe_test_env'), ('l10n_uy_edi.addenda', 'l10n_uy_edi_addenda', 'legend_type', 'type'), ] From 5138d4c22b3a1a867b937bc610a72c10b2a064e1 Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Fri, 22 Nov 2024 17:06:37 -0300 Subject: [PATCH 17/21] [FIX] l10n_uy_edi: rename of chart of account Is given problem on the res.config.settings view, we update the UY companies to be link to the new UY chart template instead --- l10n_uy_edi/17.0.0.0/post-migration.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index e48fc36..c02db80 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -152,3 +152,16 @@ def migrate(env, version): cron_ucfe_notif.unlink() if cron_ucfe_notif else False cron_vendor_bills_received.unlink() if cron_vendor_bills_received else False + + # Cambio el plan de cuentas en 16 era uy_account en el modulo l10n_uy_account. Ahora en 17 el plan de cuentas esta + # en l10n_uy y se llama 'uy'. Tenemos que actualizar este dato en la compañia porque si no cuando entramos al menu + # de Ajustes recibimos este traceback https://gist.github.com/zaoral/461d737b35601c74d05ca3054d2f6e9f . Decidimos + # pasarlo a vacio porque si le ponemeos "uy" como hay muchas diferencias entre los xml usados en una version y + # otra puede traernos problemas en el futuro de duplicacion de registros que no queremos porque los xml son + # distintos + openupgrade.logged_query(env.cr, """ + UPDATE res_company + SET + chart_template = Null + WHERE chart_template = 'uy_account' + """) From 26a068fe559dc5c5bced28604193a3cf1ab21aea Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Thu, 28 Nov 2024 17:15:05 -0300 Subject: [PATCH 18/21] [ADD] l10n_uy_edi: second version end script --- l10n_uy_edi/17.0.0.0/pre-migration.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/l10n_uy_edi/17.0.0.0/pre-migration.py b/l10n_uy_edi/17.0.0.0/pre-migration.py index e0aa4a8..20c4c3f 100644 --- a/l10n_uy_edi/17.0.0.0/pre-migration.py +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -47,8 +47,6 @@ ('res.company', 'res_company', 'l10n_uy_ucfe_terminal_code', 'l10n_uy_edi_ucfe_terminal_code'), ('res.company', 'res_company', 'l10n_uy_dgi_house_code', 'l10n_uy_edi_branch_code'), ('res.company', 'res_company', 'l10n_uy_adenda_ids', 'l10n_uy_edi_addenda_ids'), - ('res.company', 'res_company', 'l10n_uy_ucfe_prod_env', 'l10n_uy_edi_ucfe_prod_env'), - ('res.company', 'res_company', 'l10n_uy_ucfe_test_env', 'l10n_uy_edi_ucfe_test_env'), ('l10n_uy_edi.addenda', 'l10n_uy_edi_addenda', 'legend_type', 'type'), ] From f3fd78ea6628ebeee5ea039a5be9ad9fbd630b32 Mon Sep 17 00:00:00 2001 From: Nicolas Mac Rouillon Date: Wed, 27 Nov 2024 08:49:27 -0300 Subject: [PATCH 19/21] [FIX] Change "env" for "cr" due odoo restriction on 18.0 --- base/16.0.0.0/pre-0-disable-check-company.py | 2 +- base/16.0.0.0/pre-0-disable-check-views.py | 2 +- base/17.0.0.0/pre-0-disable-check-company.py | 2 +- base/17.0.0.0/pre-0-disable-check-views.py | 2 +- base/17.0.0.0/pre-0-model-checks.py | 2 +- base/18.0.0.0/pre-0-disable-check-company.py | 21 ++++++++++++++++ base/18.0.0.0/pre-0-disable-check-views.py | 21 ++++++++++++++++ base/18.0.0.0/pre-0-model-checks.py | 25 ++++++++++++++++++++ 8 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 base/18.0.0.0/pre-0-disable-check-company.py create mode 100644 base/18.0.0.0/pre-0-disable-check-views.py create mode 100644 base/18.0.0.0/pre-0-model-checks.py diff --git a/base/16.0.0.0/pre-0-disable-check-company.py b/base/16.0.0.0/pre-0-disable-check-company.py index 25fe909..3c3534a 100644 --- a/base/16.0.0.0/pre-0-disable-check-company.py +++ b/base/16.0.0.0/pre-0-disable-check-company.py @@ -17,5 +17,5 @@ def _check_company(self, fnames=None): BaseModel._check_company = _check_company -def migrate(env, version): +def migrate(cr, version): pass diff --git a/base/16.0.0.0/pre-0-disable-check-views.py b/base/16.0.0.0/pre-0-disable-check-views.py index 75c2785..d1b7b7e 100644 --- a/base/16.0.0.0/pre-0-disable-check-views.py +++ b/base/16.0.0.0/pre-0-disable-check-views.py @@ -17,5 +17,5 @@ def _check_xml(self): View._check_xml = _check_xml -def migrate(env, version): +def migrate(cr, version): pass diff --git a/base/17.0.0.0/pre-0-disable-check-company.py b/base/17.0.0.0/pre-0-disable-check-company.py index 25fe909..3c3534a 100644 --- a/base/17.0.0.0/pre-0-disable-check-company.py +++ b/base/17.0.0.0/pre-0-disable-check-company.py @@ -17,5 +17,5 @@ def _check_company(self, fnames=None): BaseModel._check_company = _check_company -def migrate(env, version): +def migrate(cr, version): pass diff --git a/base/17.0.0.0/pre-0-disable-check-views.py b/base/17.0.0.0/pre-0-disable-check-views.py index 75c2785..d1b7b7e 100644 --- a/base/17.0.0.0/pre-0-disable-check-views.py +++ b/base/17.0.0.0/pre-0-disable-check-views.py @@ -17,5 +17,5 @@ def _check_xml(self): View._check_xml = _check_xml -def migrate(env, version): +def migrate(cr, version): pass diff --git a/base/17.0.0.0/pre-0-model-checks.py b/base/17.0.0.0/pre-0-model-checks.py index 0ced762..a27eff5 100644 --- a/base/17.0.0.0/pre-0-model-checks.py +++ b/base/17.0.0.0/pre-0-model-checks.py @@ -21,5 +21,5 @@ def _process_ondelete(self): IrModelSelection._process_ondelete = _process_ondelete -def migrate(env, version): +def migrate(cr, version): pass diff --git a/base/18.0.0.0/pre-0-disable-check-company.py b/base/18.0.0.0/pre-0-disable-check-company.py new file mode 100644 index 0000000..3c3534a --- /dev/null +++ b/base/18.0.0.0/pre-0-disable-check-company.py @@ -0,0 +1,21 @@ +from odoo.models import BaseModel +import logging +_logger = logging.getLogger(__name__) + + +_original_check_company = BaseModel._check_company + + +def _check_company(self, fnames=None): + """ Patch chec_check_company to avoid any error when run scripts, we enable later """ + try: + _original_check_company + except Exception as e: + _logger.warning('incompatible companies. This is what we get:\n%s', e) + + +BaseModel._check_company = _check_company + + +def migrate(cr, version): + pass diff --git a/base/18.0.0.0/pre-0-disable-check-views.py b/base/18.0.0.0/pre-0-disable-check-views.py new file mode 100644 index 0000000..d1b7b7e --- /dev/null +++ b/base/18.0.0.0/pre-0-disable-check-views.py @@ -0,0 +1,21 @@ +from odoo.addons.base.models.ir_ui_view import View +import logging +_logger = logging.getLogger(__name__) + + +_original_check_xml = View._check_xml + + +def _check_xml(self): + """ Patch check_xml to avoid any error when loading views, we check them later """ + try: + _original_check_xml + except Exception as e: + _logger.warning('Invalid view definition. This is what we get:\n%s', e) + + +View._check_xml = _check_xml + + +def migrate(cr, version): + pass diff --git a/base/18.0.0.0/pre-0-model-checks.py b/base/18.0.0.0/pre-0-model-checks.py new file mode 100644 index 0000000..a27eff5 --- /dev/null +++ b/base/18.0.0.0/pre-0-model-checks.py @@ -0,0 +1,25 @@ +from odoo import api, models + +from odoo.addons.base.models.ir_model import ( + IrModelSelection, +) + + +def _process_ondelete(self): + """Don't break on missing models when deleting their selection fields""" + to_process = self.browse([]) + for selection in self: + try: + self.env[selection.field_id.model] # pylint: disable=pointless-statement + to_process += selection + except KeyError: + continue + return IrModelSelection._process_ondelete._original_method(to_process) + + +_process_ondelete._original_method = IrModelSelection._process_ondelete +IrModelSelection._process_ondelete = _process_ondelete + + +def migrate(cr, version): + pass From 44b2c7678d379613d9ca79a7d9c2eab57b1bc702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roc=C3=ADo=20Vega?= Date: Fri, 3 Jan 2025 17:22:37 -0300 Subject: [PATCH 20/21] [FIX] account_payment_pro_receiptbook: Update receiptbook_id in account_move table --- .../17.0.0.0/post-migration.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/account_payment_pro_receiptbook/17.0.0.0/post-migration.py b/account_payment_pro_receiptbook/17.0.0.0/post-migration.py index 43d1bfe..ddc289d 100644 --- a/account_payment_pro_receiptbook/17.0.0.0/post-migration.py +++ b/account_payment_pro_receiptbook/17.0.0.0/post-migration.py @@ -24,6 +24,16 @@ def migrate_payment_grup_data(env): """ openupgrade.logged_query(env.cr, query) + query = """ + update account_move am set + receiptbook_id = ap.receiptbook_id + from account_payment as ap + where + am.payment_id = ap.id and ap.receiptbook_id is not null; + """ + + openupgrade.logged_query(env.cr, query) + # popular to_pay_move_lines (m2m field, en post) query = """ insert into account_move_line_payment_to_pay_rel (to_pay_line_id, payment_id) From f47129d19e727314936a7fd9a0942fb507517973 Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Tue, 7 Jan 2025 17:12:30 -0300 Subject: [PATCH 21/21] [FIX] l10n_uy: odoo-upgrade fix l10n_uy_edi Ticket: 85987 --- l10n_uy/17.0.0.0/post-migration.py | 22 ++++++++++++++++++++++ l10n_uy_edi/17.0.0.0/post-migration.py | 13 ------------- 2 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 l10n_uy/17.0.0.0/post-migration.py diff --git a/l10n_uy/17.0.0.0/post-migration.py b/l10n_uy/17.0.0.0/post-migration.py new file mode 100644 index 0000000..2b7e3b6 --- /dev/null +++ b/l10n_uy/17.0.0.0/post-migration.py @@ -0,0 +1,22 @@ +from openupgradelib import openupgrade +import logging +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + _logger.info('Running post-migrate script for l10n_uy') + # Popular nueva tabla con datos en el account move + + # Cambio el plan de cuentas en 16 era uy_account en el modulo l10n_uy_account. Ahora en 17 el plan de cuentas esta + # en l10n_uy y se llama 'uy'. Tenemos que actualizar este dato en la compañia porque si no cuando entramos al menu + # de Ajustes recibimos este traceback https://gist.github.com/zaoral/461d737b35601c74d05ca3054d2f6e9f . Decidimos + # pasarlo a vacio porque si le ponemeos "uy" como hay muchas diferencias entre los xml usados en una version y + # otra puede traernos problemas en el futuro de duplicacion de registros que no queremos porque los xml son + # distintos + openupgrade.logged_query(env.cr, """ + UPDATE res_company + SET + chart_template = Null + WHERE chart_template = 'uy_account' + """) diff --git a/l10n_uy_edi/17.0.0.0/post-migration.py b/l10n_uy_edi/17.0.0.0/post-migration.py index c02db80..e48fc36 100644 --- a/l10n_uy_edi/17.0.0.0/post-migration.py +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -152,16 +152,3 @@ def migrate(env, version): cron_ucfe_notif.unlink() if cron_ucfe_notif else False cron_vendor_bills_received.unlink() if cron_vendor_bills_received else False - - # Cambio el plan de cuentas en 16 era uy_account en el modulo l10n_uy_account. Ahora en 17 el plan de cuentas esta - # en l10n_uy y se llama 'uy'. Tenemos que actualizar este dato en la compañia porque si no cuando entramos al menu - # de Ajustes recibimos este traceback https://gist.github.com/zaoral/461d737b35601c74d05ca3054d2f6e9f . Decidimos - # pasarlo a vacio porque si le ponemeos "uy" como hay muchas diferencias entre los xml usados en una version y - # otra puede traernos problemas en el futuro de duplicacion de registros que no queremos porque los xml son - # distintos - openupgrade.logged_query(env.cr, """ - UPDATE res_company - SET - chart_template = Null - WHERE chart_template = 'uy_account' - """)