diff --git a/product_state_active/README.rst b/product_state_active/README.rst new file mode 100644 index 00000000000..c3ab47ab8eb --- /dev/null +++ b/product_state_active/README.rst @@ -0,0 +1,104 @@ +==================== +Product State Active +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:93236a770b1c42f7156e43f306916838d019137641c4bb28ea211784cb373e77 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_state_active + :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_state_active + :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 allows to set options on product states that will trigger +the activation or deactivation (Archive) of the products. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to *Sales > Configuration > Products > Product States*. +2. Check the box 'Activate Product' or 'Deactivate Product' + +To deactivate the product: + +1. Go to the product itself and edit. +2. Click on the state you have configured to deactivate it + +To deactivate the product: + +1. Go to the product itself and edit. +2. Click on the state you have configured to activate it + +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Denis Roussel +- `Komit `__: + + - Cai Hoang Huynh + +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-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px + :target: https://github.com/rousseldenis + :alt: rousseldenis + +Current `maintainer `__: + +|maintainer-rousseldenis| + +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_state_active/__init__.py b/product_state_active/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_state_active/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_state_active/__manifest__.py b/product_state_active/__manifest__.py new file mode 100644 index 00000000000..49e78649fc5 --- /dev/null +++ b/product_state_active/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Product State Active", + "summary": """ + Allows to define option on product state to activate or inactivate product""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["rousseldenis"], + "website": "https://github.com/OCA/product-attribute", + "depends": [ + "product_state", + ], + "data": [ + "views/product_state.xml", + ], +} diff --git a/product_state_active/i18n/es.po b/product_state_active/i18n/es.po new file mode 100644 index 00000000000..e4d8f4f260b --- /dev/null +++ b/product_state_active/i18n/es.po @@ -0,0 +1,78 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_state_active +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-13 23:56+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_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__activate_product +msgid "Activate Product" +msgstr "Activar Producto" + +#. module: product_state_active +#: model:ir.model.fields,help:product_state_active.field_product_state__deactivate_product +msgid "Check this if you want to archive product when reaching this state." +msgstr "" +"Marque esta opción si desea archivar el producto cuando alcance este estado." + +#. module: product_state_active +#: model:ir.model.fields,help:product_state_active.field_product_state__activate_product +msgid "Check this if you want to un-archive product when reaching this state." +msgstr "" +"Marque esta opción si desea desarchivar el producto cuando alcance este " +"estado." + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__deactivate_product +msgid "Deactivate Product" +msgstr "Desactivar Producto" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__display_name +#: model:ir.model.fields,field_description:product_state_active.field_product_template__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__id +#: model:ir.model.fields,field_description:product_state_active.field_product_template__id +msgid "ID" +msgstr "ID" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state____last_update +#: model:ir.model.fields,field_description:product_state_active.field_product_template____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: product_state_active +#: model:ir.model,name:product_state_active.model_product_state +msgid "Product State" +msgstr "Estado del Producto" + +#. module: product_state_active +#: model:ir.model,name:product_state_active.model_product_template +msgid "Product Template" +msgstr "Plantilla del Producto" + +#. module: product_state_active +#: code:addons/product_state_active/models/product_state.py:0 +#, python-format +msgid "" +"You cannot have both 'Deactivate Product' and 'Activate Product' options at " +"the same time!" +msgstr "" +"¡No puede tener las opciones \"Desactivar producto\" y \"Activar producto\" " +"al mismo tiempo!" diff --git a/product_state_active/i18n/it.po b/product_state_active/i18n/it.po new file mode 100644 index 00000000000..3e0dc26d1c6 --- /dev/null +++ b/product_state_active/i18n/it.po @@ -0,0 +1,79 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_state_active +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-03 09:38+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 4.17\n" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__activate_product +msgid "Activate Product" +msgstr "Prdotto attivato" + +#. module: product_state_active +#: model:ir.model.fields,help:product_state_active.field_product_state__deactivate_product +msgid "Check this if you want to archive product when reaching this state." +msgstr "" +"Selezonare se si vuole che il prodotto venga archiviato quando raggiunge " +"questo stato." + +#. module: product_state_active +#: model:ir.model.fields,help:product_state_active.field_product_state__activate_product +msgid "Check this if you want to un-archive product when reaching this state." +msgstr "" +"Selezonare se si vuole che il prodotto venga riattivato quando raggiunge " +"questo stato." + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__deactivate_product +msgid "Deactivate Product" +msgstr "Prodotto sospeso" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__display_name +#: model:ir.model.fields,field_description:product_state_active.field_product_template__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__id +#: model:ir.model.fields,field_description:product_state_active.field_product_template__id +msgid "ID" +msgstr "ID" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state____last_update +#: model:ir.model.fields,field_description:product_state_active.field_product_template____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: product_state_active +#: model:ir.model,name:product_state_active.model_product_state +msgid "Product State" +msgstr "Stato prodotto" + +#. module: product_state_active +#: model:ir.model,name:product_state_active.model_product_template +msgid "Product Template" +msgstr "Modello prodotto" + +#. module: product_state_active +#: code:addons/product_state_active/models/product_state.py:0 +#, python-format +msgid "" +"You cannot have both 'Deactivate Product' and 'Activate Product' options at " +"the same time!" +msgstr "" +"Non si possono avere le opzioni 'Podotto sospeso' e 'Prodotto attivato' " +"nello stesso momento!" diff --git a/product_state_active/i18n/product_state_active.pot b/product_state_active/i18n/product_state_active.pot new file mode 100644 index 00000000000..a22d4309c52 --- /dev/null +++ b/product_state_active/i18n/product_state_active.pot @@ -0,0 +1,70 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_state_active +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__activate_product +msgid "Activate Product" +msgstr "" + +#. module: product_state_active +#: model:ir.model.fields,help:product_state_active.field_product_state__deactivate_product +msgid "Check this if you want to archive product when reaching this state." +msgstr "" + +#. module: product_state_active +#: model:ir.model.fields,help:product_state_active.field_product_state__activate_product +msgid "Check this if you want to un-archive product when reaching this state." +msgstr "" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__deactivate_product +msgid "Deactivate Product" +msgstr "" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__display_name +#: model:ir.model.fields,field_description:product_state_active.field_product_template__display_name +msgid "Display Name" +msgstr "" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state__id +#: model:ir.model.fields,field_description:product_state_active.field_product_template__id +msgid "ID" +msgstr "" + +#. module: product_state_active +#: model:ir.model.fields,field_description:product_state_active.field_product_state____last_update +#: model:ir.model.fields,field_description:product_state_active.field_product_template____last_update +msgid "Last Modified on" +msgstr "" + +#. module: product_state_active +#: model:ir.model,name:product_state_active.model_product_state +msgid "Product State" +msgstr "" + +#. module: product_state_active +#: model:ir.model,name:product_state_active.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_state_active +#: code:addons/product_state_active/models/product_state.py:0 +#, python-format +msgid "" +"You cannot have both 'Deactivate Product' and 'Activate Product' options at " +"the same time!" +msgstr "" diff --git a/product_state_active/models/__init__.py b/product_state_active/models/__init__.py new file mode 100644 index 00000000000..3e93acc6814 --- /dev/null +++ b/product_state_active/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_state +from . import product_template diff --git a/product_state_active/models/product_state.py b/product_state_active/models/product_state.py new file mode 100644 index 00000000000..feef9e77cd5 --- /dev/null +++ b/product_state_active/models/product_state.py @@ -0,0 +1,26 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ProductState(models.Model): + _inherit = "product.state" + + deactivate_product = fields.Boolean( + help="Check this if you want to archive product when reaching this state." + ) + activate_product = fields.Boolean( + help="Check this if you want to un-archive product when reaching this state." + ) + + @api.constrains("deactivate_product", "activate_product") + def _check_product_inactive_active(self): + if any(state.deactivate_product and state.activate_product for state in self): + raise ValidationError( + _( + "You cannot have both 'Deactivate Product' and " + "'Activate Product' options at the same time!" + ) + ) diff --git a/product_state_active/models/product_template.py b/product_state_active/models/product_template.py new file mode 100644 index 00000000000..4f20e5cd190 --- /dev/null +++ b/product_state_active/models/product_template.py @@ -0,0 +1,15 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def _inverse_product_state_id(self): + for product in self: + if product.active and product.product_state_id.deactivate_product: + product.active = False + if not product.active and product.product_state_id.activate_product: + product.active = True diff --git a/product_state_active/pyproject.toml b/product_state_active/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/product_state_active/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_state_active/readme/CONTRIBUTORS.md b/product_state_active/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..037ef79a8a8 --- /dev/null +++ b/product_state_active/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Denis Roussel \ +- [Komit](https://komit-consulting.com): + - Cai Hoang Huynh \ No newline at end of file diff --git a/product_state_active/readme/DESCRIPTION.md b/product_state_active/readme/DESCRIPTION.md new file mode 100644 index 00000000000..cc3d535013b --- /dev/null +++ b/product_state_active/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows to set options on product states that will trigger +the activation or deactivation (Archive) of the products. diff --git a/product_state_active/readme/USAGE.md b/product_state_active/readme/USAGE.md new file mode 100644 index 00000000000..eecb8412b26 --- /dev/null +++ b/product_state_active/readme/USAGE.md @@ -0,0 +1,12 @@ +1. Go to *Sales \> Configuration \> Products \> Product States*. +2. Check the box 'Activate Product' or 'Deactivate Product' + +To deactivate the product: + +1. Go to the product itself and edit. +2. Click on the state you have configured to deactivate it + +To deactivate the product: + +1. Go to the product itself and edit. +2. Click on the state you have configured to activate it diff --git a/product_state_active/static/description/icon.png b/product_state_active/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_state_active/static/description/icon.png differ diff --git a/product_state_active/static/description/index.html b/product_state_active/static/description/index.html new file mode 100644 index 00000000000..34743d26833 --- /dev/null +++ b/product_state_active/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Product State Active + + + +
+

Product State Active

+ + +

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

+

This module allows to set options on product states that will trigger +the activation or deactivation (Archive) of the products.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Sales > Configuration > Products > Product States.
  2. +
  3. Check the box ‘Activate Product’ or ‘Deactivate Product’
  4. +
+

To deactivate the product:

+
    +
  1. Go to the product itself and edit.
  2. +
  3. Click on the state you have configured to deactivate it
  4. +
+

To deactivate the product:

+
    +
  1. Go to the product itself and edit.
  2. +
  3. Click on the state you have configured to activate it
  4. +
+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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.

+

Current maintainer:

+

rousseldenis

+

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_state_active/tests/__init__.py b/product_state_active/tests/__init__.py new file mode 100644 index 00000000000..a3fc638dbc5 --- /dev/null +++ b/product_state_active/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_state diff --git a/product_state_active/tests/test_product_state.py b/product_state_active/tests/test_product_state.py new file mode 100644 index 00000000000..dcb6e15c915 --- /dev/null +++ b/product_state_active/tests/test_product_state.py @@ -0,0 +1,53 @@ +# Copyright 2021 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.exceptions import ValidationError +from odoo.tests import TransactionCase + + +class TestProductStateActive(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.state_draft = cls.env.ref("product_state.product_state_draft") + cls.state_sellable = cls.env.ref("product_state.product_state_sellable") + cls.product_1 = cls.env.ref("product.product_product_4_product_template") + + def test_constraint(self): + """ + Try to set both options True + """ + with self.assertRaises(ValidationError): + self.state_draft.write( + { + "activate_product": True, + "deactivate_product": True, + } + ) + + def test_deactivate_from_state_id(self): + """ + Change the state that deactivate a product + Check if deactivated + Change the state that activate a product + Check if activated + """ + self.state_draft.deactivate_product = True + self.state_sellable.activate_product = True + self.product_1.product_state_id = self.state_draft + self.assertFalse(self.product_1.active) + self.product_1.product_state_id = self.state_sellable + self.assertTrue(self.product_1.active) + + def test_deactivate_from_state(self): + """ + Change the state that deactivate a product + Check if deactivated + Change the state that activate a product + Check if activated + """ + self.state_draft.deactivate_product = True + self.state_sellable.activate_product = True + self.product_1.state = self.state_draft.code + self.assertFalse(self.product_1.active) + self.product_1.state = self.state_sellable.code + self.assertTrue(self.product_1.active) diff --git a/product_state_active/views/product_state.xml b/product_state_active/views/product_state.xml new file mode 100644 index 00000000000..2302d7e5733 --- /dev/null +++ b/product_state_active/views/product_state.xml @@ -0,0 +1,16 @@ + + + + + product.state.form (in product_state_active) + product.state + + + + + + + + +