Metadata-Version: 2.1
Name: odoo-addon-sale_order_add_byproduct
Version: 18.0.2.0.0.2
Requires-Python: >=3.10
Requires-Dist: odoo==18.0.*
Summary: Add produced by-products from Manufacturing Order to the originating Sales Order as invoiceable lines.
Home-page: https://github.com/OCA/sale-workflow
License: AGPL-3
Author: Odoo Community Association (OCA), OBS Solutions BV
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 18.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Description-Content-Type: text/x-rst

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

===================================
Sale Order add produced by-products
===================================

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

.. |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/license-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_byproduct
    :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_byproduct
    :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 extends the functionality of Manufacturing Orders to
automatically transfer produced by-products to the associated Sale Order
once the Manufacturing Order is closed. This allows for easier invoicing
and management of by-products sold to customers.

Key Features
------------

- Automatically adds/updates Sale Order Lines for by-products when a
  Manufacturing Order is marked as 'done'.
- Prevents additional Manufacturing Orders or procurements from being
  triggered for these by-product lines, as they are a result of existing
  production.
- Ensures accurate tracking of by-product quantities on the Sale Order
  for invoicing purposes.

**Table of contents**

.. contents::
   :local:

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

Business Use Case: By-product Invoicing for Contract Manufacturers
==================================================================

This module is designed for contract manufacturing scenarios where the
client provides raw materials or a base product for processing. Unlike
standard manufacturing where the output quantity of finished goods is
precisely known, this use case involves a process where the exact yield
of **by-products** is uncertain until after the manufacturing operation
is complete.

Scenario
--------

A contract manufacturer processes materials supplied by a client. During
this process, in addition to any primary output, a variable quantity of
by-products is inevitably generated. The client is obligated to purchase
these by-products from the contract manufacturer.

Problem
-------

At the time of sale order creation, it is impossible to accurately
determine the quantity of by-products that will be produced from the
manufacturing process. Therefore, these by-products cannot be initially
included on the sales order for invoicing. Traditional Odoo MRP
workflows are designed for planned production, not for dynamic
by-product quantification for sales.

Solution
--------

This module automates the process of adding the actual, measured
quantities of produced by-products to the corresponding sales order.
Once the Manufacturing Order (MO) for the client's material is completed
(marked as 'done'):

1. The module identifies all by-products that were actually produced
   during that specific MO.
2. **It filters these by-products, adding only those that are configured
   as "Can be Sold" (``sale_ok=True``).**
3. It then adds these filtered by-products, along with their actual
   quantities, as new lines (or updates existing lines) on the original
   sales order linked to that MO.
4. These by-product lines are flagged to ensure they do not trigger new
   manufacturing orders or procurement requests, as their supply comes
   directly from the completed production.

Benefits
--------

- **Accurate Invoicing:** Ensures clients are correctly billed for all
  by-products generated during the contract manufacturing process,
  preventing revenue loss.
- **Streamlined Operations:** Automates the manual task of reconciling
  by-product quantities and adding them to sales orders.
- **Improved Traceability:** Maintains a clear link between the
  manufacturing process and the resulting by-product sales.
- **Enhanced Reporting:** Allows for better reporting on by-product
  yields and sales for analysis and compliance.

Configuration
=============

No specific configuration is required for this module to function,
beyond the standard Odoo setup for Manufacturing Orders, Bills of
Materials (BOMs), and Products.

However, for optimal use:

- **By-product Products**: Ensure your by-product products are correctly
  defined in Odoo, ideally belonging to a specific product category
  (e.g., 'By-products').

  - **Crucially, the by-product product must have its "Can be Sold"
    (``sale_ok``) field set to ``True``** in its product form under the
    "Sales" tab. By-products with ``sale_ok = False`` will be ignored by
    this module and will not be added to the Sales Order.

- **BOMs with By-products**: Your Bills of Materials (BOMs) for your
  main manufactured products must have the relevant by-products
  configured under the "By-products" tab with their planned quantities.

Usage
=====

1. **Create a Sales Order (SO)** for the main product that your client
   will receive.

   - The main product should have a Bill of Materials (BOM) defined that
     includes the by-products under its "By-products" tab.
   - The main product's inventory route should be configured for
     "Manufacture" (or "Make to Order" if applicable).

2. **Confirm the Sales Order**. This will automatically generate a
   Manufacturing Order (MO) for the main product.
3. **Process the Manufacturing Order**:

   - Navigate to the generated Manufacturing Order.
   - Ensure all necessary raw materials are available.
   - Move the MO through its production stages (e.g., confirm, plan,
     start production, consume components).
   - **Crucially, ensure the actual quantities produced for the
     by-products are recorded** on the MO's respective moves (e.g., on
     the ``stock.move`` records associated with the by-products,
     typically under the 'Finished Products' or 'By-products' tab of the
     MO, the 'Done' quantity should reflect the actual yield).

4. **Mark the Manufacturing Order as Done**. This is the trigger for the
   module's automation.
5. **Verify the Sales Order**:

   - Go back to the Sales Order that was linked to the completed MO.
   - You will find new line(s) added (or existing lines updated) for the
     by-product(s) with their actual produced quantities from the MO.
   - These by-product lines will be flagged internally
     (``is_mrp_byproduct_line = True``) to prevent them from triggering
     new, unnecessary manufacturing orders or procurement requests.

6. **Invoice the Client**: You can now proceed to create an invoice from
   the Sales Order, which will include the by-products for billing to
   your client.

This automated process ensures that clients are accurately billed for
all by-products generated during the contract manufacturing process.

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_byproduct%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_byproduct>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
