Skip to content
Merged
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
89 changes: 89 additions & 0 deletions stock_request_bom/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
=================
Stock Request BOM
=================

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

.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--request-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-request/tree/18.0/stock_request_bom
:alt: OCA/stock-logistics-request
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-request-18-0/stock-logistics-request-18-0-stock_request_bom
: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/stock-logistics-request&target_branch=18.0
:alt: Try me on Runboat

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

This module enhances the stock request functionality by integrating with
the Bill of Materials (BOM).

Key Features: - Adds Product BOM and Quantity BOM fields to stock
request orders. - Auto-completes stock request lines based on the
selected BOM and quantity. - Allows updating and clearing BOM
selections.

**Table of contents**

.. contents::
:local:

Usage
=====

1. Select a Product BOM and enter a Quantity BOM.
2. Stock request lines will auto-fill with BOM components.
3. Adjust quantity BOM as needed.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-request/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/stock-logistics-request/issues/new?body=module:%20stock_request_bom%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
-------

* ForgeFlow

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

- Joan Sisquella Andrés <[email protected]>

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.

This module is part of the `OCA/stock-logistics-request <https://github.com/OCA/stock-logistics-request/tree/18.0/stock_request_bom>`_ 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 stock_request_bom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions stock_request_bom/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Request BOM",
"summary": "Stock Request with BOM Integration",
"version": "18.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-request",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"category": "Warehouse Management",
"depends": ["stock_request", "mrp"],
"data": [
"views/stock_request_order_views.xml",
],
"installable": True,
"auto_install": True,
}
51 changes: 51 additions & 0 deletions stock_request_bom/i18n/stock_request_bom.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_request_bom
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_request_bom
#: code:addons/stock_request_bom/models/stock_request_order.py:0
#, python-format
msgid "No BOM found for the selected product."
msgstr ""

#. module: stock_request_bom
#: model:ir.model.fields,field_description:stock_request_bom.field_stock_request_order__product_bom_id
msgid "Product BOM"
msgstr ""

#. module: stock_request_bom
#: model:ir.model.fields,field_description:stock_request_bom.field_stock_request_order__quantity_bom
msgid "Quantity BOM"
msgstr ""

#. module: stock_request_bom
#: model:ir.model.fields,help:stock_request_bom.field_stock_request_order__product_bom_id
msgid "Select a product with a BOM to auto-complete stock request lines."
msgstr ""

#. module: stock_request_bom
#: model:ir.model.fields,help:stock_request_bom.field_stock_request_order__quantity_bom
msgid "Specify the quantity for the Product BOM."
msgstr ""

#. module: stock_request_bom
#: model:ir.model,name:stock_request_bom.model_stock_request_order
msgid "Stock Request Order"
msgstr ""

#. module: stock_request_bom
#: code:addons/stock_request_bom/models/stock_request_order.py:0
#, python-format
msgid "The quantity BOM must be a positive value."
msgstr ""
1 change: 1 addition & 0 deletions stock_request_bom/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_request_order
80 changes: 80 additions & 0 deletions stock_request_bom/models/stock_request_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError


class StockRequestOrder(models.Model):
_inherit = "stock.request.order"

product_bom_id = fields.Many2one(
"product.product",
string="Product BOM",
domain="[('bom_ids', '!=', False)]",
help="Select a product with a BOM to auto-complete stock request lines.",
)
quantity_bom = fields.Float(
string="Quantity BOM",
help="Specify the quantity for the Product BOM.",
default=1.0,
)

@api.constrains("quantity_bom")
def _check_quantity_bom(self):
for order in self:
if order.quantity_bom <= 0:
raise ValidationError(_("The quantity BOM must be a positive value."))

def _prepare_bom_line(self, product, line, line_qty):
"""Prepare a dictionary for a BOM line."""
return {
"product_id": product.id,
"product_uom_id": line.product_uom_id.id,
"product_uom_qty": line_qty,
"warehouse_id": self.warehouse_id.id,
"location_id": self.location_id.id,
"company_id": self.company_id.id,
"requested_by": self.requested_by.id,
"expected_date": self.expected_date,
}

def _get_bom_lines_recursive(self, bom, quantity):
"""Recursively fetch BOM lines for a given BOM and quantity."""
bom_lines = []
bom_done, lines_done = bom.explode(self.product_bom_id, quantity)
for line, line_data in lines_done:
product = line.product_id
line_qty = line_data["qty"]
sub_bom = self.env["mrp.bom"]._bom_find(product).get(product)
if sub_bom:
# Recursively fetch lines from the sub-BOM
bom_lines += self._get_bom_lines_recursive(
sub_bom, line_qty / sub_bom.product_qty
)
else:
# Add the line directly if no sub-BOM is found
bom_lines.append(
(
0,
0,
self._prepare_bom_line(product, line, line_qty),
)
)
return bom_lines

@api.onchange("product_bom_id", "quantity_bom")
def _onchange_product_bom(self):
if not self.product_bom_id:
self.stock_request_ids = [(5, 0, 0)]
return

bom = (
self.env["mrp.bom"]._bom_find(self.product_bom_id).get(self.product_bom_id)
)
if not bom:
raise UserError(_("No BOM found for the selected product."))
# Clear the existing stock request lines
self.stock_request_ids = [(5, 0, 0)]
bom_lines = self._get_bom_lines_recursive(bom, self.quantity_bom)
self.stock_request_ids = bom_lines
3 changes: 3 additions & 0 deletions stock_request_bom/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions stock_request_bom/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Joan Sisquella Andrés \<[email protected]\>
7 changes: 7 additions & 0 deletions stock_request_bom/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module enhances the stock request functionality by integrating with
the Bill of Materials (BOM).

Key Features: - Adds Product BOM and Quantity BOM fields to stock
request orders. - Auto-completes stock request lines based on the
selected BOM and quantity. - Allows updating and clearing BOM
selections.
3 changes: 3 additions & 0 deletions stock_request_bom/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. Select a Product BOM and enter a Quantity BOM.
2. Stock request lines will auto-fill with BOM components.
3. Adjust quantity BOM as needed.
Binary file added stock_request_bom/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading