Skip to content
Open
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
32 changes: 32 additions & 0 deletions addons/account/migrations/12.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,35 @@ def drop_obsolete_constraint_wizard_multi_charts_accounts(env):
openupgrade.remove_tables_fks(env.cr, ['wizard_multi_charts_accounts'])


def fix_double_membership(cr):
# avoid error raised by new function '_check_one_user_type'

# we arbitrarily keep the tax included
Copy link
Member

Choose a reason for hiding this comment

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

Please keep tax excluded as B2B is the most usual one in my experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My point was : B2B is the default, so if the user has b2c selected, it's intented. Dont't you think ?

Copy link
Member

Choose a reason for hiding this comment

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

Is that really that way? Shouldn't all the users be homogeneous with one or the other? Applying res.config.settings apply to all users.

Copy link
Member

Choose a reason for hiding this comment

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

I think Pedro is right. res.config.settings wipes the users from the groups that are deactivated: https://github.com/odoo/odoo/blob/12.0/odoo/addons/base/models/res_config.py#L586-L587

group_to_remove = "group_show_line_subtotals_tax_excluded"
group_to_keep = "group_show_line_subtotals_tax_included"
openupgrade.logged_query(
cr, """
DELETE FROM res_groups_users_rel
WHERE
gid = (
SELECT res_id
FROM ir_model_data
WHERE module = 'account' AND name = %s
)
AND uid IN (
SELECT uid FROM res_groups_users_rel WHERE gid IN (
SELECT res_id
FROM ir_model_data
WHERE module = 'account'
AND name IN (%s, %s)
)
GROUP BY uid
HAVING count(*) > 1
);
""", (group_to_remove, group_to_remove, group_to_keep)
)


@openupgrade.migrate()
def migrate(env, version):
cr = env.cr
Expand All @@ -158,3 +187,6 @@ def migrate(env, version):
drop_obsolete_constraint_wizard_multi_charts_accounts(env)
openupgrade.set_xml_ids_noupdate_value(
env, 'account', ['account_analytic_line_rule_billing_user'], False)

# Fix potentiel duplicates in res_groups_users_rel
fix_double_membership(env.cr)