diff --git a/mrp_bom_line_formula_quantity/README.rst b/mrp_bom_line_formula_quantity/README.rst new file mode 100644 index 000000000..714b75fa4 --- /dev/null +++ b/mrp_bom_line_formula_quantity/README.rst @@ -0,0 +1,138 @@ +================================= +MRP BoM Line formula for quantity +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7cfb3a88e42e13f128328dd4a63d5bfccdef0769822be4828842019e65c5b98e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/16.0/mrp_bom_line_formula_quantity + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_bom_line_formula_quantity + :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/manufacture&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Compute the quantity of a Production Line using a formula defined in the BoM Line. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +In 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 +===== + +This 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 + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/product_attribute.png + +#. Create and publish a Product having the configured custom value, and the MTO route (archived by default) + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/product_tab_attributes.png +#. Add a BoM to the product, where one Component has the following formula for the quantity: + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/bom.png + + .. code-block:: python + + 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 + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/website_sale_product.png + +#. Confirm the sale order + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/sale_order.png + +a Production order with the selected value of Component will be created + +.. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/production_order.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Aion Tech + +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-SirAionTech| image:: https://github.com/SirAionTech.png?size=40px + :target: https://github.com/SirAionTech + :alt: SirAionTech + +Current `maintainer `__: + +|maintainer-SirAionTech| + +This module is part of the `OCA/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_bom_line_formula_quantity/__init__.py b/mrp_bom_line_formula_quantity/__init__.py new file mode 100644 index 000000000..b18eea379 --- /dev/null +++ b/mrp_bom_line_formula_quantity/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mrp_bom_line_formula_quantity/__manifest__.py b/mrp_bom_line_formula_quantity/__manifest__.py new file mode 100644 index 000000000..2d90eb903 --- /dev/null +++ b/mrp_bom_line_formula_quantity/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "MRP BoM Line formula for quantity", + "summary": "Compute the quantity of a Production Line using a formula in the BoM Line.", + "version": "16.0.1.0.0", + "author": "Aion Tech, Odoo Community Association (OCA)", + "maintainers": [ + "SirAionTech", + ], + "category": "Manufacturing", + "depends": [ + "mrp", + ], + "website": "https://github.com/OCA/manufacture" + "/tree/16.0/mrp_bom_line_formula_quantity", + "license": "AGPL-3", + "data": [ + "views/mrp_bom_line_views.xml", + "views/mrp_bom_views.xml", + ], +} diff --git a/mrp_bom_line_formula_quantity/i18n/it.po b/mrp_bom_line_formula_quantity/i18n/it.po new file mode 100644 index 000000000..4e0638084 --- /dev/null +++ b/mrp_bom_line_formula_quantity/i18n/it.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_line_formula_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-01-24 14:13+0000\n" +"PO-Revision-Date: 2024-01-24 14:13+0000\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: mrp_bom_line_formula_quantity +#: model:ir.model,name:mrp_bom_line_formula_quantity.model_mrp_bom_line +msgid "Bill of Material Line" +msgstr "Riga distinta base" + +#. module: mrp_bom_line_formula_quantity +#: model:ir.model.fields,help:mrp_bom_line_formula_quantity.field_mrp_bom_line__quantity_formula +msgid "" +"Formula to be evaluated when generating the quantity for a production order line.\n" +"The following values are available:\n" +"- bom_line: the current BoM line,\n" +"- operation: the operation where the components are consumed for current BoM line,\n" +"- product: the Product of current BoM line,\n" +"- product_uom: the UoM of the Product of current BoM line,\n" +"- product_uom_qty: the quantity of the production order line,\n" +"- production: the production order being created,\n" +"The computed quantity must be assigned to the `quantity` variable." +msgstr "" +"Formula da valutare durante la generazione della quantità per una riga di ordine di produzione.\n" +"Sono disponibili le seguenti variabili:\n" +"- bom_line: la riga corrente della distinta base,\n" +"- operation: l'operazione in cui i componenti vengono consumati per la riga corrente della distinta base,\n" +"- product: il prodotto della riga corrente della distinta base,\n" +"- product_uom: l'unità di misura del prodotto della riga corrente della distinta base,\n" +"- product_uom_qty: la quantità della riga dell'ordine di produzione,\n" +"- production: l'ordine di produzione che si sta creando,\n" +"La quantità calcolata deve essere assegnata alla variabile `quantity`." + +#. module: mrp_bom_line_formula_quantity +#: model:ir.model,name:mrp_bom_line_formula_quantity.model_mrp_production +msgid "Production Order" +msgstr "Ordine di produzione" + +#. module: mrp_bom_line_formula_quantity +#: model:ir.model.fields,field_description:mrp_bom_line_formula_quantity.field_mrp_bom_line__quantity_formula +msgid "Quantity Formula" +msgstr "Formula per quantità" \ No newline at end of file diff --git a/mrp_bom_line_formula_quantity/models/__init__.py b/mrp_bom_line_formula_quantity/models/__init__.py new file mode 100644 index 000000000..8551b74af --- /dev/null +++ b/mrp_bom_line_formula_quantity/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import mrp_bom_line +from . import mrp_production diff --git a/mrp_bom_line_formula_quantity/models/mrp_bom_line.py b/mrp_bom_line_formula_quantity/models/mrp_bom_line.py new file mode 100644 index 000000000..a32c10487 --- /dev/null +++ b/mrp_bom_line_formula_quantity/models/mrp_bom_line.py @@ -0,0 +1,86 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.exceptions import ValidationError +from odoo.tools.safe_eval import safe_eval, test_python_expr + + +class MRPBomLine(models.Model): + _inherit = "mrp.bom.line" + + quantity_formula = fields.Text( + help="Formula to be evaluated " + "when generating the quantity " + "for a production order line.\n" + "The following values are available:\n" + "- bom_line: the current BoM line,\n" + "- operation: the operation where the components are consumed for current BoM line,\n" + "- product: the Product of current BoM line,\n" + "- product_uom: the UoM of the Product of current BoM line,\n" + "- product_uom_qty: the quantity of the production order line,\n" + "- production: the production order being created,\n" + "The computed quantity " + "must be assigned to the `quantity` variable.", + ) + + @api.constrains( + "quantity_formula", + ) + def _constrain_quantity_formula(self): + for line in self: + quantity_formula = line.quantity_formula + if quantity_formula: + error_message = test_python_expr( + expr=quantity_formula, + mode="exec", + ) + if error_message: + raise ValidationError(error_message) + + def _quantity_formula_values( + self, + product, + product_uom, + product_uom_qty, + production, + operation_id=False, + ): + self.ensure_one() + return { + "bom_line": self, + "operation": self.env["mrp.routing.workcenter"].browse(operation_id), + "product": product, + "product_uom": product_uom, + "product_uom_qty": product_uom_qty, + "production": production, + } + + def _eval_quantity_formula( + self, + product, + product_uom, + product_uom_qty, + production, + operation_id=False, + ): + self.ensure_one() + formula = self.quantity_formula + if formula: + values = self._quantity_formula_values( + product, + product_uom, + product_uom_qty, + production, + operation_id=operation_id, + ) + safe_eval( + formula, + globals_dict=values, + mode="exec", + nocopy=True, + ) + quantity = values.get("quantity", 0) + else: + quantity = None + return quantity diff --git a/mrp_bom_line_formula_quantity/models/mrp_production.py b/mrp_bom_line_formula_quantity/models/mrp_production.py new file mode 100644 index 000000000..daaadef2a --- /dev/null +++ b/mrp_bom_line_formula_quantity/models/mrp_production.py @@ -0,0 +1,35 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class MRPProduction(models.Model): + _inherit = "mrp.production" + + def _get_move_raw_values( + self, + product_id, + product_uom_qty, + product_uom, + operation_id=False, + bom_line=False, + ): + values = super()._get_move_raw_values( + product_id, + product_uom_qty, + product_uom, + operation_id=operation_id, + bom_line=bom_line, + ) + if bom_line: + computed_quantity = bom_line._eval_quantity_formula( + product_id, + product_uom, + product_uom_qty, + self, + operation_id=operation_id, + ) + if computed_quantity is not None: + values["product_uom_qty"] = computed_quantity + return values diff --git a/mrp_bom_line_formula_quantity/readme/CONFIGURE.rst b/mrp_bom_line_formula_quantity/readme/CONFIGURE.rst new file mode 100644 index 000000000..c4e25d969 --- /dev/null +++ b/mrp_bom_line_formula_quantity/readme/CONFIGURE.rst @@ -0,0 +1,12 @@ +In 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. diff --git a/mrp_bom_line_formula_quantity/readme/DESCRIPTION.rst b/mrp_bom_line_formula_quantity/readme/DESCRIPTION.rst new file mode 100644 index 000000000..605fd31d1 --- /dev/null +++ b/mrp_bom_line_formula_quantity/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Compute the quantity of a Production Line using a formula defined in the BoM Line. diff --git a/mrp_bom_line_formula_quantity/readme/USAGE.rst b/mrp_bom_line_formula_quantity/readme/USAGE.rst new file mode 100644 index 000000000..56e38b96a --- /dev/null +++ b/mrp_bom_line_formula_quantity/readme/USAGE.rst @@ -0,0 +1,39 @@ +This 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 + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/product_attribute.png + +#. Create and publish a Product having the configured custom value, and the MTO route (archived by default) + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/product_tab_attributes.png +#. Add a BoM to the product, where one Component has the following formula for the quantity: + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/bom.png + + .. code-block:: python + + 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 + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/website_sale_product.png + +#. Confirm the sale order + + .. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/sale_order.png + +a Production order with the selected value of Component will be created + +.. image:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/production_order.png diff --git a/mrp_bom_line_formula_quantity/static/description/images/bom.png b/mrp_bom_line_formula_quantity/static/description/images/bom.png new file mode 100644 index 000000000..839e3c205 Binary files /dev/null and b/mrp_bom_line_formula_quantity/static/description/images/bom.png differ diff --git a/mrp_bom_line_formula_quantity/static/description/images/product_attribute.png b/mrp_bom_line_formula_quantity/static/description/images/product_attribute.png new file mode 100644 index 000000000..f208e66dc Binary files /dev/null and b/mrp_bom_line_formula_quantity/static/description/images/product_attribute.png differ diff --git a/mrp_bom_line_formula_quantity/static/description/images/product_tab_attributes.png b/mrp_bom_line_formula_quantity/static/description/images/product_tab_attributes.png new file mode 100644 index 000000000..feb5677b5 Binary files /dev/null and b/mrp_bom_line_formula_quantity/static/description/images/product_tab_attributes.png differ diff --git a/mrp_bom_line_formula_quantity/static/description/images/production_order.png b/mrp_bom_line_formula_quantity/static/description/images/production_order.png new file mode 100644 index 000000000..4479157ee Binary files /dev/null and b/mrp_bom_line_formula_quantity/static/description/images/production_order.png differ diff --git a/mrp_bom_line_formula_quantity/static/description/images/sale_order.png b/mrp_bom_line_formula_quantity/static/description/images/sale_order.png new file mode 100644 index 000000000..b4fec4013 Binary files /dev/null and b/mrp_bom_line_formula_quantity/static/description/images/sale_order.png differ diff --git a/mrp_bom_line_formula_quantity/static/description/images/website_sale_product.png b/mrp_bom_line_formula_quantity/static/description/images/website_sale_product.png new file mode 100644 index 000000000..d54f1647a Binary files /dev/null and b/mrp_bom_line_formula_quantity/static/description/images/website_sale_product.png differ diff --git a/mrp_bom_line_formula_quantity/static/description/index.html b/mrp_bom_line_formula_quantity/static/description/index.html new file mode 100644 index 000000000..aa2db962e --- /dev/null +++ b/mrp_bom_line_formula_quantity/static/description/index.html @@ -0,0 +1,467 @@ + + + + + +MRP BoM Line formula for quantity + + + +
+

MRP BoM Line formula for quantity

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

Compute the quantity of a Production Line using a formula defined in the BoM Line.

+

Table of contents

+ +
+

Configuration

+

In 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

+

This 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:

+
    +
  1. Create an attribute “Component quantity” with a custom value

    +https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/product_attribute.png +
  2. +
  3. Create and publish a Product having the configured custom value, and the MTO route (archived by default)

    +https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/product_tab_attributes.png +
  4. +
  5. Add a BoM to the product, where one Component has the following formula for the quantity:

    +https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/bom.png +
    +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)
    +
    +
  6. +
  7. In the e-commerce, select a quantity for the custom value and buy the product

    +https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/website_sale_product.png +
  8. +
  9. Confirm the sale order

    +https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/sale_order.png +
  10. +
+

a Production order with the selected value of Component will be created

+https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_formula_quantity/static/description/images/production_order.png +
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Aion Tech
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

SirAionTech

+

This module is part of the OCA/manufacture project on GitHub.

+

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

+
+
+
+ + diff --git a/mrp_bom_line_formula_quantity/tests/__init__.py b/mrp_bom_line_formula_quantity/tests/__init__.py new file mode 100644 index 000000000..0cefacf8e --- /dev/null +++ b/mrp_bom_line_formula_quantity/tests/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_mrp_bom_line +from . import test_mrp_production diff --git a/mrp_bom_line_formula_quantity/tests/test_mrp_bom_line.py b/mrp_bom_line_formula_quantity/tests/test_mrp_bom_line.py new file mode 100644 index 000000000..8455701ab --- /dev/null +++ b/mrp_bom_line_formula_quantity/tests/test_mrp_bom_line.py @@ -0,0 +1,23 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.fields import first + +from odoo.addons.mrp.tests.common import TestMrpCommon + + +class TestMRPBoMLine(TestMrpCommon): + def test_formula_validation(self): + """The formula of a BoM line is checked for not permitted operations.""" + # Arrange + bom = self.bom_1.copy() + bom_line = first(bom.bom_line_ids) + + # Act + with self.assertRaises(ValidationError) as ve: + bom_line["quantity_formula"] = "import *" + exc_message = ve.exception.args[0] + + # Assert + self.assertIn("invalid syntax", exc_message) diff --git a/mrp_bom_line_formula_quantity/tests/test_mrp_production.py b/mrp_bom_line_formula_quantity/tests/test_mrp_production.py new file mode 100644 index 000000000..13e438d8f --- /dev/null +++ b/mrp_bom_line_formula_quantity/tests/test_mrp_production.py @@ -0,0 +1,33 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.fields import first + +from odoo.addons.mrp.tests.common import TestMrpCommon + + +class TestMRPProduction(TestMrpCommon): + def test_line_quantity(self): + """When a BoM line has a formula for the quantity, + the formula computes the quantity of the generated production order line. + """ + # Arrange + formula_quantity = 10 + bom = self.bom_1.copy() + formula_bom_line = first(bom.bom_line_ids) + formula_bom_line["quantity_formula"] = "quantity = %s" % formula_quantity + # pre-condition + self.assertNotEqual(formula_bom_line.product_qty, formula_quantity) + + # Act + order = self.env["mrp.production"].create( + { + "bom_id": bom.id, + } + ) + + # Assert + formula_order_line = order.move_raw_ids.filtered( + lambda ol: ol.bom_line_id == formula_bom_line + ) + self.assertEqual(formula_order_line.product_uom_qty, formula_quantity) diff --git a/mrp_bom_line_formula_quantity/views/mrp_bom_line_views.xml b/mrp_bom_line_formula_quantity/views/mrp_bom_line_views.xml new file mode 100644 index 000000000..23b17c011 --- /dev/null +++ b/mrp_bom_line_formula_quantity/views/mrp_bom_line_views.xml @@ -0,0 +1,17 @@ + + + + + Add compute quantity fields to BoM Line form view + mrp.bom.line + + + + + + + + diff --git a/mrp_bom_line_formula_quantity/views/mrp_bom_views.xml b/mrp_bom_line_formula_quantity/views/mrp_bom_views.xml new file mode 100644 index 000000000..6b23db4e6 --- /dev/null +++ b/mrp_bom_line_formula_quantity/views/mrp_bom_views.xml @@ -0,0 +1,20 @@ + + + + + Add compute quantity fields to BoM form view + mrp.bom + + + + + + + + diff --git a/setup/mrp_bom_line_formula_quantity/odoo/addons/mrp_bom_line_formula_quantity b/setup/mrp_bom_line_formula_quantity/odoo/addons/mrp_bom_line_formula_quantity new file mode 120000 index 000000000..a64d6ce1e --- /dev/null +++ b/setup/mrp_bom_line_formula_quantity/odoo/addons/mrp_bom_line_formula_quantity @@ -0,0 +1 @@ +../../../../mrp_bom_line_formula_quantity \ No newline at end of file diff --git a/setup/mrp_bom_line_formula_quantity/setup.py b/setup/mrp_bom_line_formula_quantity/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_bom_line_formula_quantity/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)