Skip to content
Merged
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
14 changes: 13 additions & 1 deletion openupgrade_scripts/scripts/account/18.0.1.3/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def link_payments_to_moves(env):


def convert_company_dependent(env):
openupgrade_180.convert_company_dependent(env, "account.account", "code_store")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasn't a property before, we need to create our own property field

openupgrade_180.convert_company_dependent(
env, "account.cash.rounding", "loss_account_id"
)
Expand Down Expand Up @@ -125,10 +124,23 @@ def fill_res_partner_property_x_payment_method_line_id(env):
)


def account_account_code_fields(env):
"""
Fill account.account#code_store from company_id and code
"""
env.cr.execute(
"""
UPDATE account_account
SET code_store=json_build_object(company_id, code)
"""
)


@openupgrade.migrate()
def migrate(env, version):
replace_period_lock_date(env)
link_payments_to_moves(env)
account_account_code_fields(env)
openupgrade.m2o_to_x2m(
env.cr, env["account.account"], "account_account", "company_ids", "company_id"
)
Expand Down
18 changes: 0 additions & 18 deletions openupgrade_scripts/scripts/account/18.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from openupgradelib import openupgrade

field_renames = [
("account.account", "account_account", "code", "code_store"),
("account.move", "account_move", "payment_id", "origin_payment_id"),
("account.move", "account_move", "reversal_move_id", "reversal_move_ids"),
("account.move", "account_move", "send_and_print_values", "sending_data"),
Expand Down Expand Up @@ -135,23 +134,6 @@ def adapt_account_move_sending_data(env):
'{author_user_id}', sending_data::jsonb->'sp_user_id')
WHERE sending_data IS NOT NULL AND sending_data::jsonb ? 'sp_user_id'""",
)
# mail_template_id -> mail_template:
env.cr.execute(
"""
SELECT id, sending_data::jsonb->'mail_template_id' as mail_template_id
FROM account_move
WHERE sending_data IS NOT NULL AND sending_data::jsonb ? 'mail_template_id'""",
)
for move_id, mail_template_id in env.cr.fetchall():
mail_template = env.ref(mail_template_id)
openupgrade.logged_query(
env.cr,
f"""
UPDATE account_move
SET sending_data = jsonb_set(sending_data::jsonb - 'mail_template_id',
'{{mail_template}}', {mail_template})
WHERE id = {move_id}""",
)
Copy link
Author

@hbrunn hbrunn May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sending_data field is only used for the batch wizard, and there the mail template can't be set at all.

See the test data file that actually fills this field for the test migration, the above code fails there because this is an id in v17

# send_mail: True -> 'sending_methods': {"email"}:
openupgrade.logged_query(
env.cr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ account / account.account / code_mapping_ids (one2many) : NEW re
account / account.account / code (char) : not stored anymore
account / account.account / code (char) : now a function
account / account.account / code_store (char) : NEW
# DONE: pre-migration: renamed field
# DONE: post-migration: used openupgrade_180.convert_company_dependent
# DONE: post-migration: fill code_store from code and company_id

account / account.account / company_currency_id (many2one): not related anymore
account / account.account / company_currency_id (many2one): now a function
Expand Down Expand Up @@ -79,7 +78,7 @@ account / account.lock_exception / lock_date (date) : NEW
account / account.lock_exception / lock_date_field (selection) : NEW required, selection_keys: ['fiscalyear_lock_date', 'purchase_lock_date', 'sale_lock_date', 'tax_lock_date']
account / account.lock_exception / reason (char) : NEW
account / account.lock_exception / user_id (many2one) : NEW relation: res.users, hasdefault: default
# NOTHING TO DO? (new model)
# NOTHING TO DO: new feature

account / account.move / amount_untaxed_in_currency_signed (float): NEW isfunction: function, stored
# DONE: pre-migration: pre-created and filled
Expand All @@ -102,7 +101,7 @@ account / account.move / journal_group_id (many2one) : NEW re
# NOTHING TO DO: store = False

account / account.move / made_sequence_gap (boolean) : NEW isfunction: function, stored
# NOTHING TO DO?
# NOTHING TO DO: will be computed by ORM

account / account.move / origin_payment_id (many2one) : NEW relation: account.payment
account / account.move / payment_id (many2one) : DEL relation: account.payment
Expand Down
13 changes: 13 additions & 0 deletions openupgrade_scripts/scripts/account/tests/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
env = locals().get("env")
# call sending wizard on some moves asynchronously
action = (
env["account.move"]
.search([("move_type", "=", "out_invoice")])
.action_send_and_print()
)
env[action["res_model"]].with_context(**action["context"]).create(
{
"checkbox_download": False,
}
).action_send_and_print()
env.cr.commit()
Loading