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) 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 new file mode 100644 index 0000000..a27eff5 --- /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(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 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/17.0.0.0/pre-migration.py b/l10n_uy/17.0.0.0/pre-migration.py new file mode 100644 index 0000000..f86565f --- /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): + _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'), + ('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 new file mode 100644 index 0000000..e48fc36 --- /dev/null +++ b/l10n_uy_edi/17.0.0.0/post-migration.py @@ -0,0 +1,154 @@ +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_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) + 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 + + # 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.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 + SET + l10n_uy_edi_cfe_state = 'error' + 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 + WHERE l10n_uy_cfe_state_bu IN ('not_apply', 'draft_cfe'); + """) + + # Cambios en las addendas + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'issuer' + WHERE type = 'emisor' + """) + + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'receiver' + WHERE type = 'receptor' + """) + + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'cfe_doc' + WHERE type = 'comprobante' + """) + + openupgrade.logged_query(env.cr, """ + UPDATE l10n_uy_edi_addenda + SET + type = 'addenda' + 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 + 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' + + + # Los re-creamos + 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 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..20c4c3f --- /dev/null +++ b/l10n_uy_edi/17.0.0.0/pre-migration.py @@ -0,0 +1,68 @@ +from openupgradelib import openupgrade +import logging +_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 = [ + ('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), + ('l10n_uy_cfe_pdf', 'l10n_uy_cfe_pdf_bu', None), + ], + '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 = [ + ('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_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'), + + ('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.info('Running migrate script for l10n_uy_edi') + + 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)