Skip to content

Commit 23b9b06

Browse files
committed
Merge PR #388 into 18.0
Signed-off-by pedrobaeza
2 parents 9f27b23 + 02830e1 commit 23b9b06

18 files changed

Lines changed: 737 additions & 0 deletions

product_variant_name/README.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
====================
2+
Product Variant Name
3+
====================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:01807873c437c2b9ccb9455f775c849a9bd28768663da312b0acc32af69a5f2f
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github
20+
:target: https://github.com/OCA/product-variant/tree/18.0/product_variant_name
21+
:alt: OCA/product-variant
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/product-variant-18-0/product-variant-18-0-product_variant_name
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-variant&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows having different product variant names than the name
32+
of their template.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Bug Tracker
40+
===========
41+
42+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-variant/issues>`_.
43+
In case of trouble, please check there if your issue has already been reported.
44+
If you spotted it first, help us to smash it by providing a detailed and welcomed
45+
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_name%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
46+
47+
Do not contact contributors directly about support or help with technical issues.
48+
49+
Credits
50+
=======
51+
52+
Authors
53+
-------
54+
55+
* ForgeFlow
56+
57+
Contributors
58+
------------
59+
60+
- Jordi Masvidal <jordi.masvidal@forgeflow.com>
61+
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__
62+
63+
- Bhavesh Heliconia
64+
65+
Maintainers
66+
-----------
67+
68+
This module is maintained by the OCA.
69+
70+
.. image:: https://odoo-community.org/logo.png
71+
:alt: Odoo Community Association
72+
:target: https://odoo-community.org
73+
74+
OCA, or the Odoo Community Association, is a nonprofit organization whose
75+
mission is to support the collaborative development of Odoo features and
76+
promote its widespread use.
77+
78+
This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/18.0/product_variant_name>`_ project on GitHub.
79+
80+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

product_variant_name/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2023 ForgeFlow, S.L.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from . import models
5+
from .init_hook import pre_init_hook
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2023 ForgeFlow, S.L.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "Product Variant Name",
6+
"version": "18.0.1.0.0",
7+
"category": "Product",
8+
"author": "ForgeFlow, Odoo Community Association (OCA)",
9+
"website": "https://github.com/OCA/product-variant",
10+
"license": "AGPL-3",
11+
"depends": [
12+
"product",
13+
],
14+
"data": ["views/product_view.xml"],
15+
"installable": True,
16+
"pre_init_hook": "pre_init_hook",
17+
}

product_variant_name/i18n/es.po

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * product_variant_name
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2024-02-14 19:35+0000\n"
10+
"Last-Translator: Ivorra78 <informatica@totmaterial.es>\n"
11+
"Language-Team: none\n"
12+
"Language: es\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 4.17\n"
18+
19+
#. module: product_variant_name
20+
#: model:ir.model.fields,field_description:product_variant_name.field_product_product__name
21+
msgid "Name"
22+
msgstr "Nombre"
23+
24+
#. module: product_variant_name
25+
#: model:ir.model,name:product_variant_name.model_product_template
26+
msgid "Product"
27+
msgstr "Producto"
28+
29+
#. module: product_variant_name
30+
#: model:ir.model,name:product_variant_name.model_product_product
31+
msgid "Product Variant"
32+
msgstr "Variante del Producto"

product_variant_name/i18n/it.po

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * product_variant_name
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2023-11-10 11:39+0000\n"
10+
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
11+
"Language-Team: none\n"
12+
"Language: it\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 4.17\n"
18+
19+
#. module: product_variant_name
20+
#: model:ir.model.fields,field_description:product_variant_name.field_product_product__name
21+
msgid "Name"
22+
msgstr "Nome"
23+
24+
#. module: product_variant_name
25+
#: model:ir.model,name:product_variant_name.model_product_template
26+
msgid "Product"
27+
msgstr "Prodotto"
28+
29+
#. module: product_variant_name
30+
#: model:ir.model,name:product_variant_name.model_product_product
31+
msgid "Product Variant"
32+
msgstr "Variante prodotto"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * product_variant_name
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: product_variant_name
17+
#: model:ir.model.fields,field_description:product_variant_name.field_product_product__name
18+
msgid "Name"
19+
msgstr ""
20+
21+
#. module: product_variant_name
22+
#: model:ir.model,name:product_variant_name.model_product_template
23+
msgid "Product"
24+
msgstr ""
25+
26+
#. module: product_variant_name
27+
#: model:ir.model,name:product_variant_name.model_product_product
28+
msgid "Product Variant"
29+
msgstr ""

product_variant_name/init_hook.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2023 ForgeFlow, S.L.
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
import logging
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
def pre_init_hook(env):
10+
"""Create and populate product variant name column BEFORE Odoo adds constraints"""
11+
logger.info("Pre-init: Creating name column on product_product")
12+
env.cr.execute(
13+
"""
14+
SELECT column_name
15+
FROM information_schema.columns
16+
WHERE table_name='product_product' AND column_name='name';
17+
"""
18+
)
19+
20+
if not env.cr.fetchone():
21+
env.cr.execute(
22+
"""
23+
ALTER TABLE product_product
24+
ADD COLUMN name JSONB;
25+
"""
26+
)
27+
28+
logger.info("Pre-init: Populating product variant names from templates")
29+
env.cr.execute(
30+
"""
31+
UPDATE product_product pp
32+
SET name = pt.name
33+
FROM product_template pt
34+
WHERE pp.product_tmpl_id = pt.id;
35+
"""
36+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2023 ForgeFlow, S.L.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from . import product_product
5+
from . import product_template
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2023 ForgeFlow, S.L.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
5+
from odoo import fields, models
6+
7+
8+
class ProductProduct(models.Model):
9+
_inherit = "product.product"
10+
11+
name = fields.Char(index="trigram", required=True, translate=True)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2023 ForgeFlow, S.L.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
5+
from odoo import models
6+
7+
8+
class ProductTemplate(models.Model):
9+
_inherit = "product.template"
10+
11+
def _prepare_variant_values(self, combination):
12+
variant_dict = super()._prepare_variant_values(combination)
13+
variant_dict["name"] = self.name
14+
return variant_dict

0 commit comments

Comments
 (0)