-
-
Notifications
You must be signed in to change notification settings - Fork 533
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
[16.0][FIX] mass_edit: Play onchanges before writing #963
Open
grindtildeath
wants to merge
3
commits into
OCA:16.0
Choose a base branch
from
grindtildeath:16.0-imp-mass_edit_play_onchanges
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from ast import literal_eval | ||
from unittest.mock import patch | ||
|
||
from odoo.exceptions import ValidationError | ||
from odoo.tests import Form, common, new_test_user | ||
|
@@ -405,3 +406,68 @@ def test_onchange_model_id(self): | |
result, | ||
None, | ||
) | ||
|
||
@patch("odoo.addons.base.models.res_partner.Partner.onchange_email") | ||
def test_wizard_field_onchange(self, patched): | ||
server_action_partner = self.env["ir.actions.server"].create( | ||
{ | ||
"name": "Mass Edit Partner", | ||
"state": "mass_edit", | ||
"model_id": self.env.ref("base.model_res_partner").id, | ||
} | ||
) | ||
self.env["ir.actions.server.mass.edit.line"].create( | ||
[ | ||
{ | ||
"server_action_id": server_action_partner.id, | ||
"field_id": self.env.ref("base.field_res_partner__country_id").id, | ||
"apply_onchanges": True, | ||
}, | ||
{ | ||
"server_action_id": server_action_partner.id, | ||
"field_id": self.env.ref("base.field_res_partner__email").id, | ||
"apply_onchanges": False, | ||
}, | ||
] | ||
) | ||
self.assertEqual( | ||
server_action_partner.mass_edit_play_onchanges, | ||
{ | ||
"country_id": True, | ||
"email": False, | ||
}, | ||
) | ||
us_country = self.env.ref("base.us") | ||
mx_country = self.env.ref("base.mx") | ||
partners = self.env["res.partner"].create( | ||
[ | ||
{ | ||
"name": "ACME", | ||
"country_id": us_country.id, | ||
"state_id": self.env.ref("base.state_us_1").id, | ||
}, | ||
{ | ||
"name": "Example.com", | ||
"country_id": us_country.id, | ||
"state_id": self.env.ref("base.state_us_2").id, | ||
}, | ||
] | ||
) | ||
self.MassEditingWizard.with_context( | ||
server_action_id=server_action_partner.id, | ||
active_ids=partners.ids, | ||
).create( | ||
{ | ||
"selection__country_id": "set", | ||
"selection__email": "set", | ||
"country_id": mx_country, | ||
"email": "[email protected]", | ||
} | ||
) | ||
for partner in partners: | ||
self.assertEqual(partner.country_id, mx_country) | ||
# state_id is set to False by _onchange_country_id | ||
self.assertFalse(partner.state_id) | ||
self.assertEqual(partner.email, "[email protected]") | ||
# onchange_email is not called | ||
patched.assert_not_called() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very complete test. Thanks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add more information in the help text. Perfomance possible problem if it is executed on a lot of records versus inconsistency data if onchange are not executed.
Note : for new version (v18), I think we can put default="True", as it is the most expected behaviour.