Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions sale_order_add_consumed_components/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
==================================
Sale Order add consumed components
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:108bac1d4201008f5801a728bc3ff6e92dae1e898ec0351042b9af78c2f6b09e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/18.0/sale_order_add_consumed_components
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_order_add_consumed_components
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to update a sales order with the actual consumed
(and sellable) components used from the manufacturing order.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Business Need In many manufacturing workflows, products are sold to
customers via Sales Orders and subsequently manufactured through
Manufacturing Orders (MOs). Often, these manufactured products require
various components that are consumed during production and tracked via
Bills of Materials (BoMs).

However, in certain business scenarios, it's necessary not only to
manufacture a finished product but also to invoice the customer for the
individual components used in production, especially when the components
themselves are valuable, consumable, or customer-specific.

Odoo, by default, does not automatically add consumed components to the
related Sale Order. This leads to:

- Manual effort in identifying and adding consumed items for invoicing.
- Risk of underbilling customers for actual material usage.
- Inconsistencies between manufacturing records and customer billing.

Module Purpose This module addresses the above gap by automatically
adding all ``sale_ok=True`` components that were actually consumed in a
Manufacturing Order to the linked Sale Order. It ensures:

- Full traceability and billing accuracy of component usage.
- Avoidance of double entry by manufacturing and sales teams.

Compatibility with multiple MOs linked to the same SO (incrementing
quantities when the same component is used more than once).

Real word use case: This module is very usefull in a subcontractee
scenario. E.g. the customer is the owner of the component and
endproduct. But the subcontractee is providing operations over the
product and adding components. These components need to be invoiced
separately to the customer. In this scenario, the raw material supplied
by the customer is not saleble. (He already owns it and gives it in
consinee to the subcontractee.) The added components should be set up as
salebale products.

With this module installed and the scenario where consumption of the
components are added to a mo. Upon "mark done" of the MO the consumed
components are added to the sale order. Making them invoicable to the
customer.

Usage
=====

- Sell an end product with a BoM. (Make sure the product is configured
as an MTO)
- Create and process the manufacturing order.
- The BoM components are automatically added to the related sales order
after production is marked as done.
- You can now create an invoice from the sale order with the consumed
components.

Known issues / Roadmap
======================



Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_add_consumed_components%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* OBS Solutions BV

Contributors
------------

- bosd

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-bosd| image:: https://github.com/bosd.png?size=40px
:target: https://github.com/bosd
:alt: bosd

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-bosd|

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/18.0/sale_order_add_consumed_components>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_order_add_consumed_components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions sale_order_add_consumed_components/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Sale Order add consumed components",
"version": "18.0.2.0.0",
"category": "Sales Management",
"summary": "Add consumed components from Manufacturing Order "
"to the originating Sales Order as invoiceable lines.",
"author": "Odoo Community Association (OCA), OBS Solutions BV",
"website": "https://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"depends": ["sale_management", "mrp"],
"demo": ["demo/sale_demo.xml"],
"maintainers": ["bosd"],
"installable": True,
}
58 changes: 58 additions & 0 deletions sale_order_add_consumed_components/demo/sale_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_product_finished" model="product.product">
<field name="name">Finished Product</field>
<field name="list_price">100.0</field>
<field name="type">consu</field>
<field
name="route_ids"
eval="[(4, ref('mrp.route_warehouse0_manufacture')), (4, ref('stock.route_warehouse0_mto'))]"
/>
</record>

<record id="product_product_component_1" model="product.product">
<field name="name">Component 1</field>
<field name="list_price">10.0</field>
<field name="sale_ok" eval="True" />
<field name="type">consu</field>
</record>

<record id="product_product_component_2" model="product.product">
<field name="name">Component 2</field>
<field name="list_price">15.0</field>
<field name="type">consu</field>
</record>

<record id="mrp_bom_finished" model="mrp.bom">
<field
name="product_tmpl_id"
ref="sale_order_add_consumed_components.product_product_finished_product_template"
/>
<field name="product_qty">1.0</field>
</record>

<record id="mrp_bom_line_1" model="mrp.bom.line">
<field name="bom_id" ref="mrp_bom_finished" />
<field name="product_id" ref="product_product_component_1" />
<field name="product_qty">2.0</field>
</record>

<record id="mrp_bom_line_2" model="mrp.bom.line">
<field name="bom_id" ref="mrp_bom_finished" />
<field name="product_id" ref="product_product_component_2" />
<field name="product_qty">3.0</field>
</record>

<record id="demo_sale_order" model="sale.order">
<field name="partner_id" ref="base.res_partner_1" />
<field
name="order_line"
eval="[(0, 0, {
'product_id': ref('product_product_finished'),
'product_uom_qty': 1.0,
'product_uom': ref('uom.product_uom_unit'),
'price_unit': 100.0
})]"
/>
</record>
</odoo>
5 changes: 5 additions & 0 deletions sale_order_add_consumed_components/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# © 2025 OBS Solutions
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import mrp_production
from . import sale_order_line
106 changes: 106 additions & 0 deletions sale_order_add_consumed_components/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# © 2025 OBS Solutions
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class MrpProduction(models.Model):
_inherit = "mrp.production"

def action_add_consumed_components_to_sale(self):
for mo in self:
if not mo.origin:
continue

sale_order = self.env["sale.order"].search(
[("name", "=", mo.origin)], limit=1
)
if not sale_order:
_logger.info(f"No Sale Order found with origin {mo.origin}")
continue

so_line_map = {line.product_id.id: line for line in sale_order.order_line}

for move in mo.move_raw_ids:
product = move.product_id
if not product.sale_ok:
continue

quantity = move.quantity
if not quantity:
continue

if product.id in so_line_map:
# Update existing sale order line quantity
so_line = so_line_map[product.id]
so_line.product_uom_qty += quantity
so_line.qty_delivered += quantity
else:
SaleOrderLine = self.env["sale.order.line"]

# Calculate price based on the sale order's pricelist
# Get the price from the product with the pricelist applied
date_order = sale_order.date_order or fields.Date.context_today(
sale_order
)
# Get price from pricelist for this product
price = sale_order.pricelist_id._get_product_price(
product,
quantity=quantity,
uom=product.uom_id,
date=date_order,
partner=sale_order.partner_id,
)

so_line = SaleOrderLine.create(
{
"order_id": sale_order.id,
"product_id": product.id,
"product_uom_qty": quantity,
"product_uom": product.uom_id.id,
"price_unit": price,
"name": product.display_name,
"qty_delivered_method": "manual",
"is_mrp_component_line": True,
# 'qty_delivered': quantity,
# 'route_id': False,
}
)
so_line.qty_delivered = quantity
# so_line.product_uom_qty = quantity
_logger.info(
"Added product %s to sale order %s",
product.display_name,
sale_order.name,
)

def button_mark_done(self):
res = super().button_mark_done()
for mo in self:
mo.action_add_consumed_components_to_sale()
return res

# Fix the domain so the smartbutton on the SO
# will not show the individual components
@api.depends("procurement_group_id")
def _compute_mrp_production_ids(self):
for sale in self:
productions = (
self.env["mrp.production"].search(
[
(
"procurement_group_id",
"=",
sale.procurement_group_id.id,
)
]
)
if sale.procurement_group_id
else self.env["mrp.production"]
)
sale.mrp_production_ids = productions
sale.mrp_production_count = len(productions)
13 changes: 13 additions & 0 deletions sale_order_add_consumed_components/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import fields, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

is_mrp_component_line = fields.Boolean("Added from MO Component", default=False)

def _action_launch_stock_rule(self, previous_product_uom_qty=False):
lines = self.filtered(lambda ln: not ln.is_mrp_component_line)
return super(SaleOrderLine, lines)._action_launch_stock_rule(
previous_product_uom_qty=previous_product_uom_qty
)
3 changes: 3 additions & 0 deletions sale_order_add_consumed_components/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
32 changes: 32 additions & 0 deletions sale_order_add_consumed_components/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Business Need
In many manufacturing workflows, products are sold to customers via Sales Orders and subsequently manufactured through Manufacturing Orders (MOs). Often, these manufactured products require various components that are consumed during production and tracked via Bills of Materials (BoMs).

However, in certain business scenarios, it's necessary not only to manufacture a finished product but also to invoice the customer for the individual components used in production, especially when the components themselves are valuable, consumable, or customer-specific.


Odoo, by default, does not automatically add consumed components to the related Sale Order. This leads to:

- Manual effort in identifying and adding consumed items for invoicing.
- Risk of underbilling customers for actual material usage.
- Inconsistencies between manufacturing records and customer billing.

Module Purpose
This module addresses the above gap by automatically adding all `sale_ok=True` components that were actually consumed in a Manufacturing Order to the linked Sale Order. It ensures:

- Full traceability and billing accuracy of component usage.
- Avoidance of double entry by manufacturing and sales teams.

Compatibility with multiple MOs linked to the same SO (incrementing quantities when the same component is used more than once).

Real word use case:
This module is very usefull in a subcontractee scenario.
E.g. the customer is the owner of the component and endproduct.
But the subcontractee is providing operations over the product and adding components.
These components need to be invoiced separately to the customer.
In this scenario, the raw material supplied by the customer is not saleble.
(He already owns it and gives it in consinee to the subcontractee.)
The added components should be set up as salebale products.

With this module installed and the scenario where consumption of the components are added to a mo.
Upon "mark done" of the MO the consumed components are added to the sale order.
Making them invoicable to the customer.
1 change: 1 addition & 0 deletions sale_order_add_consumed_components/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- bosd
1 change: 1 addition & 0 deletions sale_order_add_consumed_components/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows you to update a sales order with the actual consumed (and sellable) components used from the manufacturing order.
1 change: 1 addition & 0 deletions sale_order_add_consumed_components/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 5 additions & 0 deletions sale_order_add_consumed_components/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Sell an end product with a BoM.
(Make sure the product is configured as an MTO)
- Create and process the manufacturing order.
- The BoM components are automatically added to the related sales order after production is marked as done.
- You can now create an invoice from the sale order with the consumed components.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading