MRP BoM Line formula for quantity
Compute the quantity of a Production Line using a formula defined in the BoM Line.
auto_awesome What this module does
AI-generated from the code · Odoo 18.0Add a formula field to Bill of Materials lines so the component quantity on a manufacturing order is calculated automatically instead of being fixed.
This module adds a new "quantity formula" text field to each component line of a Bill of Materials (BoM). Instead of always using the fixed quantity written on the BoM line, you can write a small calculation that Odoo runs when a manufacturing order is created, and the result becomes the quantity of the component to consume.
The formula can use the BoM line itself, the operation where the component is consumed, the component product, its unit of measure, the quantity of the production order line, and the production order being created. The result must be stored in a variable named quantity. Basic rounding helpers (ceil and floor) are available.
Where it appears: - On the BoM line form, right after the quantity field. - In the list of components inside the BoM form.
Business rules and automatic behaviour: - When you save a formula, Odoo checks that it is valid Python and that it runs without error; otherwise it shows a validation message and refuses to save. - When a manufacturing order is generated, the component quantity is replaced by the formula result if a formula is set; if the field is empty, the normal BoM quantity is used.
It touches the BoM line, the BoM, and the manufacturing order models.
Depends on
Models and fields (2)
- mrp.bom.line · extends an existing modelquantity_formula
- mrp.production · extends an existing model
Text generated by AI (DeepSeek) from reading the Odoo 18.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub
Availability by version
Reviewed: 2026-11-03Confirmation status: 2 confirmed, 7 with no information of 9 versions.
Sources · Odoo 18.0
Confirmed on 2026-11-03 in branch 18.0 of OCA/manufacture.
terminal Installation and usage
OCA documentation · Odoo 18.0Configuration
Source · Odoo 18.0In any BoM line, fill the Quantity Formula field.
The following values are available:
bom_line: the current BoM line,production: the production order being created,product: the Product of current BoM line,product_uom_qty: the quantity of the production order line,product_uom: the UoM of the Product of current BoM line,operation: the operation where the components are consumed for current BoM line,
The computed quantity must be assigned to the quantity variable.
Usage
Source · Odoo 18.0This module can be used to customize the quantity of a component based on a custom attribute value selected on the product. The following configuration works when the website_sale module is installed.
In order to do that, configure as follows:
- Create an attribute "Component quantity" with a custom value
- Create and publish a Product having the configured custom value, and the MTO route (archived by default)
- Add a BoM to the product, where one Component has the following formula for the quantity:
sale_lines = production.move_dest_ids.sale_line_id
produced_template = production.product_tmpl_id
produced_template_sale_line = sale_lines.filtered(lambda l: l.product_template_id == produced_template)
custom_attributes_values = produced_template_sale_line.product_custom_attribute_value_ids.with_context(lang=None)
component_quantity_attribute_value = custom_attributes_values.filtered(
lambda av: av.custom_product_template_attribute_value_id.attribute_id.name == "Component quantity"
)
component_quantity = component_quantity_attribute_value.custom_value
quantity = int(component_quantity)- In the e-commerce, select a quantity for the custom value and buy the product
- Confirm the sale order
a Production order with the selected value of Component will be created
No verified information in OCA: Installation.
Installation instructions, the distribution package, dependencies and configuration steps are not shown because they have not yet been verified in the module documentation for any version.
Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.