[16.0][FIX] onchange_helper: Do not overwrite precomputed fields - #3152
Open
SirAionTech wants to merge 2 commits into
Open
SirAionTech wants to merge 2 commits into
SirAionTech wants to merge 2 commits into
Conversation
Closed
1 task
SirAionTech
marked this pull request as ready for review
December 23, 2024 11:01
Only fields in the view being shown should be changed, otherwise the behavior is different than what happens in the UI
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Steps:
sale_managementproductdiscount_policy = without_discount, with a rule for the created productorderproduct_idfor a new line having values:{ "order_id": order.id, "product_id": product.id, }Observed behavior:
Error
Details
File "/home/odoo/src/user/OCA/server-tools/onchange_helper/models/base.py", line 58, in play_onchanges onchange_values = self.onchange(all_values, field, onchange_specs) File "/home/odoo/src/odoo/odoo/models.py", line 6622, in onchange todo = [ File "/home/odoo/src/odoo/odoo/models.py", line 6625, in if name not in done and snapshot0.has_changed(name) File "/home/odoo/src/odoo/odoo/models.py", line 6408, in has_changed return self[name] != record[name] File "/home/odoo/src/odoo/odoo/models.py", line 5957, in __getitem__ return self._fields[key].__get__(self, self.env.registry[self._name]) File "/home/odoo/src/odoo/odoo/fields.py", line 1158, in __get__ self.recompute(record) File "/home/odoo/src/odoo/odoo/fields.py", line 1370, in recompute apply_except_missing(self.compute_value, recs) File "/home/odoo/src/odoo/odoo/fields.py", line 1343, in apply_except_missing func(records) File "/home/odoo/src/odoo/odoo/fields.py", line 1392, in compute_value records._compute_field_value(self) File "/home/odoo/src/odoo/odoo/models.py", line 4241, in _compute_field_value fields.determine(field.compute, self) File "/home/odoo/src/odoo/odoo/fields.py", line 98, in determine return needle(*args) File "/home/odoo/src/user/OCA/sale-workflow/sale_pricelist_triple_discount/model/sale.py", line 29, in compute_discount res = super()._compute_discount() File "/home/odoo/src/odoo/addons/sale/models/sale_order_line.py", line 583, in _compute_discount base_price = line._get_pricelist_price_before_discount() File "/home/odoo/src/odoo/addons/sale/models/sale_order_line.py", line 551, in _get_pricelist_price_before_discount price = pricelist_rule._compute_base_price( File "/home/odoo/src/odoo/addons/product/models/product_pricelist_item.py", line 422, in _compute_base_price target_currency.ensure_one() File "/home/odoo/src/odoo/odoo/models.py", line 5186, in ensure_one raise ValueError("Expected singleton: %s" % self) ValueError: Expected singleton: res.currency()Expected behavior:
The order line is created
Additional context:
I could not add a test case for this module due to the complexity of sale model and precomputed fields, even using fake models of https://github.com/OCA/odoo-test-helper, any suggestion is appreciated.
The only test case I managed to create is in OCA/product-configurator#145.