Skip to content

Commit

Permalink
shopinvader_base_url: add fields url_key and redirect_url_key, shopin…
Browse files Browse the repository at this point in the history
…vader_product_url add fields to schemas
  • Loading branch information
qgroulard committed Aug 29, 2023
1 parent cf8e56e commit 1c3071e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
15 changes: 15 additions & 0 deletions shopinvader_base_url/models/abstract_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions shopinvader_product_url/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import schemas
2 changes: 1 addition & 1 deletion shopinvader_product_url/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"depends": [
"shopinvader_base_url",
"product",
"shopinvader_product",
],
"data": [],
"demo": [],
Expand Down
2 changes: 2 additions & 0 deletions shopinvader_product_url/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import category
from . import product
27 changes: 27 additions & 0 deletions shopinvader_product_url/schemas/category.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions shopinvader_product_url/schemas/product.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1c3071e

Please sign in to comment.