Skip to content
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
44 changes: 42 additions & 2 deletions openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def post_statements(env):
# instead, call it one by one.
stmts = env["account.bank.statement"].browse(stmt_ids)
for stmt in stmts:
stmt.button_post()
# trobz migrate: skip_check_constrains_account_id_journal_id
stmt.with_context(skip_check_constrains_account_id_journal_id=True).button_post()


def pass_bank_statement_line_note_to_journal_entry_narration(env):
Expand Down Expand Up @@ -581,6 +582,17 @@ def map_account_payment_transfer(env):


def fill_account_payment_reconciliation(env):
env.cr.execute(
"""
SELECT 1
FROM account_payment
WHERE is_matched IS NOT NULL OR is_reconciled IS NOT NULL
LIMIT 1
"""
)
has_prefilled_reconciliation = bool(env.cr.fetchone())
if has_prefilled_reconciliation:
return
openupgrade.logged_query(
env.cr,
"""
Expand Down Expand Up @@ -710,7 +722,8 @@ def fill_account_payment_with_no_move(env):
)
deprecated_accounts.deprecated = False
try:
payment._synchronize_to_moves(
# trobz migrate: add context skip_check_constrains_account_id_journal_id to skip constraint
payment.with_context(skip_check_constrains_account_id_journal_id=True)._synchronize_to_moves(
[
"date",
"amount",
Expand Down Expand Up @@ -745,6 +758,29 @@ def try_delete_noupdate_records(env):


def fill_account_move_line_amounts(env):
legacy_amount_currency = openupgrade.get_legacy_name("amount_currency")
if openupgrade.column_exists(env.cr, "account_move_line", "mig18_amount_currency"):
if openupgrade.column_exists(env.cr, "account_move_line", "amount_currency") and not openupgrade.column_exists(
env.cr, "account_move_line", legacy_amount_currency
):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move_line
RENAME COLUMN amount_currency TO {}
""".format(legacy_amount_currency),
)
if openupgrade.column_exists(env.cr, "account_move_line", "mig18_amount_currency") and not openupgrade.column_exists(
env.cr, "account_move_line", "amount_currency"
):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move_line
RENAME COLUMN mig18_amount_currency TO amount_currency
""",
)
return
openupgrade.logged_query(
env.cr,
"""
Expand Down Expand Up @@ -930,12 +966,16 @@ def migrate(env, version):
try_delete_noupdate_records(env)
_create_hooks(env)
fill_company_account_journal_suspense_account_id(env)

fill_statement_lines_with_no_move(env)

fill_account_journal_payment_credit_debit_account_id(env)
create_new_counterpart_account_payment_transfer(env)
map_account_payment_transfer(env)
fill_account_payment_reconciliation(env)

fill_account_payment_with_no_move(env)

fill_account_bank_statement_line_reconciliation(env)
post_statements(env)
_delete_hooks(env)
Expand Down
91 changes: 83 additions & 8 deletions openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ def fill_empty_partner_type_account_payment(env):


def fill_account_move_line_currency_id(env):
legacy_currency_id = openupgrade.get_legacy_name("currency_id")
legacy_amount_residual_currency = openupgrade.get_legacy_name(
"amount_residual_currency"
)
# Disappeared constraint
openupgrade.logged_query(
env.cr,
Expand All @@ -308,6 +312,48 @@ def fill_account_move_line_currency_id(env):
openupgrade.delete_records_safely_by_xml_id(
env, ["account.constraint_account_move_line_check_amount_currency_balance_sign"]
)
if openupgrade.column_exists(env.cr, "account_move_line", "mig18_currency_id"):
if openupgrade.column_exists(env.cr, "account_move_line", "currency_id") and not openupgrade.column_exists(
env.cr, "account_move_line", legacy_currency_id
):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move_line
RENAME COLUMN currency_id TO {}
""".format(legacy_currency_id),
)
if openupgrade.column_exists(env.cr, "account_move_line", "amount_residual_currency") and not openupgrade.column_exists(
env.cr, "account_move_line", legacy_amount_residual_currency
):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move_line
RENAME COLUMN amount_residual_currency TO {}
""".format(legacy_amount_residual_currency),
)
if openupgrade.column_exists(env.cr, "account_move_line", "mig18_amount_residual_currency") and not openupgrade.column_exists(
env.cr, "account_move_line", "amount_residual_currency"
):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move_line
RENAME COLUMN mig18_amount_residual_currency TO amount_residual_currency
""",
)
if openupgrade.column_exists(env.cr, "account_move_line", "mig18_currency_id") and not openupgrade.column_exists(
env.cr, "account_move_line", "currency_id"
):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move_line
RENAME COLUMN mig18_currency_id TO currency_id
""",
)
return
openupgrade.logged_query(
env.cr,
"""
Expand All @@ -320,6 +366,17 @@ def fill_account_move_line_currency_id(env):


def fill_account_move_line_matching_number(env):
has_mig18_matching_number = openupgrade.column_exists(
env.cr, "account_move_line", "mig18_matching_number"
)
if has_mig18_matching_number:
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move_line
RENAME COLUMN mig18_matching_number TO matching_number
""",
)
openupgrade.add_fields(
env,
[
Expand All @@ -333,6 +390,8 @@ def fill_account_move_line_matching_number(env):
),
],
)
if has_mig18_matching_number:
return
openupgrade.logged_query(
env.cr,
"""
Expand Down Expand Up @@ -470,6 +529,22 @@ def fill_account_payment_data(env):


def create_account_payment_reconciliation(env):
if openupgrade.column_exists(env.cr, "account_payment", "mig18_is_reconciled"):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_payment
RENAME COLUMN mig18_is_reconciled TO is_reconciled
""",
)
if openupgrade.column_exists(env.cr, "account_payment", "mig18_is_matched"):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_payment
RENAME COLUMN mig18_is_matched TO is_matched
""",
)
openupgrade.add_fields(
env,
[
Expand Down Expand Up @@ -677,22 +752,22 @@ def fill_partial_reconcile_currency(env):
env.cr,
"""
UPDATE account_partial_reconcile apr
SET debit_currency_id = COALESCE(aml.currency_id, rc.currency_id)
FROM account_move_line aml,
SET debit_currency_id = COALESCE(am.currency_id, rc.currency_id)
FROM account_move am,
res_company rc
WHERE aml.id = apr.debit_move_id
AND rc.id = aml.company_id
WHERE am.id = apr.debit_move_id
AND rc.id = am.company_id
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE account_partial_reconcile apr
SET credit_currency_id = COALESCE(aml.currency_id, rc.currency_id)
FROM account_move_line aml,
SET credit_currency_id = COALESCE(am.currency_id, rc.currency_id)
FROM account_move am,
res_company rc
WHERE aml.id = apr.credit_move_id
AND rc.id = aml.company_id
WHERE am.id = apr.credit_move_id
AND rc.id = am.company_id
""",
)

Expand Down
5 changes: 5 additions & 0 deletions openupgrade_scripts/scripts/base/14.0.1.3/pre-migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def migrate(cr, version):
if cr.fetchall():
merged_modules["edi"] = renamed_modules.pop("edi")

# Trobz, duplicate edi_storage_oca key when renaming
cr.execute("SELECT 1 FROM ir_module_module WHERE name='edi_storage_oca'")
if cr.fetchall():
merged_modules["edi_storage"] = renamed_modules.pop("edi_storage")

openupgrade.update_module_names(cr, renamed_modules.items())
openupgrade.update_module_names(cr, merged_modules.items(), merge_modules=True)
openupgrade.clean_transient_models(cr)
Expand Down
21 changes: 12 additions & 9 deletions openupgrade_scripts/scripts/mass_mailing/14.0.2.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ def _assign_newsletter_xml_id(env):
env.cr.execute("SELECT id FROM mailing_list WHERE name='Newsletter'")
row = env.cr.fetchone()
if row:
openupgrade.logged_query(
env.cr,
"""INSERT INTO ir_model_data
(module, name, res_id, model, noupdate)
VALUES
('mass_mailing', 'mailing_list_data', %s, 'mailing.list', True)
""",
(row[0],),
)
# trobz migrate
env.cr.execute("SELECT id FROM ir_model_data WHERE module='mass_mailing' and name='mailing_list_data' and model='mailing.list' and res_id=%s" % row[0])
if not env.cr.fetchone():
openupgrade.logged_query(
env.cr,
"""INSERT INTO ir_model_data
(module, name, res_id, model, noupdate)
VALUES
('mass_mailing', 'mailing_list_data', %s, 'mailing.list', True)
""",
(row[0],),
)


@openupgrade.migrate()
Expand Down
12 changes: 7 additions & 5 deletions openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def migrate(env, version):
"""CREATE TABLE project_allowed_portal_users_rel
(project_project_id INTEGER, res_users_id INTEGER)""",
)
openupgrade.logged_query(
env.cr,
"""CREATE TABLE project_task_res_users_rel
(project_task_id INTEGER, res_users_id INTEGER)""",
)
# trobz migrate: only create if project_task_res_users_rel not exist
if not openupgrade.table_exists(env.cr, 'project_task_res_users_rel'):
openupgrade.logged_query(
env.cr,
"""CREATE TABLE project_task_res_users_rel
(project_task_id INTEGER, res_users_id INTEGER)""",
)
fast_fill_stored_calculated_fields(env)
18 changes: 16 additions & 2 deletions openupgrade_scripts/scripts/purchase/14.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@


def fill_purchase_order_line_qty_to_invoice(env):
if not openupgrade.column_exists(env.cr, "purchase_order_line", "qty_to_invoice"):
has_mig18_qty_to_invoice = openupgrade.column_exists(
env.cr, "purchase_order_line", "mig18_qty_to_invoice"
)
if has_mig18_qty_to_invoice:
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE purchase_order_line
RENAME COLUMN mig18_qty_to_invoice TO qty_to_invoice
""",
)
elif not openupgrade.column_exists(env.cr, "purchase_order_line", "qty_to_invoice"):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE purchase_order_line
ADD COLUMN qty_to_invoice numeric""",
)
if has_mig18_qty_to_invoice:
return
openupgrade.logged_query(
env.cr,
"""
Expand All @@ -23,7 +36,8 @@ def fill_purchase_order_line_qty_to_invoice(env):
ELSE 0 END
FROM purchase_order po, product_product pp
JOIN product_template pt ON pp.product_tmpl_id = pt.id
WHERE pol.order_id = po.id AND pol.product_id = pp.id""",
WHERE pol.order_id = po.id AND pol.product_id = pp.id
""",
)


Expand Down
3 changes: 2 additions & 1 deletion openupgrade_scripts/scripts/stock/14.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def delete_domain_from_view(env):

@openupgrade.migrate()
def migrate(env, version):
merge_priorities(env)
# priority has been updated in foodcoop_mig18_precompute_fields
# merge_priorities(env)
delete_domain_from_view(env)
openupgrade.load_data(env.cr, "stock", "14.0.1.1/noupdate_changes.xml")
recompute_stock_picking_scheduled_date(env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def fast_precreate_orderpoint_product_category_id(env):

@openupgrade.migrate()
def migrate(env, version):
openupgrade.copy_columns(env.cr, _column_copies)
# openupgrade.copy_columns(env.cr, _column_copies)
openupgrade.rename_fields(env, _field_renames)
openupgrade.rename_xmlids(env.cr, _xmlid_renames)
openupgrade.add_fields(env, _field_additons)
Expand Down
Loading