diff --git a/shopinvader_base_url/models/abstract_url.py b/shopinvader_base_url/models/abstract_url.py index ac92bbe57f..91e3c5efaf 100644 --- a/shopinvader_base_url/models/abstract_url.py +++ b/shopinvader_base_url/models/abstract_url.py @@ -41,6 +41,10 @@ class AbstractUrl(models.AbstractModel): compute="_compute_url_need_refresh", store=True, readonly=False ) count_url = fields.Integer(compute="_compute_count_url") + url_key = fields.Char(compute="_compute_url_key") + redirect_url_key = fields.Serialized( + compute="_compute_url_key", string="Redirect Url Keys" + ) def _compute_count_url(self): res = self.env["url.url"].read_group( @@ -63,6 +67,17 @@ def _compute_url_need_refresh(self): for record in self: record.url_need_refresh = True + @api.depends("url_ids") + @api.depends_context("lang", "referential") + def _compute_url_key(self): + referential = self._context.get("referential", "global") + lang = self._context.get("lang", "en_US") + for record in self: + record.url_key = record._get_main_url(referential, lang).key + record.redirect_url_key = record._get_redirect_urls( + referential, lang + ).mapped("key") + def _get_keyword_fields(self): """This method return a list of field that will be concatenated with '-' to generate the url diff --git a/shopinvader_product_url/__init__.py b/shopinvader_product_url/__init__.py index 0650744f6b..106fc57265 100644 --- a/shopinvader_product_url/__init__.py +++ b/shopinvader_product_url/__init__.py @@ -1 +1,2 @@ from . import models +from . import schemas diff --git a/shopinvader_product_url/__manifest__.py b/shopinvader_product_url/__manifest__.py index 8c39235d5b..8fdd430737 100644 --- a/shopinvader_product_url/__manifest__.py +++ b/shopinvader_product_url/__manifest__.py @@ -18,7 +18,7 @@ }, "depends": [ "shopinvader_base_url", - "product", + "shopinvader_product", ], "data": [], "demo": [], diff --git a/shopinvader_product_url/schemas/__init__.py b/shopinvader_product_url/schemas/__init__.py new file mode 100644 index 0000000000..c4b279f562 --- /dev/null +++ b/shopinvader_product_url/schemas/__init__.py @@ -0,0 +1,2 @@ +from . import category +from . import product diff --git a/shopinvader_product_url/schemas/category.py b/shopinvader_product_url/schemas/category.py new file mode 100644 index 0000000000..46548b1611 --- /dev/null +++ b/shopinvader_product_url/schemas/category.py @@ -0,0 +1,27 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.shopinvader_product.schemas.category import ( + ShortShopinvaderCategory as BaseShortShopinvaderCategory, + ShopinvaderCategory as BaseShopinvaderCategory, +) + + +class ShortShopinvaderCategory(BaseShortShopinvaderCategory, extends=True): + url_key: str | None = None + + @classmethod + def from_shopinvader_category(cls, odoo_rec): + obj = super().from_shopinvader_category(odoo_rec) + obj.url_key = odoo_rec.url_key or None + return obj + + +class ShopinvaderCategory(BaseShopinvaderCategory, extends=True): + redirect_url_key: list[str] = [] + + @classmethod + def from_shopinvader_category(cls, odoo_rec): + obj = super().from_shopinvader_category(odoo_rec) + obj.redirect_url_key = odoo_rec.redirect_url_key + return obj diff --git a/shopinvader_product_url/schemas/product.py b/shopinvader_product_url/schemas/product.py new file mode 100644 index 0000000000..f0dd87a7bf --- /dev/null +++ b/shopinvader_product_url/schemas/product.py @@ -0,0 +1,18 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.shopinvader_product.schemas.product import ( + ShopinvaderVariant as BaseShopinvaderVariant, +) + + +class ShopinvaderVariant(BaseShopinvaderVariant, extends=True): + url_key: str | None = None + redirect_url_key: list[str] = [] + + @classmethod + def from_shopinvader_variant(cls, odoo_rec): + obj = super().from_shopinvader_variant(odoo_rec) + obj.url_key = odoo_rec.url_key or None + obj.redirect_url_key = odoo_rec.redirect_url_key + return obj