[18.0][FIX] mrp_bom_attribute_match: Error when use Compute Price from BOM on Product use Attribute Match on BOM Lines #1614
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.
Odoo's "Compute Price from BOM" button on the product template expects a concrete product variant (product.product) on the BOM line to retrieve the Unit of Measure (uom_id).
When BOM Attribute Match is used, a user selects a product template (product.template) instead of a specific variant. This leads to an error because the BOM line's product_id field is not populated, causing the system to fail when trying to compute the price.
Reproduce:

1/ Create a BOM Attribute Match for Test 1
2/ Go to Product Variant of Test 1 -> Click on Compute Price from BOM

Full error message:
Traceback (most recent call last):
File "/opt/odoo/odoo/models.py", line 6268, in ensure_one
_id, = self._ids
ValueError: not enough values to unpack (expected 1, got 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/odoo/odoo/http.py", line 2144, in _transactioning
return service_model.retrying(func, env=self.env)
File "/opt/odoo/odoo/service/model.py", line 156, in retrying
result = func()
File "/opt/odoo/odoo/http.py", line 2111, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/opt/odoo/odoo/http.py", line 2359, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 333, in _dispatch
result = endpoint(**request.params)
File "/opt/odoo/odoo/http.py", line 754, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/opt/odoo/addons/web/controllers/dataset.py", line 42, in call_button
action = call_kw(request.env[model], method, args, kwargs)
File "/opt/odoo/odoo/api.py", line 535, in call_kw
result = getattr(recs, name)(*args, **kwargs)
File "/opt/odoo/addons/mrp_account/models/product.py", line 37, in button_bom_cost
self._set_price_from_bom()
File "/opt/odoo/addons/mrp_account/models/product.py", line 48, in _set_price_from_bom
self.standard_price = self._compute_bom_price(bom, boms_to_recompute=boms_to_recompute)
File "/opt/odoo/addons/mrp_subcontracting_account/models/product_product.py", line 12, in _compute_bom_price
price = super()._compute_bom_price(bom, boms_to_recompute, byproduct_bom)
File "/opt/odoo/addons/mrp_account/models/product.py", line 105, in _compute_bom_price
total += line.product_id.uom_id._compute_price(line.product_id.standard_price, line.product_uom_id) * line.product_qty
File "/opt/odoo/addons/uom/models/uom_uom.py", line 244, in _compute_price
self.ensure_one()
File "/opt/odoo/odoo/models.py", line 6271, in ensure_one
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: uom.uom()