Skip to content

Conversation

Vang-NguyenPhu
Copy link

@Vang-NguyenPhu Vang-NguyenPhu commented Sep 23, 2025

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
image

2/ Go to Product Variant of Test 1 -> Click on Compute Price from BOM
image

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()

@Vang-NguyenPhu Vang-NguyenPhu force-pushed the fix_compute_price_from_bom branch 2 times, most recently from 081adac to beafbc1 Compare September 26, 2025 10:00
…m BOM on Product use Attribute Match on BOM Lines
@Vang-NguyenPhu Vang-NguyenPhu force-pushed the fix_compute_price_from_bom branch from beafbc1 to d713c82 Compare September 29, 2025 02:35
Copy link

@hieulucky111 hieulucky111 left a comment

Choose a reason for hiding this comment

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

Code Review. LGTM

@DucTruongKomit

This comment was marked as duplicate.

Copy link

@DucTruongKomit DucTruongKomit left a comment

Choose a reason for hiding this comment

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

Review code LGTM

Copy link

@huynh-ch huynh-ch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants