Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix define_settings method #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Unreleased

**Bugfixes**

* Calling anthem.lyrics.settings.define_settings in 13.0 breaks odoo environment

**Improvements**

**Documentation**
Expand Down
28 changes: 23 additions & 5 deletions anthem/lyrics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html)

from past.builtins import basestring
from ..cli import odoo


def define_settings(ctx, model, values):
""" Define settings like being in the interface
Example :
- model = 'sale.config.settings' or ctx.env['sale.config.settings']
- values = {'default_invoice_policy': 'delivery'}
Be careful, settings onchange are not triggered with this function.

Example:

model: 'sale.config.settings' or ctx.env['sale.config.settings']
values: {'default_invoice_policy': 'delivery'}

Be careful:

* settings onchange are not triggered with this function.
* in recent versions, the model is always 'res.config.settings'
* it cannot be used to install/uninstall modules
"""
if isinstance(model, basestring):
model = ctx.env[model]
model.create(values).execute()
if odoo.release.version_info[0] < 13:
# < 13.0, execute takes care of default values, groups,
# install/uninstall and call set_values() for the rest.
# We don't want the install part, but we need default and groups,
# so call execute().
model.create(values).execute()
else:
# In 13.0, execute calls set_values(), then takes care of
# install/uninstall. execute() resets the env which breaks
# computed fields afterwards, so do not call it.
model.create(values).set_values()
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if some projects don't rely on it to install modules 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They shouldn't ;)
And for < 13.0, the behavior doesn't change, so not too much risk I guess. Anyway, it's broken in 13.0