-
-
Notifications
You must be signed in to change notification settings - Fork 564
[18.0][MIG] product_alias (was shopinvader_product_alias) #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sebalix
wants to merge
8
commits into
OCA:18.0
Choose a base branch
from
akretion:18.0-mig-shopinvader_product_alias
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fbd012f
[14.0][ADD] shopinvader_product_alias
Kev-Roche a911c3a
shopinvader_product_alias: add alias_id on product.product and add test
sebastienbeau a7f129d
shopinvader_product_alias: improve view
sebastienbeau e74d1b5
FIX matching_alias error raising
Kev-Roche be497b2
FIX available_attribute_value compute
Kev-Roche 84e4507
[FIX] shopinvader_product_alias: Prevent variant alias view and use i…
paradoxxxzero 5542301
[IMP] product_alias: pre-commit auto fixes
sebalix ecc80e5
[MIG] product_alias: Migration to 18.0
sebalix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 url aliases from the product template for each | ||
| selectected variants (or attribute values's combinaison). | ||
|
|
||
| **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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": "Shopinvader", | ||
| "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", | ||
| ], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # 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 | ||
|
|
||
|
|
||
| class ProductAlias(models.Model): | ||
| _name = "product.alias" | ||
| _description = "Product Alias" | ||
|
|
||
| product_tmpl_id = fields.Many2one( | ||
| "product.template", | ||
| required=True, | ||
| ) | ||
|
|
||
| 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, | ||
| ) | ||
|
|
||
| available_attribute_value_ids = fields.Many2many( | ||
| "product.attribute.value", | ||
| string="Available Attributes", | ||
| compute="_compute_available_attribute", | ||
| ) | ||
|
|
||
| @api.depends("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 = [ | ||
| (6, 0, tmpl.attribute_line_ids.value_ids._origin.ids) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # 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( | ||
| _( | ||
| "Wrong alias attribute value configuration" | ||
| "The variant %(variant)s match too many aliases %(aliases)s", | ||
| ) | ||
| % dict( | ||
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Kévin Roche \<kevin.roche@akretion.com\> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| This module allows to add url aliases from the product template for each | ||
| selectected variants (or attribute values's combinaison). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL? I see no URL feature here 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, how is this different from having product links of type "alias"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @sebastienbeau