From 215de3b2982533e1a6fc4a68fab279e7ff20278b Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 3 Feb 2025 13:42:53 +0100 Subject: [PATCH] [OU-IMP] more review followups --- .../account/17.0.1.2/noupdate_changes.xml | 19 --- .../17.0.1.2/noupdate_changes_work.xml | 157 ++++++++++++++++++ .../account/17.0.1.2/post-migration.py | 17 +- .../scripts/account/17.0.1.2/pre-migration.py | 72 +++++++- .../17.0.1.2/upgrade_analysis_work.txt | 5 +- 5 files changed, 242 insertions(+), 28 deletions(-) create mode 100644 openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes_work.xml diff --git a/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes.xml b/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes.xml index d9df6a524d18..3f88cf19fce0 100644 --- a/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes.xml +++ b/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes.xml @@ -18,59 +18,40 @@ [('company_id', 'in', company_ids)] - - - - 10 Days after End of Next Month Payment terms: 10 Days after End of Next Month - - 7 2 True - - ['|', ('company_id', '=', False), ('company_id', 'parent_of', company_ids)] - - [('company_id', 'parent_of', company_ids)] diff --git a/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes_work.xml b/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes_work.xml new file mode 100644 index 000000000000..d9df6a524d18 --- /dev/null +++ b/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes_work.xml @@ -0,0 +1,157 @@ + + + + [('company_id', 'in', company_ids)] + + + [('company_id', 'parent_of', company_ids)] + + + [('company_id', 'parent_of', company_ids)] + + + [('company_id', 'parent_of', company_ids)] + + + [('company_id', 'in', company_ids)] + + + [('company_id', 'in', company_ids)] + + + + + + + + + + + 10 Days after End of Next Month + Payment terms: 10 Days after End of Next Month + + + + + + + 7 + 2 + True + + + + + + + + + ['|', ('company_id', '=', False), ('company_id', 'parent_of', company_ids)] + + + + + + + + + [('company_id', 'parent_of', company_ids)] + + + [('company_id', 'parent_of', company_ids)] + + + ['|',('company_id','=',False), ('company_id', 'parent_of', company_ids)] + + + + + + + + + + + + +
+

+ Dear + Brandon Freeman (Azure Interior), + + Brandon Freeman, + +

+ Here is your + + invoice INV/2021/05/0005 + + + invoice + + + (with reference: SUB003) + + amounting in $ 143,750.00 + from YourCompany. + + This invoice is already paid. + + + Please remit payment at your earliest convenience. +

+ Please use the following communication for your payment: INV/2021/05/0005 + + on the account + + . +
+
+

+ PS: you can review your timesheets from the portal. +
+

+ Do not hesitate to contact us if you have any questions. +

--
Mitchell Admin
+

+
+
+ +
+ + [('company_id', 'in', company_ids)] + + + [('company_id', 'parent_of', company_ids)] + + + [('company_id', 'parent_of', company_ids)] + + + + + + [('company_id', 'parent_of', company_ids)] + + + ['|',('company_id','=',False), ('company_id', 'parent_of', company_ids)] + +
diff --git a/openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py b/openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py index a9586265d79b..9861a3b81100 100644 --- a/openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py +++ b/openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py @@ -165,7 +165,7 @@ def _onboarding_state_migration(env): ], limit=1, ): - step.action_set_just_done() + step.with_company(company_id).action_set_just_done() if account_onboarding_invoice_layout_state in ("just_done", "done"): step = env.ref( "account.onboarding_onboarding_step_base_document_layout", @@ -373,7 +373,7 @@ def _account_tax_group_migration(env): And then in each l10n module, only need to perform rename xml_id like https://github.com/Viindoo/OpenUpgrade/pull/655 """ - origin_id_column = openupgrade.get_legacy_name("origin_id") + origin_id_column = "original_tax_group_id" openupgrade.logged_query( env.cr, f""" @@ -460,7 +460,7 @@ def _force_install_account_payment_term_module_module(env): it has already merged in odoo master """ account_payment_term_module = env["ir.module.module"].search( - [("name", "=", "account_payment_term")] + [("name", "=", "account_payment_term")], limit=1 ) needs_account_payment_term = bool( env["account.payment.term.line"].search( @@ -523,7 +523,16 @@ def migrate(env, version): _account_payment_term_migration(env) _account_payment_term_early_payment_discount(env) _force_install_account_payment_term_module_module(env) - openupgrade.load_data(env, "account", "17.0.1.2/noupdate_changes.xml") + openupgrade.load_data(env, "account", "17.0.1.2/noupdate_changes_work.xml") + openupgrade.delete_record_translations( + env.cr, + "account", + ( + "email_template_edi_credit_note", + "email_template_edi_invoice", + "mail_template_data_payment_receipt", + ), + ) openupgrade.delete_records_safely_by_xml_id( env, _deleted_xml_records, diff --git a/openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py b/openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py index 1da54c872d1a..06eb6d65ff5f 100644 --- a/openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py +++ b/openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py @@ -76,7 +76,6 @@ def _generic_coa_rename_xml_id(env): def _convert_account_tax_description(env): - openupgrade.copy_columns(env.cr, {"account_tax": [("description", None, None)]}) openupgrade.rename_columns( env.cr, {"account_tax": [("description", "invoice_label")]} ) @@ -99,7 +98,7 @@ def _am_create_delivery_date_column(env): def _am_create_incoterm_location_column(env): """ - Create column then in sale_stock, purchase_stock will fill it in pre, + Create column then in sale_stock and purchase_stock will fill it in pre, pr: https://github.com/odoo/odoo/pull/118954 """ openupgrade.logged_query( @@ -120,7 +119,7 @@ def _am_uniquify_name(env): """ UPDATE account_move SET name=name || ' [' || id || ']' FROM ( - SElECT array_agg(id) ids FROM account_move + SELECT array_agg(id) ids FROM account_move GROUP BY journal_id, name HAVING COUNT(id)>1 ) duplicate_names WHERE account_move.id=ANY(duplicate_names.ids); @@ -199,10 +198,74 @@ def _pre_create_early_pay_discount_computation(env): FROM res_company rc WHERE apt.company_id = rc.id AND apt.early_pay_discount_computation IS NULL + AND rc.early_pay_discount_computation IS NOT NULL """, ) +def _decouple_obsolete_tables(env): + """ + Remove all foreign keys held by and pointed to template tables + """ + obsolete_tables = [ + "account_account_template", + "account_fiscal_position_account_template", + "account_fiscal_position_tax_template", + "account_fiscal_position_template", + "account_group_template", + "account_reconcile_model_line_template", + "account_reconcile_model_template", + "account_tax_repartition_line_template", + "account_tax_template", + ] + openupgrade.remove_tables_fks(env.cr, obsolete_tables) + env.cr.execute( + """ + SELECT tc.table_name, tc.constraint_name + FROM information_schema.table_constraints tc + JOIN information_schema.constraint_table_usage ctu + ON tc.constraint_name=ctu.constraint_name + WHERE ctu.table_name in %s + AND tc.constraint_type='FOREIGN KEY' + """, + (tuple(obsolete_tables),), + ) + for table, constraint in env.cr.fetchall(): + openupgrade.logged_query( + env.cr, f"ALTER TABLE {table} DROP CONSTRAINT {constraint}" + ) + + +def _pre_create_account_report_active(env): + """ + Precreate column with default value true, then switch back to false + """ + env.cr.execute( + """ + ALTER TABLE account_report ADD COLUMN active boolean DEFAULT true + """ + ) + env.cr.execute( + """ + ALTER TABLE account_report ALTER COLUMN active SET DEFAULT false + """ + ) + + +def _remove_obsolete_constraints(env): + """ + Remove constraints that will be deleted at the end of the migration + """ + table2constraints = { + "account_account": ["code_company_uniq"], + "account_fiscal_position_account": ["account_src_dest_uniq"], + "account_tax": ["name_company_uniq", "template_name_company_uniq"], + } + for table, constraints in table2constraints.items(): + for constraint in constraints: + openupgrade.delete_sql_constraint_safely(env, "account", table, constraint) + + @openupgrade.migrate() def migrate(env, version): _map_account_report_filter_account_type(env) @@ -223,3 +286,6 @@ def migrate(env, version): _account_report_update_figure_type(env) _account_tax_repartition_line_merge_repartition_lines_m2o(env) _pre_create_early_pay_discount_computation(env) + _decouple_obsolete_tables(env) + _pre_create_account_report_active(env) + _remove_obsolete_constraints(env) diff --git a/openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt index 5b0d88e56fb7..ff09942f712e 100644 --- a/openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt @@ -8,7 +8,7 @@ obsolete model account.reconcile.model.line.template obsolete model account.reconcile.model.template obsolete model account.tax.repartition.line.template obsolete model account.tax.template -# NOTHING TO DO: these models has been converted to CSV definition and existing company records XML-ID follow the same logic +# DONE: these models has been converted to CSV definition and existing company records XML-ID follow the same logic. Removed all constraints from tables obsolete model account.invoice.send [transient] new model account.move.send [transient] @@ -247,8 +247,9 @@ account / account.reconcile.model.template / rule_type (selection) account / account.reconcile.model.template / sequence (integer) : DEL required account / account.reconcile.model.template / to_check (boolean) : DEL account / account.report / _order : _order is now 'sequence, id' ('id') -account / account.report / active (boolean) : NEW hasdefault: default # NOTHING TO DO +account / account.report / active (boolean) : NEW hasdefault: default +# DONE: precreated with value True account / account.report / chart_template (selection) : NEW selection_keys: function account / account.report / chart_template_id (many2one) : DEL relation: account.chart.template