Skip to content

Commit

Permalink
[MIG] account: migration
Browse files Browse the repository at this point in the history
  • Loading branch information
duong77476-viindoo committed Jun 4, 2024
1 parent 3349edd commit 7f33c61
Show file tree
Hide file tree
Showing 4 changed files with 560 additions and 13 deletions.
13 changes: 13 additions & 0 deletions openupgrade_scripts/scripts/account/17.0.1.2/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade


def _res_partner_bank_computation(env):
partner_banks = env["res.partner.bank"].with_context(active_test=False).search([])
partner_banks._compute_display_account_warning()


@openupgrade.migrate()
def migrate(env, version):
_res_partner_bank_computation(env)
101 changes: 101 additions & 0 deletions openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,111 @@
]


def _aml_update_matching_number(env):
fulls = env["account.full.reconcile"].search([])
env["account.partial.reconcile"]._update_matching_number(fulls.reconciled_line_ids)


def _am_update_invoice_pdf_report_file(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE ir_attachment ia
SET res_field = 'invoice_pdf_report_file',
res_id = am.id
FROM account_move am
WHERE am.message_main_attachment_id = ia.id
""",
)


def _onboarding_state_migration(env):
"""
Following pr: https://github.com/odoo/odoo/pull/104223/
"""
env.cr.execute(
"""
SELECT id, account_onboarding_create_invoice_state_flag,
account_onboarding_invoice_layout_state,
account_onboarding_sale_tax_state, account_setup_bank_data_state,
account_setup_bill_state, account_setup_coa_state, account_setup_fy_data_state,
account_setup_taxes_state FROM res_company
"""
)
for (
company_id,
account_onboarding_create_invoice_state_flag,
account_onboarding_invoice_layout_state,
account_onboarding_sale_tax_state,
account_setup_bank_data_state,
account_setup_bill_state,
account_setup_coa_state,
account_setup_fy_data_state,
account_setup_taxes_state,
) in env.cr.fetchall():
OnboardingStep = env["onboarding.onboarding.step"].with_company(company_id)
company = env["res.company"].browse(company_id)
if company.street and company.street.strip():
# Same behaviour for this base setup company data in v16
# Check method 'action_save_onboarding_company_step' in v16
# Note in v17 you only need to save it then it will be done
OnboardingStep.action_validate_step(
"account.onboarding_onboarding_step_company_data"
)
if account_onboarding_create_invoice_state_flag:
step = env.ref(
"account.onboarding_onboarding_step_create_invoice",
raise_if_not_found=False,
)
if step and step.current_step_state == "not_done":
if env["account.move"].search(
[
("company_id", "=", company_id),
("move_type", "=", "out_invoice"),
],
limit=1,
):
step.action_set_just_done()
if account_onboarding_invoice_layout_state in ("just_done", "done"):
step = env.ref(
"account.onboarding_onboarding_step_base_document_layout",
raise_if_not_found=False,
)
if step:
step.with_company(company_id).action_set_just_done()
if account_onboarding_sale_tax_state in ("just_done", "done"):
OnboardingStep.action_validate_step(
"account.onboarding_onboarding_step_sales_tax"
)
if account_setup_bank_data_state in ("just_done", "done"):
OnboardingStep.action_validate_step(
"account.onboarding_onboarding_step_bank_account"
)
if account_setup_bill_state in ("just_done", "done"):
OnboardingStep.action_validate_step(
"account.onboarding_onboarding_step_setup_bill"
)
if account_setup_coa_state in ("just_done", "done"):
OnboardingStep.action_validate_step(
"account.onboarding_onboarding_step_chart_of_accounts"
)
if account_setup_fy_data_state in ("just_done", "done"):
OnboardingStep.action_validate_step(
"account.onboarding_onboarding_step_fiscal_year"
)
if account_setup_taxes_state in ("just_done", "done"):
OnboardingStep.action_validate_step(
"account.onboarding_onboarding_step_default_taxes"
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "account", "17.0.1.2/noupdate_changes.xml")
openupgrade.delete_records_safely_by_xml_id(
env,
_deleted_xml_records,
)
_aml_update_matching_number(env)
_am_update_invoice_pdf_report_file(env)
_onboarding_state_migration(env)
Loading

0 comments on commit 7f33c61

Please sign in to comment.