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] onchange_helper: Do not overwrite precomputed fields #3152

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from

Conversation

SirAionTech
Copy link
Contributor

Steps:

  1. Install sale_management
  2. Create a product template product
  3. Create a pricelist with discount_policy = without_discount, with a rule for the created product
  4. Create a sale order order
  5. In the Python code, play the onchanges for product_id for 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.

Only fields in the view being shown should be changed, otherwise the behavior is different than what happens in the UI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant