diff --git a/product_code_mandatory/README.rst b/product_code_mandatory/README.rst new file mode 100644 index 000000000000..5349fc1e3a43 --- /dev/null +++ b/product_code_mandatory/README.rst @@ -0,0 +1,90 @@ +====================== +Product Code Mandatory +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/15.0/product_code_mandatory + :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-15-0/product-attribute-15-0-product_code_mandatory + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/135/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module sets the field internal reference (default_code) of the product +as required. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Unable to save a product with an empty or blank internal reference. +* When creating more than one product variant from the template, a variant will be created + with a default value for default_code field. +* A pre_init_hook process is initiated when there exist records without an internal reference(default_code). + A default value is generated to populate empty field as a temporary value. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/135/12.0 + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Open Source Integrators + +Contributors +~~~~~~~~~~~~ + +* Antonio Yamuta +* Sudhir Arya +* Watthanun Khorchai +* Nedas Žilinskas + +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_code_mandatory/__init__.py b/product_code_mandatory/__init__.py new file mode 100644 index 000000000000..511066707ab8 --- /dev/null +++ b/product_code_mandatory/__init__.py @@ -0,0 +1,27 @@ +from . import models + +from odoo import api, SUPERUSER_ID + + +def pre_init_product_code(cr): + env = api.Environment(cr, SUPERUSER_ID, {}) + + cr.execute( + """ + SELECT product_tmpl_id from product_product + WHERE default_code is NULL + OR LENGTH(default_code) = 0 + GROUP BY product_tmpl_id + HAVING COUNT(product_tmpl_id) = 1""" + ) + product_template_ids = [x[0] for x in cr.fetchall()] + cr.execute( + """UPDATE product_product + SET default_code = 'DEFAULT' || nextval('ir_default_id_seq') + WHERE default_code is NULL + OR LENGTH(default_code) = 0""" + ) + + env["product.template"].browse(product_template_ids)._compute_default_code() + + return True diff --git a/product_code_mandatory/__manifest__.py b/product_code_mandatory/__manifest__.py new file mode 100644 index 000000000000..7404927194da --- /dev/null +++ b/product_code_mandatory/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Product Code Mandatory", + "summary": "Set Product Internal Reference as a required field", + "version": "16.0.1.0.1", + "license": "AGPL-3", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "category": "Product", + "website": "https://github.com/OCA/product-attribute", + "depends": ["product"], + "data": ["data/product_code_seq.xml", "views/product_view.xml"], + "pre_init_hook": "pre_init_product_code", + "installable": True, +} diff --git a/product_code_mandatory/data/product_code_seq.xml b/product_code_mandatory/data/product_code_seq.xml new file mode 100644 index 000000000000..b388e14c2405 --- /dev/null +++ b/product_code_mandatory/data/product_code_seq.xml @@ -0,0 +1,10 @@ + + + + Product Default Code Mandatory + product.default.code + DEFAULT- + 4 + + + diff --git a/product_code_mandatory/i18n/ca.po b/product_code_mandatory/i18n/ca.po new file mode 100644 index 000000000000..1419f045da61 --- /dev/null +++ b/product_code_mandatory/i18n/ca.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_code_mandatory +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-04-22 10:05+0000\n" +"Last-Translator: pablontura \n" +"Language-Team: none\n" +"Language: ca\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.3.2\n" + +#. module: product_code_mandatory +#: model:ir.model.fields,field_description:product_code_mandatory.field_product_product__default_code +msgid "Internal Reference" +msgstr "Referència interna" + +#. module: product_code_mandatory +#: model:ir.model,name:product_code_mandatory.model_product_product +msgid "Product" +msgstr "Producte" + +#. module: product_code_mandatory +#: model:ir.model.fields,help:product_code_mandatory.field_product_product__default_code +msgid "" +"Set to '/' and save if you want a new internal reference to be proposed." +msgstr "" diff --git a/product_code_mandatory/i18n/fr.po b/product_code_mandatory/i18n/fr.po new file mode 100644 index 000000000000..c8c9fe611a70 --- /dev/null +++ b/product_code_mandatory/i18n/fr.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_code_mandatory +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-04-10 11:46+0000\n" +"Last-Translator: Yves Le Doeuff \n" +"Language-Team: none\n" +"Language: fr\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.3.2\n" + +#. module: product_code_mandatory +#: model:ir.model.fields,field_description:product_code_mandatory.field_product_product__default_code +msgid "Internal Reference" +msgstr "Référence interne" + +#. module: product_code_mandatory +#: model:ir.model,name:product_code_mandatory.model_product_product +msgid "Product" +msgstr "Article" + +#. module: product_code_mandatory +#: model:ir.model.fields,help:product_code_mandatory.field_product_product__default_code +msgid "" +"Set to '/' and save if you want a new internal reference to be proposed." +msgstr "" +"Mettez '/' et sauvegardez si vous voulez qu'une nouvelle référence vous soit " +"proposée." + +#~ msgid "Display Name" +#~ msgstr "Nom affiché" + +#~ msgid "Last Modified on" +#~ msgstr "Dernière modification" diff --git a/product_code_mandatory/i18n/fr_FR.po b/product_code_mandatory/i18n/fr_FR.po new file mode 100644 index 000000000000..af934ded7879 --- /dev/null +++ b/product_code_mandatory/i18n/fr_FR.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_code_mandatory +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-04-10 15:46+0000\n" +"Last-Translator: Yves Le Doeuff \n" +"Language-Team: none\n" +"Language: fr_FR\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.3.2\n" + +#. module: product_code_mandatory +#: model:ir.model.fields,field_description:product_code_mandatory.field_product_product__default_code +msgid "Internal Reference" +msgstr "Référence interne" + +#. module: product_code_mandatory +#: model:ir.model,name:product_code_mandatory.model_product_product +msgid "Product" +msgstr "Article" + +#. module: product_code_mandatory +#: model:ir.model.fields,help:product_code_mandatory.field_product_product__default_code +msgid "" +"Set to '/' and save if you want a new internal reference to be proposed." +msgstr "" +"Mettez '/' et sauvegardez si vous voulez qu'une nouvelle référence vous soit " +"proposée." + +#~ msgid "Display Name" +#~ msgstr "Nom affiché" + +#~ msgid "Last Modified on" +#~ msgstr "Dernière modification" diff --git a/product_code_mandatory/i18n/product_code_mandatory.pot b/product_code_mandatory/i18n/product_code_mandatory.pot new file mode 100644 index 000000000000..784b6ca0b6b5 --- /dev/null +++ b/product_code_mandatory/i18n/product_code_mandatory.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_code_mandatory +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_code_mandatory +#: model:ir.model.fields,field_description:product_code_mandatory.field_product_product__default_code +msgid "Internal Reference" +msgstr "" + +#. module: product_code_mandatory +#: model:ir.model,name:product_code_mandatory.model_product_product +msgid "Product" +msgstr "" + +#. module: product_code_mandatory +#: model:ir.model.fields,help:product_code_mandatory.field_product_product__default_code +msgid "" +"Set to '/' and save if you want a new internal reference to be proposed." +msgstr "" diff --git a/product_code_mandatory/i18n/pt.po b/product_code_mandatory/i18n/pt.po new file mode 100644 index 000000000000..e90e12a1fc59 --- /dev/null +++ b/product_code_mandatory/i18n/pt.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_code_mandatory +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-03-23 14:13+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\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 3.10\n" + +#. module: product_code_mandatory +#: model:ir.model.fields,field_description:product_code_mandatory.field_product_product__default_code +msgid "Internal Reference" +msgstr "Referência Interna" + +#. module: product_code_mandatory +#: model:ir.model,name:product_code_mandatory.model_product_product +msgid "Product" +msgstr "Produto" + +#. module: product_code_mandatory +#: model:ir.model.fields,help:product_code_mandatory.field_product_product__default_code +msgid "" +"Set to '/' and save if you want a new internal reference to be proposed." +msgstr "" +"Defina como '/' e guarde caso pretenda que uma nova referência interna seja " +"proposta." diff --git a/product_code_mandatory/models/__init__.py b/product_code_mandatory/models/__init__.py new file mode 100644 index 000000000000..9649db77a159 --- /dev/null +++ b/product_code_mandatory/models/__init__.py @@ -0,0 +1 @@ +from . import product diff --git a/product_code_mandatory/models/product.py b/product_code_mandatory/models/product.py new file mode 100644 index 000000000000..33e5f57039a4 --- /dev/null +++ b/product_code_mandatory/models/product.py @@ -0,0 +1,15 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators License AGPL-3.0 +# or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def _get_default_code(self): + return self.env["ir.sequence"].next_by_code("product.default.code") + + default_code = fields.Char( + "Internal Reference", index=True, default=_get_default_code + ) diff --git a/product_code_mandatory/readme/CONTRIBUTORS.rst b/product_code_mandatory/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..21c5ea622675 --- /dev/null +++ b/product_code_mandatory/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Antonio Yamuta +* Sudhir Arya +* Watthanun Khorchai +* Nedas Žilinskas diff --git a/product_code_mandatory/readme/DESCRIPTION.rst b/product_code_mandatory/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..2c5007126431 --- /dev/null +++ b/product_code_mandatory/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module sets the field internal reference (default_code) of the product +as required. diff --git a/product_code_mandatory/readme/USAGE.rst b/product_code_mandatory/readme/USAGE.rst new file mode 100644 index 000000000000..e9a7b9fc7f74 --- /dev/null +++ b/product_code_mandatory/readme/USAGE.rst @@ -0,0 +1,9 @@ +* Unable to save a product with an empty or blank internal reference. +* When creating more than one product variant from the template, a variant will be created + with a default value for default_code field. +* A pre_init_hook process is initiated when there exist records without an internal reference(default_code). + A default value is generated to populate empty field as a temporary value. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/135/12.0 diff --git a/product_code_mandatory/static/description/icon.png b/product_code_mandatory/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/product_code_mandatory/static/description/icon.png differ diff --git a/product_code_mandatory/static/description/index.html b/product_code_mandatory/static/description/index.html new file mode 100644 index 000000000000..c3cafc938dcc --- /dev/null +++ b/product_code_mandatory/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +Product Code Mandatory + + + +
+

Product Code Mandatory

+ + +

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

+

This module sets the field internal reference (default_code) of the product +as required.

+

Table of contents

+ +
+

Usage

+
    +
  • Unable to save a product with an empty or blank internal reference.
  • +
  • When creating more than one product variant from the template, a variant will be created +with a default value for default_code field.
  • +
  • A pre_init_hook process is initiated when there exist records without an internal reference(default_code). +A default value is generated to populate empty field as a temporary value.
  • +
+Try me on Runbot +
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Open Source Integrators
  • +
+
+
+

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_code_mandatory/tests/__init__.py b/product_code_mandatory/tests/__init__.py new file mode 100644 index 000000000000..fd357bf28010 --- /dev/null +++ b/product_code_mandatory/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_code diff --git a/product_code_mandatory/tests/test_product_code.py b/product_code_mandatory/tests/test_product_code.py new file mode 100644 index 000000000000..6db56fce44c6 --- /dev/null +++ b/product_code_mandatory/tests/test_product_code.py @@ -0,0 +1,14 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestProductCode(TransactionCase): + def setUp(self): + super(TestProductCode, self).setUp() + self.product_model = self.env["product.product"] + self.product = self.product_model.create({"name": "Test Product Code"}) + + def test_product_code(self): + """Check Product Code""" + self.assertTrue(self.product.default_code, "Product code is not set.") diff --git a/product_code_mandatory/views/product_view.xml b/product_code_mandatory/views/product_view.xml new file mode 100644 index 000000000000..648dd282b20e --- /dev/null +++ b/product_code_mandatory/views/product_view.xml @@ -0,0 +1,26 @@ + + + + product.template.only.form.code.mandatory.view + product.template + + + + {'invisible': [('product_variant_count', '>', 1)], + 'required': [('product_variant_count', '=', 1)]} + + + + + product.normal.form.code.mandatory.view + product.product + + + + True + + + + diff --git a/setup/product_code_mandatory/odoo/addons/product_code_mandatory b/setup/product_code_mandatory/odoo/addons/product_code_mandatory new file mode 120000 index 000000000000..4e71d6fc7f94 --- /dev/null +++ b/setup/product_code_mandatory/odoo/addons/product_code_mandatory @@ -0,0 +1 @@ +../../../../product_code_mandatory \ No newline at end of file diff --git a/setup/product_code_mandatory/setup.py b/setup/product_code_mandatory/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/product_code_mandatory/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)