diff --git a/product_optional_product_quantity/README.rst b/product_optional_product_quantity/README.rst new file mode 100644 index 00000000000..f0b3b167d03 --- /dev/null +++ b/product_optional_product_quantity/README.rst @@ -0,0 +1,106 @@ +================================= +Product Optional Product Quantity +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:19c5748e08443684d61807c9a609fcd25cd03d10eb4a7420bd715a19eefb771f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/18.0/product_optional_product_quantity + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_optional_product_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-attribute&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module implements core functionality for the optional product +quantity multipliers. You can depend on this module to implement further +user features. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +Odoo has an option to define optional products for products. However +sometimes optional product may have different quantity in relation to +the main one. For example you have a "Tea party set" product which +consists of 4 tea cups. Your customers can also buy same cups +separately. In this case "Tea cup" will be an optional product for "Tee +party set" with quantity multiplier 4. So when you add  "Tear party set" +with quantity=2 to quotation "Tea cup" with quantity=8 will be added in +the "Optional products" tab.  + +Configuration +============= + +Go to Settings > Sales tab In the "Product Catalog" section enable +"Optional Products Quantity" feature + +Open a product and go to the "Sales" tab. Add optional products with +quantities in the "Optional Products" field. + +Usage +===== + +Usage flow is implemented in modules depending on this one. + +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 +------- + +* Cetmix + +Contributors +------------ + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_optional_product_quantity/__init__.py b/product_optional_product_quantity/__init__.py new file mode 100644 index 00000000000..88b2aa93281 --- /dev/null +++ b/product_optional_product_quantity/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/product_optional_product_quantity/__manifest__.py b/product_optional_product_quantity/__manifest__.py new file mode 100644 index 00000000000..1eedaee307c --- /dev/null +++ b/product_optional_product_quantity/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Product Optional Product Quantity", + "version": "18.0.1.0.0", + "category": "Product", + "summary": "Specify optional products quantity for product", + "author": "Cetmix, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/product-attribute", + "license": "AGPL-3", + "depends": [ + "sale", + ], + "data": [ + "security/res_groups.xml", + "security/ir.model.access.csv", + "views/product_template_views.xml", + "views/res_config_settings_views.xml", + ], + "installable": True, + "auto_install": False, +} diff --git a/product_optional_product_quantity/i18n/es.po b/product_optional_product_quantity/i18n/es.po new file mode 100644 index 00000000000..c0b63b7ff6f --- /dev/null +++ b/product_optional_product_quantity/i18n/es.po @@ -0,0 +1,137 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_optional_product_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-03-26 22:36+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__company_id +msgid "Company" +msgstr "Compañía" + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_res_config_settings +msgid "Config Settings" +msgstr "Ajustes Config" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__create_date +msgid "Created on" +msgstr "Creado el" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__id +msgid "ID" +msgstr "ID" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__write_date +msgid "Last Updated on" +msgstr "Última Actualización Realizada el" + +#. module: product_optional_product_quantity +#: model_terms:ir.ui.view,arch_db:product_optional_product_quantity.res_config_settings_view_form +msgid "Manage quantities of optional products" +msgstr "Gestionar las cantidades de productos opcionales" + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_product_optional_line +msgid "Optional Product" +msgstr "Producto Opcional" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_product__optional_product_ids +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_template__optional_product_ids +msgid "Optional Products" +msgstr "Productos Opcionales" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_product__product_optional_line_ids +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_template__product_optional_line_ids +msgid "Optional Products Line" +msgstr "Línea Productos Opcionales" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_res_config_settings__group_product_optional_quantity +msgid "Optional Products Quantity" +msgstr "Productos Opcionales Cantidad" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,help:product_optional_product_quantity.field_product_product__optional_product_ids +#: model:ir.model.fields,help:product_optional_product_quantity.field_product_template__optional_product_ids +msgid "" +"Optional Products are suggested whenever the customer hits *Add to Cart* " +"(cross-sell strategy, e.g. for computers: warranty, software, etc.)." +msgstr "" +"Los Productos opcionales se sugieren cada vez que el cliente pulsa *Añadir " +"al carrito* (estrategia de venta cruzada, por ejemplo, para ordenadores: " +"garantía, software, etc.)." + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_product_template +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__optional_product_tmpl_id +msgid "Product" +msgstr "Producto" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__quantity +msgid "Quantity" +msgstr "Cantidad" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__product_tmpl_id +msgid "Related Product" +msgstr "Productos Relacionados" + +#. module: product_optional_product_quantity +#: model:res.groups,name:product_optional_product_quantity.group_product_optional_quantity +msgid "Use Optional Products Quantity" +msgstr "Utilizar Productos Opcionales Cantidad" + +#. module: product_optional_product_quantity +#. odoo-python +#: code:addons/product_optional_product_quantity/models/product_optional_line.py:0 +#, python-format +msgid "You can't add product this line is related to as optional." +msgstr "" +"No se puede añadir como opcional el producto con el que está relacionada " +"esta línea." + +#. module: product_optional_product_quantity +#. odoo-python +#: code:addons/product_optional_product_quantity/models/product_optional_line.py:0 +#, python-format +msgid "You can't add two same products as optional." +msgstr "No puedes añadir dos productos iguales como opcionales." diff --git a/product_optional_product_quantity/i18n/it.po b/product_optional_product_quantity/i18n/it.po new file mode 100644 index 00000000000..b2678627155 --- /dev/null +++ b/product_optional_product_quantity/i18n/it.po @@ -0,0 +1,137 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_optional_product_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-10-03 18:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__company_id +msgid "Company" +msgstr "Azienda" + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_res_config_settings +msgid "Config Settings" +msgstr "Impostazioni configurazione" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__create_uid +msgid "Created by" +msgstr "Creato da" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__create_date +msgid "Created on" +msgstr "Creato il" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__id +msgid "ID" +msgstr "ID" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__write_uid +msgid "Last Updated by" +msgstr "Ultimo aggiornamento di" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__write_date +msgid "Last Updated on" +msgstr "Ultimo aggiornamento il" + +#. module: product_optional_product_quantity +#: model_terms:ir.ui.view,arch_db:product_optional_product_quantity.res_config_settings_view_form +msgid "Manage quantities of optional products" +msgstr "Gestione quantità di prodotti opzionali" + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_product_optional_line +msgid "Optional Product" +msgstr "Prodotto opzionale" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_product__optional_product_ids +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_template__optional_product_ids +msgid "Optional Products" +msgstr "Prodotti opzionali" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_product__product_optional_line_ids +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_template__product_optional_line_ids +msgid "Optional Products Line" +msgstr "Linea di Prodotti Opzionale" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_res_config_settings__group_product_optional_quantity +msgid "Optional Products Quantity" +msgstr "Quantità prodotti opzionali" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,help:product_optional_product_quantity.field_product_product__optional_product_ids +#: model:ir.model.fields,help:product_optional_product_quantity.field_product_template__optional_product_ids +msgid "" +"Optional Products are suggested whenever the customer hits *Add to Cart* " +"(cross-sell strategy, e.g. for computers: warranty, software, etc.)." +msgstr "" +"I prodotti opzionali sono suggeriti quando il cliente fa clic su \"Aggiungi " +"al carrello\" (strategia cross-selling, es. per computer: garanzia, " +"programmi, ecc.)." + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_product_template +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__optional_product_tmpl_id +msgid "Product" +msgstr "Prodotto" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__quantity +msgid "Quantity" +msgstr "Quantità" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__product_tmpl_id +msgid "Related Product" +msgstr "Prodotto collegato" + +#. module: product_optional_product_quantity +#: model:res.groups,name:product_optional_product_quantity.group_product_optional_quantity +msgid "Use Optional Products Quantity" +msgstr "Usare quantità prodotti opzionali" + +#. module: product_optional_product_quantity +#. odoo-python +#: code:addons/product_optional_product_quantity/models/product_optional_line.py:0 +#, python-format +msgid "You can't add product this line is related to as optional." +msgstr "" +"Non è possibile aggiungere il prodotto a cui è correlata questa riga come " +"facoltativo." + +#. module: product_optional_product_quantity +#. odoo-python +#: code:addons/product_optional_product_quantity/models/product_optional_line.py:0 +#, python-format +msgid "You can't add two same products as optional." +msgstr "Non è possibile aggiungere due prodotti uguali come facoltativi." diff --git a/product_optional_product_quantity/i18n/product_optional_product_quantity.pot b/product_optional_product_quantity/i18n/product_optional_product_quantity.pot new file mode 100644 index 00000000000..745506d144d --- /dev/null +++ b/product_optional_product_quantity/i18n/product_optional_product_quantity.pot @@ -0,0 +1,129 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_optional_product_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__company_id +msgid "Company" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__create_uid +msgid "Created by" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__create_date +msgid "Created on" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__display_name +msgid "Display Name" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__id +msgid "ID" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__write_date +msgid "Last Updated on" +msgstr "" + +#. module: product_optional_product_quantity +#: model_terms:ir.ui.view,arch_db:product_optional_product_quantity.res_config_settings_view_form +msgid "Manage quantities of optional products" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_product_optional_line +msgid "Optional Product" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_product__optional_product_ids +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_template__optional_product_ids +msgid "Optional Products" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_product__product_optional_line_ids +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_template__product_optional_line_ids +msgid "Optional Products Line" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_res_config_settings__group_product_optional_quantity +msgid "Optional Products Quantity" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,help:product_optional_product_quantity.field_product_product__optional_product_ids +#: model:ir.model.fields,help:product_optional_product_quantity.field_product_template__optional_product_ids +msgid "" +"Optional Products are suggested whenever the customer hits *Add to Cart* " +"(cross-sell strategy, e.g. for computers: warranty, software, etc.)." +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model,name:product_optional_product_quantity.model_product_template +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__optional_product_tmpl_id +msgid "Product" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__quantity +msgid "Quantity" +msgstr "" + +#. module: product_optional_product_quantity +#: model:ir.model.fields,field_description:product_optional_product_quantity.field_product_optional_line__product_tmpl_id +msgid "Related Product" +msgstr "" + +#. module: product_optional_product_quantity +#: model:res.groups,name:product_optional_product_quantity.group_product_optional_quantity +msgid "Use Optional Products Quantity" +msgstr "" + +#. module: product_optional_product_quantity +#. odoo-python +#: code:addons/product_optional_product_quantity/models/product_optional_line.py:0 +#, python-format +msgid "You can't add product this line is related to as optional." +msgstr "" + +#. module: product_optional_product_quantity +#. odoo-python +#: code:addons/product_optional_product_quantity/models/product_optional_line.py:0 +#, python-format +msgid "You can't add two same products as optional." +msgstr "" diff --git a/product_optional_product_quantity/models/__init__.py b/product_optional_product_quantity/models/__init__.py new file mode 100644 index 00000000000..47cefa79d1f --- /dev/null +++ b/product_optional_product_quantity/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import product_optional_line +from . import res_config_settings +from . import product_template diff --git a/product_optional_product_quantity/models/product_optional_line.py b/product_optional_product_quantity/models/product_optional_line.py new file mode 100644 index 00000000000..120c702dbc5 --- /dev/null +++ b/product_optional_product_quantity/models/product_optional_line.py @@ -0,0 +1,62 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class ProductOptionalLine(models.Model): + _name = "product.optional.line" + _description = "Optional Product" + + product_tmpl_id = fields.Many2one( + comodel_name="product.template", + domain="[('id', '!=', optional_product_tmpl_id)]", + string="Related Product", + required=True, + ) + company_id = fields.Many2one(related="product_tmpl_id.company_id") + optional_product_tmpl_id = fields.Many2one( + comodel_name="product.template", + domain=[ + ("company_id", "in", [company_id, False]), + ("id", "!=", product_tmpl_id), + ], + string="Product", + required=True, + ) + quantity = fields.Float( + default=1.0, + ) + + @api.constrains("product_tmpl_id", "optional_product_tmpl_id") + def _check_same_product_as_related(self): + """ + Restrict setting product template this line is related to as optional. + """ + for r in self: + if ( + r.product_tmpl_id + and r.optional_product_tmpl_id + and r.product_tmpl_id == r.optional_product_tmpl_id + ): + raise models.ValidationError( + self.env._( + "You can't add product this line is related to as optional." + ) + ) + + @api.constrains("product_tmpl_id", "optional_product_tmpl_id") + def _check_unique_products_within_product(self): + """ + Make sure that all of the optional products are unique. + """ + for r in self: + if self.search_count( + [ + ("optional_product_tmpl_id", "=", r.optional_product_tmpl_id.id), + ("product_tmpl_id", "=", r.product_tmpl_id.id), + ("id", "!=", r.id), + ] + ): + raise models.ValidationError( + self.env._("You can't add two same products as optional.") + ) diff --git a/product_optional_product_quantity/models/product_template.py b/product_optional_product_quantity/models/product_template.py new file mode 100644 index 00000000000..0d1069da714 --- /dev/null +++ b/product_optional_product_quantity/models/product_template.py @@ -0,0 +1,30 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + product_optional_line_ids = fields.One2many( + string="Optional Products Line", + comodel_name="product.optional.line", + inverse_name="product_tmpl_id", + ) + optional_product_ids = fields.Many2many( + compute="_compute_optional_product_ids", + readonly=False, + store=True, + ) + + @api.depends("product_optional_line_ids") + def _compute_optional_product_ids(self): + """ + To avoid possible issues with optional products in other modules, + we need to compute them based on optional product lines, because + we hide the original field. + """ + for r in self: + r.optional_product_ids = r.product_optional_line_ids.mapped( + "optional_product_tmpl_id" + ) diff --git a/product_optional_product_quantity/models/res_config_settings.py b/product_optional_product_quantity/models/res_config_settings.py new file mode 100644 index 00000000000..cc639269078 --- /dev/null +++ b/product_optional_product_quantity/models/res_config_settings.py @@ -0,0 +1,12 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + group_product_optional_quantity = fields.Boolean( + string="Optional Products Quantity", + implied_group="product_optional_product_quantity.group_product_optional_quantity", + ) diff --git a/product_optional_product_quantity/pyproject.toml b/product_optional_product_quantity/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/product_optional_product_quantity/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_optional_product_quantity/readme/CONFIGURE.md b/product_optional_product_quantity/readme/CONFIGURE.md new file mode 100644 index 00000000000..47af794bf4b --- /dev/null +++ b/product_optional_product_quantity/readme/CONFIGURE.md @@ -0,0 +1,5 @@ +Go to Settings > Sales tab +In the "Product Catalog" section enable "Optional Products Quantity" feature + + +Open a product and go to the "Sales" tab. Add optional products with quantities in the "Optional Products" field. \ No newline at end of file diff --git a/product_optional_product_quantity/readme/CONTEXT.md b/product_optional_product_quantity/readme/CONTEXT.md new file mode 100644 index 00000000000..04c16d567d3 --- /dev/null +++ b/product_optional_product_quantity/readme/CONTEXT.md @@ -0,0 +1,4 @@ +Odoo has an option to define optional products for products. However sometimes optional product may have different quantity in relation to the main one. +For example you have a "Tea party set" product which consists of 4 tea cups. Your customers can also buy same cups separately. +In this case "Tea cup" will be an optional product for "Tee party set" with quantity multiplier 4. +So when you add  "Tear party set" with quantity=2 to quotation "Tea cup" with quantity=8 will be added in the "Optional products" tab.  \ No newline at end of file diff --git a/product_optional_product_quantity/readme/CONTRIBUTORS.md b/product_optional_product_quantity/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..2f6060845e2 --- /dev/null +++ b/product_optional_product_quantity/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/product_optional_product_quantity/readme/DESCRIPTION.md b/product_optional_product_quantity/readme/DESCRIPTION.md new file mode 100644 index 00000000000..7052250c14c --- /dev/null +++ b/product_optional_product_quantity/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module implements core functionality for the optional product quantity multipliers. You can depend on this module to implement further user features. \ No newline at end of file diff --git a/product_optional_product_quantity/readme/USAGE.md b/product_optional_product_quantity/readme/USAGE.md new file mode 100644 index 00000000000..fcb0ab4d59a --- /dev/null +++ b/product_optional_product_quantity/readme/USAGE.md @@ -0,0 +1 @@ +Usage flow is implemented in modules depending on this one. \ No newline at end of file diff --git a/product_optional_product_quantity/security/ir.model.access.csv b/product_optional_product_quantity/security/ir.model.access.csv new file mode 100644 index 00000000000..aecd7220f9c --- /dev/null +++ b/product_optional_product_quantity/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_product_optional_line_user,product_optional_line_user,model_product_optional_line,base.group_user,1,0,0,0 +access_product_optional_line_salesman,product_optional_line_salesman,model_product_optional_line,sales_team.group_sale_salesman,1,1,1,1 diff --git a/product_optional_product_quantity/security/res_groups.xml b/product_optional_product_quantity/security/res_groups.xml new file mode 100644 index 00000000000..858ead1e8b3 --- /dev/null +++ b/product_optional_product_quantity/security/res_groups.xml @@ -0,0 +1,7 @@ + + + + Use Optional Products Quantity + + + diff --git a/product_optional_product_quantity/static/description/icon.png b/product_optional_product_quantity/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_optional_product_quantity/static/description/icon.png differ diff --git a/product_optional_product_quantity/static/description/index.html b/product_optional_product_quantity/static/description/index.html new file mode 100644 index 00000000000..65c919c1474 --- /dev/null +++ b/product_optional_product_quantity/static/description/index.html @@ -0,0 +1,453 @@ + + + + + +Product Optional Product Quantity + + + +
+

Product Optional Product Quantity

+ + +

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

+

This module implements core functionality for the optional product +quantity multipliers. You can depend on this module to implement further +user features.

+

Table of contents

+ +
+

Use Cases / Context

+

Odoo has an option to define optional products for products. However +sometimes optional product may have different quantity in relation to +the main one. For example you have a “Tea party set” product which +consists of 4 tea cups. Your customers can also buy same cups +separately. In this case “Tea cup” will be an optional product for “Tee +party set” with quantity multiplier 4. So when you add  “Tear party set” +with quantity=2 to quotation “Tea cup” with quantity=8 will be added in +the “Optional products” tab.

+
+
+

Configuration

+

Go to Settings > Sales tab In the “Product Catalog” section enable +“Optional Products Quantity” feature

+

Open a product and go to the “Sales” tab. Add optional products with +quantities in the “Optional Products” field.

+
+
+

Usage

+

Usage flow is implemented in modules depending on this one.

+
+
+

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

+
    +
  • Cetmix
  • +
+
+
+

Contributors

+ +
+
+

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.

+

This module is part of the OCA/product-attribute project on GitHub.

+

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

+
+
+
+ + diff --git a/product_optional_product_quantity/tests/__init__.py b/product_optional_product_quantity/tests/__init__.py new file mode 100644 index 00000000000..bac69801585 --- /dev/null +++ b/product_optional_product_quantity/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_optional_product_quantity diff --git a/product_optional_product_quantity/tests/test_optional_product_quantity.py b/product_optional_product_quantity/tests/test_optional_product_quantity.py new file mode 100644 index 00000000000..5fa1e154749 --- /dev/null +++ b/product_optional_product_quantity/tests/test_optional_product_quantity.py @@ -0,0 +1,92 @@ +# Copyright 2024 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import exceptions +from odoo.tests.common import tagged + +from odoo.addons.base.tests.common import BaseCommon + + +@tagged("post_install", "-at_install") +class TestOptionalProductQuantity(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_template_1 = cls.env["product.template"].create( + { + "name": "Product 1", + "type": "consu", + "categ_id": cls.env.ref("product.product_category_all").id, + } + ) + cls.product_template_2 = cls.env["product.template"].create( + { + "name": "Product 2", + "type": "consu", + "categ_id": cls.env.ref("product.product_category_all").id, + } + ) + cls.product_template_3 = cls.env["product.template"].create( + { + "name": "Product 3", + "type": "consu", + "categ_id": cls.env.ref("product.product_category_all").id, + } + ) + + def test_product_optional_line_constrains(self): + # Try to set parent product as an optional + with self.assertRaises(exceptions.ValidationError): + self.env["product.optional.line"].create( + { + "product_tmpl_id": self.product_template_1.id, + "optional_product_tmpl_id": self.product_template_1.id, + } + ) + + # Try to set two same products as optional + with self.assertRaises(exceptions.ValidationError): + self.env["product.optional.line"].create( + [ + { + "product_tmpl_id": self.product_template_1.id, + "optional_product_tmpl_id": self.product_template_2.id, + }, + { + "product_tmpl_id": self.product_template_1.id, + "optional_product_tmpl_id": self.product_template_2.id, + }, + ] + ) + + def test_optional_product_ids_computation(self): + # Create first optional product for Product 1 + self.env["product.optional.line"].create( + { + "product_tmpl_id": self.product_template_1.id, + "optional_product_tmpl_id": self.product_template_2.id, + } + ) + # optional_product_ids of Product 1 should contain 1 + # record with name 'Product 2' + self.assertTrue( + len(self.product_template_1.optional_product_ids) == 1 + and self.product_template_1.optional_product_ids[0].name == "Product 2", + msg="optional_product_ids of product.template " + "has been computed incorrectly", + ) + # Create second optional product for Product 1 + self.env["product.optional.line"].create( + { + "product_tmpl_id": self.product_template_1.id, + "optional_product_tmpl_id": self.product_template_3.id, + } + ) + # optional_product_ids of Product 1 should contain 2 records + # with names 'Product 2' and 'Product 3' + self.assertTrue( + len(self.product_template_1.optional_product_ids) == 2 + and self.product_template_1.optional_product_ids[0].name == "Product 2" + and self.product_template_1.optional_product_ids[1].name == "Product 3", + msg="optional_product_ids of product.template has " + "been computed incorrectly", + ) diff --git a/product_optional_product_quantity/views/product_template_views.xml b/product_optional_product_quantity/views/product_template_views.xml new file mode 100644 index 00000000000..cf8f2766546 --- /dev/null +++ b/product_optional_product_quantity/views/product_template_views.xml @@ -0,0 +1,26 @@ + + + + product.template.view.form.inherit.optional.qty + product.template + + + + 1 + + + + + + + + + + + + + + diff --git a/product_optional_product_quantity/views/res_config_settings_views.xml b/product_optional_product_quantity/views/res_config_settings_views.xml new file mode 100644 index 00000000000..5a42e2543bd --- /dev/null +++ b/product_optional_product_quantity/views/res_config_settings_views.xml @@ -0,0 +1,18 @@ + + + + res.config.settings.view.form.inherit.optional.qty + res.config.settings + + + + + + + + + +