Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions product_alias/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
=============
Product Alias
=============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:71afc9274b4773d337e892f32dad5f96bbb83699ac312296e1569cc8fb674d67
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fe--commerce-lightgray.png?logo=github
:target: https://github.com/OCA/e-commerce/tree/18.0/product_alias
:alt: OCA/e-commerce
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/e-commerce-18-0/e-commerce-18-0-product_alias
: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/e-commerce&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to add aliases from the product template for each
selected variants (or attribute values combination).

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/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/e-commerce/issues/new?body=module:%20product_alias%0Aversion:%2018.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
-------

* Akretion

Contributors
------------

- Kévin Roche <kevin.roche@akretion.com>

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-Kev-Roche| image:: https://github.com/Kev-Roche.png?size=40px
:target: https://github.com/Kev-Roche
:alt: Kev-Roche

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Kev-Roche|

This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/18.0/product_alias>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_alias/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions product_alias/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Product Alias",
"summary": "Alias for each product attribute values's configuration",
"version": "18.0.1.0.0",
"category": "E-Commerce",
"website": "https://github.com/OCA/e-commerce",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["Kev-Roche"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"product",
],
"data": [
"views/product_template.xml",
"security/ir.model.access.csv",
],
}
3 changes: 3 additions & 0 deletions product_alias/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_alias
from . import product_template
from . import product_product
63 changes: 63 additions & 0 deletions product_alias/models/product_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.exceptions import ValidationError


class ProductAlias(models.Model):
_name = "product.alias"
_description = "Product Alias"

product_tmpl_id = fields.Many2one(
"product.template",
required=True,
ondelete="cascade",
)
Comment thread
sebalix marked this conversation as resolved.

name = fields.Char(
required=True,
)

attribute_value_ids = fields.Many2many(
"product.attribute.value",
string="Attribute Values",
domain="[('id', 'in', available_attribute_value_ids)]",
required=True,
)

Comment thread
sebalix marked this conversation as resolved.
available_attribute_value_ids = fields.Many2many(
"product.attribute.value",
string="Available Attributes",
compute="_compute_available_attribute",
)

@api.depends("product_tmpl_id.attribute_line_ids.value_ids")
@api.depends_context("default_product_tmpl_id")
def _compute_available_attribute(self):
for rec in self:
if self.env.context.get("default_product_tmpl_id"):
tmpl = self.env["product.template"].search(
[("id", "=", self.env.context.get("default_product_tmpl_id"))],
limit=1,
)
else:
tmpl = self.product_tmpl_id
rec.available_attribute_value_ids = self.env[
"product.attribute.value"
].browse(tmpl.attribute_line_ids.value_ids._origin.ids)

@api.constrains("attribute_value_ids")
def _check_attribute_value_ids(self):
for rec in self:
available_attr_values = rec.available_attribute_value_ids
for attr_value in rec.attribute_value_ids:
if attr_value in available_attr_values:
continue
raise ValidationError(
self.env._(
"Attribute value %(value)s is not available.",
value=attr_value.display_name,
)
)
40 changes: 40 additions & 0 deletions product_alias/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.exceptions import UserError


class ProductProduct(models.Model):
_inherit = "product.product"

alias_id = fields.Many2one(
"product.alias", "Alias", compute="_compute_alias_id", store=True
)

def _get_matching_alias(self):
match = self.env["product.alias"]
values = self.product_template_attribute_value_ids.product_attribute_value_id
for alias in self.product_alias_ids:
attrs = alias.attribute_value_ids.attribute_id
variant_values = values.filtered(
lambda s, attrs=attrs: s.attribute_id in attrs
)
if variant_values and not (variant_values - alias.attribute_value_ids):
match |= alias
if len(match) > 1:
raise UserError(
self.env._(
"Wrong alias attribute value configuration. "
"The variant %(variant)s match too many aliases %(aliases)s",
variant=self.display_name,
aliases=match.mapped("name"),
)
)
return match

@api.depends("product_alias_ids.attribute_value_ids")
def _compute_alias_id(self):
for record in self:
record.alias_id = record._get_matching_alias()
15 changes: 15 additions & 0 deletions product_alias/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

product_alias_ids = fields.One2many(
comodel_name="product.alias",
inverse_name="product_tmpl_id",
string="Product Aliases",
)
3 changes: 3 additions & 0 deletions product_alias/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions product_alias/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Kévin Roche \<kevin.roche@akretion.com\>
2 changes: 2 additions & 0 deletions product_alias/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows to add aliases from the product template for each
selected variants (or attribute values combination).
2 changes: 2 additions & 0 deletions product_alias/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_alias,product.alias.user,model_product_alias,base.group_user,1,1,1,1
Loading
Loading