-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shopinvader_product_url: add module, shopinvader_base_url: improve mo…
…dule
- Loading branch information
1 parent
baf8e6d
commit e132a15
Showing
18 changed files
with
231 additions
and
10 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/shopinvader_product_url/odoo/addons/shopinvader_product_url
This file contains 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 @@ | ||
../../../../shopinvader_product_url |
This file contains 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,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_url_url,access_url_url,model_url_url,,1,0,0,0 | ||
access_read_url_url,access_url_url,model_url_url,,1,0,0,0 | ||
access_edit_url_url,access_url_url,model_url_url,group_edit_url,1,1,1,1 |
This file contains 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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record model="res.groups" id="group_edit_url"> | ||
<field name="name">Edit url</field> | ||
<field | ||
name="users" | ||
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]" | ||
/> | ||
</record> | ||
|
||
</odoo> |
This file contains 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
Empty file.
This file contains 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 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,25 @@ | ||
# Copyright 2023 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
|
||
{ | ||
"name": "Shopinvader product url", | ||
"summary": "Generate url for product and category", | ||
"version": "16.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Shopinvader", | ||
"website": "https://github.com/shopinvader/odoo-shopinvader", | ||
"author": " Akretion", | ||
"license": "AGPL-3", | ||
"external_dependencies": { | ||
"python": [], | ||
"bin": [], | ||
}, | ||
"depends": [ | ||
"shopinvader_base_url", | ||
"product", | ||
], | ||
"data": [], | ||
"demo": [], | ||
} |
This file contains 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 @@ | ||
from . import product_template | ||
from . import product_category |
This file contains 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,33 @@ | ||
# Copyright 2023 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
from odoo.addons.shopinvader_base_url.models.abstract_url import DEFAULT_LANG | ||
|
||
|
||
class ProductCategory(models.Model): | ||
_inherit = ["product.category", "abstract.url"] | ||
_name = "product.category" | ||
|
||
url_need_refresh = fields.Boolean(recursive=True) | ||
|
||
def _update_url_key(self, referential="global", lang=DEFAULT_LANG): | ||
# Ensure that parent url is up to date before updating the current url | ||
if self.parent_id: | ||
self.parent_id._update_url_key(referential=referential, lang=lang) | ||
return super()._update_url_key(referential=referential, lang=lang) | ||
|
||
def _generate_url_key(self, referential, lang): | ||
url_key = super()._generate_url_key(referential, lang) | ||
if self.parent_id: | ||
parent_url = self.parent_id._get_main_url(referential, lang) | ||
if parent_url: | ||
return "/".join([parent_url.key, url_key]) | ||
return url_key | ||
|
||
def _compute_url_need_refresh_depends(self): | ||
return super()._compute_url_need_refresh_depends() + [ | ||
"parent_id.url_need_refresh" | ||
] |
This file contains 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,13 @@ | ||
# Copyright 2023 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = ["product.template", "abstract.url"] | ||
_name = "product.template" | ||
|
||
def _get_keyword_fields(self): | ||
return super()._get_keyword_fields() + ["default_code"] |
This file contains 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 @@ | ||
* Sebastien BEAU <[email protected]> |
This file contains 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 @@ | ||
Generate url for product and category |
This file contains 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 test_category_url |
This file contains 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,57 @@ | ||
# Copyright 2019 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.tests import TransactionCase | ||
|
||
|
||
class TestCategoryUrl(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.lang_en = cls.env.ref("base.lang_en") | ||
cls.lang_fr = cls.env.ref("base.lang_fr") | ||
cls.lang_fr.active = True | ||
cls.categ_1 = ( | ||
cls.env["product.category"] | ||
.with_context(lang="en_US") | ||
.create({"name": "Root"}) | ||
) | ||
cls.categ_2 = ( | ||
cls.env["product.category"] | ||
.with_context(lang="en_US") | ||
.create({"name": "Level 1", "parent_id": cls.categ_1.id}) | ||
) | ||
cls.categ_3 = ( | ||
cls.env["product.category"] | ||
.with_context(lang="en_US") | ||
.create({"name": "Level 2", "parent_id": cls.categ_2.id}) | ||
) | ||
|
||
def _expect_url_for_lang(self, record, lang, url_key): | ||
self.assertEqual(record._get_main_url("global", lang).key, url_key) | ||
|
||
def test_url_for_main_categ(self): | ||
self.categ_1._update_url_key(lang="en_US") | ||
self._expect_url_for_lang(self.categ_1, "en_US", "root") | ||
|
||
def test_url_for_child(self): | ||
self.categ_3._update_url_key(lang="en_US") | ||
self._expect_url_for_lang(self.categ_1, "en_US", "root") | ||
self._expect_url_for_lang(self.categ_2, "en_US", "root/level-1") | ||
self._expect_url_for_lang(self.categ_3, "en_US", "root/level-1/level-2") | ||
|
||
def test_update_main(self): | ||
self.categ_3._update_url_key(lang="en_US") | ||
self.categ_1.name = "New Root" | ||
self.categ_3._update_url_key(lang="en_US") | ||
self._expect_url_for_lang(self.categ_1, "en_US", "new-root") | ||
self._expect_url_for_lang(self.categ_2, "en_US", "new-root/level-1") | ||
self._expect_url_for_lang(self.categ_3, "en_US", "new-root/level-1/level-2") | ||
|
||
def test_update_child(self): | ||
self.categ_3._update_url_key(lang="en_US") | ||
self.categ_2.name = "New Level 1" | ||
self.categ_3._update_url_key(lang="en_US") | ||
self._expect_url_for_lang(self.categ_1, "en_US", "root") | ||
self._expect_url_for_lang(self.categ_2, "en_US", "root/new-level-1") | ||
self._expect_url_for_lang(self.categ_3, "en_US", "root/new-level-1/level-2") |