-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD]product_configurator_mrp_quantity
- Loading branch information
1 parent
c8324a3
commit ff460fe
Showing
28 changed files
with
1,553 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,96 @@ | ||
================================= | ||
Product Configurator MRP Quantity | ||
================================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:063e1950e625643c35ac391930663d43b87029135206c6de4aff60eec0a9295e | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/17.0/product_configurator_mrp_quantity | ||
: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-17-0/product-configurator-17-0-product_configurator_mrp_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/product-configurator&target_branch=17.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module enhances the Product Configurator MRP Quantity functionality | ||
by introducing dynamic quantity adjustments within the Product | ||
Configurator Wizard. Users can now define specific attributes that allow | ||
for quantity variations during the configuration process. | ||
|
||
The quantity field becomes visible only when a specific checkbox is | ||
selected on the corresponding attribute line within the product | ||
template. | ||
|
||
By default, the quantity field displays a value of "1" which can be | ||
modified by the user during configuration. | ||
|
||
This functionality offers greater flexibility and customization for | ||
users by enabling: | ||
|
||
Configurable Quantity Adjustments: Define attributes that directly | ||
impact the quantity of materials required for a product based on user | ||
selection. Streamlined MRP Integration: Dynamic quantity adjustments | ||
automatically reflect in the Material Requirements Planning (MRP) | ||
process, ensuring accurate inventory calculations. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
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 to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/product-configurator/issues/new?body=module:%20product_configurator_mrp_quantity%0Aversion:%2017.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 | ||
|
||
Contributors | ||
------------ | ||
|
||
- Vandan Pandeji <<[email protected]>> | ||
- Patrick Wilson <<[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/product-configurator <https://github.com/OCA/product-configurator/tree/17.0/product_configurator_mrp_quantity>`_ 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,2 @@ | ||
from . import models | ||
from . import wizard |
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,22 @@ | ||
{ | ||
"name": "Product Configurator MRP Quantity", | ||
"version": "17.0.1.0.0", | ||
"category": "Manufacturing", | ||
"summary": "Configuration for adding quantity in product configurator.", | ||
"author": "Open Source Integrators,Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/product-configurator", | ||
"depends": ["product_configurator", "product_configurator_mrp"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/product_view.xml", | ||
"views/product_attribute_view.xml", | ||
"wizard/product_configurator_view.xml", | ||
"views/product_config_view.xml", | ||
], | ||
"images": ["static/description/cover.png"], | ||
"development_status": "Beta", | ||
"maintainer": "Open Source Integrators", | ||
"installable": True, | ||
"auto_install": False, | ||
} |
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 product_config | ||
from . import product_attribute | ||
from . import product |
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,54 @@ | ||
from odoo import api, fields, models | ||
from odoo.tools.sql import drop_index, index_exists | ||
|
||
|
||
class ProductProductAttributeValueQty(models.Model): | ||
_name = "product.product.attribute.value.qty" | ||
_description = "A link between variants and attributes and the quantity of that combination Fields" | ||
|
||
product_id = fields.Many2one( | ||
"product.product", string="Product Variant", ondelete="cascade" | ||
) | ||
attr_value_id = fields.Many2one("product.attribute.value", required=True) | ||
qty = fields.Integer(string="Quantity") | ||
|
||
@api.depends("attr_value_id", "qty") | ||
def _compute_display_name(self): | ||
res = super()._compute_display_name() | ||
for rec in self: | ||
if rec.attr_value_id and rec.qty: | ||
rec.display_name = ( | ||
rec.attr_value_id.display_name + "(" + str(rec.qty) + ")" | ||
) | ||
return res | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
_rec_name = "config_name" | ||
|
||
@api.depends("product_attribute_value_qty_ids") | ||
def _compute_qty_combination_indices(self): | ||
for product in self: | ||
qty_combination_indices = product.product_attribute_value_qty_ids.mapped( | ||
"qty" | ||
) | ||
product.qty_combination_indices = ",".join( | ||
[str(i) for i in sorted(qty_combination_indices)] | ||
) | ||
|
||
product_attribute_value_qty_ids = fields.One2many( | ||
"product.product.attribute.value.qty", "product_id" | ||
) | ||
qty_combination_indices = fields.Char( | ||
compute="_compute_qty_combination_indices", store=True, index=True | ||
) | ||
|
||
def init(self): | ||
if index_exists(self.env.cr, "product_product_combination_unique"): | ||
drop_index(self.env.cr, "product_product_combination_unique", self._table) | ||
|
||
self.env.cr.execute( | ||
"CREATE UNIQUE INDEX IF NOT EXISTS product_product_combination_qty_attrs_unique ON %s (product_tmpl_id, combination_indices,qty_combination_indices) WHERE active is true" | ||
% self._table | ||
) |
29 changes: 29 additions & 0 deletions
29
product_configurator_mrp_quantity/models/product_attribute.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,29 @@ | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProductAttributeLine(models.Model): | ||
_inherit = "product.template.attribute.line" | ||
|
||
is_qty_required = fields.Boolean(string="Qty Required", copy=False) | ||
|
||
|
||
class ProductAttributePrice(models.Model): | ||
_inherit = "product.template.attribute.value" | ||
|
||
is_qty_required = fields.Boolean( | ||
related="attribute_line_id.is_qty_required", | ||
store=True, | ||
string="Qty Required", | ||
copy=False, | ||
) | ||
default_qty = fields.Integer("Default Quantity", default=1) | ||
maximum_qty = fields.Integer("Max Quantity", default=1) | ||
|
||
@api.constrains("default_qty", "maximum_qty") | ||
def _check_default_qty_maximum_qty(self): | ||
for rec in self: | ||
if rec.default_qty > rec.maximum_qty: | ||
raise ValidationError( | ||
_("Maximum Qty can't be smaller then Default Qty") | ||
) |
Oops, something went wrong.