-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UPD] Updated code with working items. [UPD] Improved logic and added config component domain [UPD] Added readme and default qty [UPD] pre-commit [UPD] pre-commit [UPD] pre-commit Allow search config component by internal ref
- Loading branch information
1 parent
b4d91a7
commit d141569
Showing
15 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
============================================ | ||
Product Configurator Manufacturing Component | ||
============================================ | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Fproduct--configurator-lightgray.png?logo=github | ||
:target: https://github.com/OCA/product-configurator/tree/14.0/product_configurator_mrp_component | ||
:alt: OCA/product-configurator | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/product-configurator-14-0/product-configurator-14-0-product_configurator_mrp_component | ||
:alt: Translate me on Weblate | ||
|
||
|badge1| |badge2| |badge3| |badge4| | ||
|
||
Adds the ability to have configurable products as components on Bill of Materials. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
#. Setup the parent product to contain all attributes/values as the configuration components. | ||
#. Create a BoM for the parent product, and add the configurable components and their qty to the BoM, in the Configurable Components tab. | ||
#. Only configurable products that have all their attribute values in the parent product will be able to be added to the BoM. | ||
|
||
Usage | ||
===== | ||
* When the parent product is configured, the system will look for the first BoM for that product and cycle through the configurable components. | ||
* If a product variant doesn't exist for the configurable component then one will be created with the matching values in the config wizard. | ||
* The parent product BoM will then be modified with a new bom line(s) and configuration set(s) for the new configurable component variants. | ||
* The new parent product variant will be created if one doesn't exist and it's BoM will contain the new configurable components lines. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-configurator/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/product-configurator/issues/new?body=module:%20product_configurator_mrp_component%0Aversion:%2014.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 | ||
~~~~~~~ | ||
|
||
* Open Source Integrators | ||
|
||
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. | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
This module is part of the `OCA/product-configurator <https://github.com/OCA/product-configurator/tree/14.0/product_configurator_mrp_component>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (C) 2022-Today Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Product Configurator Manufacturing Components", | ||
"version": "14.0.1.0.0", | ||
"category": "Manufacturing", | ||
"summary": "BOM Support for configurable products", | ||
"author": "Pledra, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/product-configurator", | ||
"depends": ["product_configurator_mrp"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/mrp_bom.xml", | ||
], | ||
"installable": True, | ||
"auto_install": False, | ||
"development_status": "Beta", | ||
"maintainers": ["PCatinean"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import mrp_bom_line_config | ||
from . import mrp_bom | ||
from . import product_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (C) 2022-Today Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class MRPBoM(models.Model): | ||
_inherit = "mrp.bom" | ||
|
||
bom_line_config_ids = fields.One2many( | ||
"mrp.bom.line.config", "bom_id", string="Configurable Components" | ||
) | ||
available_config_components = fields.Many2many( | ||
"product.template", | ||
compute="_compute_available_config_components", | ||
store=True, | ||
) | ||
|
||
@api.depends("bom_line_config_ids", "product_tmpl_id") | ||
def _compute_available_config_components(self): | ||
"""Compute list of products available for configurable components""" | ||
if self.config_ok and not self.product_id: | ||
for bom in self: | ||
bom.available_config_components = False | ||
products = self.env["product.template"].search( | ||
[ | ||
("config_ok", "=", True), | ||
("id", "!=", bom.product_tmpl_id.id), | ||
( | ||
"id", | ||
"!=", | ||
bom.bom_line_config_ids.mapped("product_tmpl_id").ids, | ||
), | ||
] | ||
) | ||
for prod in products: | ||
prod_vals = prod.mapped("attribute_line_ids.value_ids") | ||
bom_tmpl_values = bom.product_tmpl_id.mapped( | ||
"attribute_line_ids.value_ids" | ||
) | ||
if all(att_val in bom_tmpl_values for att_val in prod_vals): | ||
bom.available_config_components = [(4, prod.id)] |
47 changes: 47 additions & 0 deletions
47
product_configurator_mrp_component/models/mrp_bom_line_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (C) 2022-Today Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class MRPBoMLineConfig(models.Model): | ||
_name = "mrp.bom.line.config" | ||
|
||
def _get_default_product_uom_id(self): | ||
return self.env["uom.uom"].search([], limit=1, order="id").id | ||
|
||
bom_id = fields.Many2one( | ||
"mrp.bom", | ||
string="BoM", | ||
required=True, | ||
) | ||
product_tmpl_id = fields.Many2one( | ||
"product.template", | ||
string="Configurable Product", | ||
required=True, | ||
) | ||
product_qty = fields.Float( | ||
"Quantity", | ||
default=1.0, | ||
required=True, | ||
) | ||
product_uom_id = fields.Many2one( | ||
"uom.uom", | ||
default=_get_default_product_uom_id, | ||
string="Product Unit of Measure", | ||
required=True, | ||
) | ||
available_config_components = fields.Many2many( | ||
"product.template", | ||
related="bom_id.available_config_components", | ||
) | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
@api.model | ||
def name_search(self, name="", args=None, operator="ilike", limit=100): | ||
domain = args or [] | ||
domain += ["|", ("name", operator, name), ("default_code", operator, name)] | ||
return self.search(domain, limit=limit).name_get() |
70 changes: 70 additions & 0 deletions
70
product_configurator_mrp_component/models/product_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (C) 2022-Today Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class ProductConfigSession(models.Model): | ||
_inherit = "product.config.session" | ||
|
||
def create_get_bom(self, variant, product_tmpl_id=None, values=None): | ||
master_bom = self.env["mrp.bom"].search( | ||
[ | ||
("product_tmpl_id", "=", product_tmpl_id.id), | ||
("product_id", "=", False), | ||
], | ||
order="sequence asc", | ||
limit=1, | ||
) | ||
vals = False | ||
for config_component_line in master_bom.bom_line_config_ids: | ||
wizard_values = variant.product_template_attribute_value_ids.mapped( | ||
"product_attribute_value_id" | ||
) | ||
config_component_vals = config_component_line.product_tmpl_id.mapped( | ||
"attribute_line_ids.value_ids" | ||
) | ||
vals = set(wizard_values.ids).intersection(set(config_component_vals.ids)) | ||
component_config_session = self.create_get_session( | ||
config_component_line.product_tmpl_id.id | ||
) | ||
component_config_session.write({"value_ids": [(6, 0, vals)]}) | ||
component_config_session.action_confirm() | ||
component_variant = component_config_session.product_id | ||
|
||
# Look for existing configuration set and if doesn't exist, create it. | ||
bom_line_config_set = self.env["mrp.bom.line.configuration.set"].search( | ||
[("name", "=", component_variant.display_name)], | ||
limit=1, | ||
) | ||
if not bom_line_config_set: | ||
bom_line_config_set = self.env["mrp.bom.line.configuration.set"].create( | ||
{ | ||
"name": component_variant.display_name, | ||
} | ||
) | ||
self.env["mrp.bom.line.configuration"].create( | ||
{ | ||
"config_set_id": bom_line_config_set.id, | ||
"value_ids": [(6, 0, vals)], | ||
} | ||
) | ||
# Look for existing bom line and if doesn't exist, create it. | ||
existing_bom_line = self.env["mrp.bom.line"].search( | ||
[ | ||
("bom_id", "=", master_bom.id), | ||
("product_id", "=", component_config_session.product_id.id), | ||
("config_set_id", "=", bom_line_config_set.id), | ||
], | ||
limit=1, | ||
) | ||
if not existing_bom_line: | ||
self.env["mrp.bom.line"].create( | ||
{ | ||
"bom_id": master_bom.id, | ||
"product_id": component_variant.id, | ||
"config_set_id": bom_line_config_set.id, | ||
"product_qty": config_component_line.product_qty, | ||
} | ||
) | ||
return super().create_get_bom(variant, product_tmpl_id=None, values=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#. Setup the parent product to contain all attributes/values as the configuration components. | ||
#. Create a BoM for the parent product, and add the configurable components and their qty to the BoM, in the Configurable Components tab. | ||
#. Only configurable products that have all their attribute values in the parent product will be able to be added to the BoM. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Adds the ability to have configurable products as components on Bill of Materials. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* When the parent product is configured, the system will look for the first BoM for that product and cycle through the configurable components. | ||
* If a product variant doesn't exist for the configurable component then one will be created with the matching values in the config wizard. | ||
* The parent product BoM will then be modified with a new bom line(s) and configuration set(s) for the new configurable component variants. | ||
* The new parent product variant will be created if one doesn't exist and it's BoM will contain the new configurable components lines. |
2 changes: 2 additions & 0 deletions
2
product_configurator_mrp_component/security/ir.model.access.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_mrp_bom_line_config,access_mrp_bom_line_config,model_mrp_bom_line_config,product_configurator.group_product_configurator_manager,1,1,1,1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<odoo> | ||
|
||
<record id="mrp_bom_configurable_components_inherit" model="ir.ui.view"> | ||
<field name="name">mrp.bom.configure.components</field> | ||
<field name="model">mrp.bom</field> | ||
<field name="inherit_id" ref="mrp.mrp_bom_form_view" /> | ||
<field name="arch" type="xml"> | ||
<page name="components" position="after"> | ||
<page | ||
name="config_components" | ||
string="Configurable Components" | ||
attrs="{'invisible':[('config_ok', '=', False)]}" | ||
> | ||
<field name="available_config_components" invisible="1" /> | ||
<field | ||
name="bom_line_config_ids" | ||
context="{'default_bom_id': active_id, 'default_product_tmpl_id': False}" | ||
> | ||
<tree editable="bottom"> | ||
<field name="available_config_components" invisible="1" /> | ||
<field | ||
name="product_tmpl_id" | ||
domain="[('id', 'in', available_config_components)]" | ||
/> | ||
<field name="product_qty" /> | ||
<field | ||
name="product_uom_id" | ||
options="{'no_open':True,'no_create':True}" | ||
groups="uom.group_uom" | ||
/> | ||
<field name="bom_id" invisible="1" /> | ||
</tree> | ||
<form string="Configure Components"> | ||
<group> | ||
<field | ||
name="available_config_components" | ||
invisible="1" | ||
/> | ||
<field | ||
name="product_tmpl_id" | ||
domain="[('id', 'in', available_config_components)]" | ||
/> | ||
<field name="product_qty" /> | ||
<field | ||
name="product_uom_id" | ||
options="{'no_open':True,'no_create':True}" | ||
groups="uom.group_uom" | ||
/> | ||
</group> | ||
</form> | ||
</field> | ||
</page> | ||
</page> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/product_configurator_mrp_component/odoo/addons/product_configurator_mrp_component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../product_configurator_mrp_component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |