Skip to content

Commit

Permalink
Get index from record context
Browse files Browse the repository at this point in the history
  • Loading branch information
qgroulard committed Sep 19, 2023
1 parent 7094a6e commit ba61d55
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 67 deletions.
16 changes: 5 additions & 11 deletions shopinvader_product/schemas/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ class ShortShopinvaderCategory(StrictExtendableBaseModel):
childs: list[ShortShopinvaderCategory] = []

@classmethod
def from_shopinvader_category(cls, odoo_rec, with_hierarchy=False, *args, **kwargs):
def from_shopinvader_category(cls, odoo_rec, with_hierarchy=False):
obj = cls.model_construct(
id=odoo_rec.record_id, name=odoo_rec.name, level=odoo_rec.short_description
)
if with_hierarchy:
parent = odoo_rec.parent_id
children = odoo_rec.child_id
obj.parent = (
ShortShopinvaderCategory.from_shopinvader_category(
parent, *args, **kwargs
)
ShortShopinvaderCategory.from_shopinvader_category(parent)
if parent
else None
)
obj.childs = [
ShortShopinvaderCategory.from_shopinvader_category(
child, *args, **kwargs
)
ShortShopinvaderCategory.from_shopinvader_category(child)
for child in children
]
return obj
Expand All @@ -41,9 +37,7 @@ class ShopinvaderCategory(ShortShopinvaderCategory):
sequence: int | None = None

@classmethod
def from_shopinvader_category(cls, odoo_rec, *args, **kwargs):
obj = super().from_shopinvader_category(
odoo_rec, with_hierarchy=True, *args, **kwargs
)
def from_shopinvader_category(cls, odoo_rec):
obj = super().from_shopinvader_category(odoo_rec, with_hierarchy=True)
obj.sequence = odoo_rec.sequence or None
return obj
6 changes: 2 additions & 4 deletions shopinvader_product/schemas/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ShopinvaderVariant(StrictExtendableBaseModel):
price: dict[str, ShopinvaderProductPriceInfo] = {}

@classmethod
def from_shopinvader_variant(cls, odoo_rec, *args, **kwargs):
def from_shopinvader_variant(cls, odoo_rec):
return cls.model_construct(
id=odoo_rec.record_id,
model=ShopinvaderProduct.from_shopinvader_product(
Expand All @@ -47,9 +47,7 @@ def from_shopinvader_variant(cls, odoo_rec, *args, **kwargs):
short_name=odoo_rec.short_name or None,
variant_count=odoo_rec.product_variant_count,
categories=[
ShortShopinvaderCategory.from_shopinvader_category(
shopinvader_category, with_hierarchy=False, *args, **kwargs
)
ShortShopinvaderCategory.from_shopinvader_category(shopinvader_category)
for shopinvader_category in odoo_rec.shopinvader_categ_ids
],
sku=odoo_rec.default_code or None,
Expand Down
4 changes: 2 additions & 2 deletions shopinvader_product_description/schemas/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ShopinvaderCategory(BaseShopinvaderCategory, extends=True):
short_description: str | None = None

@classmethod
def from_shopinvader_category(cls, odoo_rec, *args, **kwargs):
obj = super().from_shopinvader_category(odoo_rec, *args, **kwargs)
def from_shopinvader_category(cls, odoo_rec):
obj = super().from_shopinvader_category(odoo_rec)
obj.subtitle = odoo_rec.subtitle or None
obj.description = odoo_rec.description or None
obj.short_description = odoo_rec.short_description or None
Expand Down
4 changes: 2 additions & 2 deletions shopinvader_product_description/schemas/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ShopinvaderVariant(BaseShopinvaderVariant, extends=True):
description: str | None = None

@classmethod
def from_shopinvader_variant(cls, odoo_rec, *args, **kwargs):
obj = super().from_shopinvader_variant(odoo_rec, *args, **kwargs)
def from_shopinvader_variant(cls, odoo_rec):
obj = super().from_shopinvader_variant(odoo_rec)
obj.short_description = odoo_rec.description_sale_short or None
obj.description = odoo_rec.description_sale_long or None
return obj
4 changes: 2 additions & 2 deletions shopinvader_product_seo/schemas/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ShopinvaderCategory(BaseShopinvaderCategory, extends=True):
meta_description: str | None = None

@classmethod
def from_shopinvader_category(cls, odoo_rec, *args, **kwargs):
obj = super().from_shopinvader_category(odoo_rec, *args, **kwargs)
def from_shopinvader_category(cls, odoo_rec):
obj = super().from_shopinvader_category(odoo_rec)
obj.seo_title = odoo_rec.seo_title or None
obj.meta_keywords = odoo_rec.meta_keywords or None
obj.meta_description = odoo_rec.meta_description or None
Expand Down
4 changes: 2 additions & 2 deletions shopinvader_search_engine/models/se_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def _check_model(self):
def _get_serializer(self):
self.ensure_one()
if self.serializer_type == "shopinvader_category_exports":
return ProductCategoryShopinvaderSerializer(self)
return ProductCategoryShopinvaderSerializer()
elif self.serializer_type == "shopinvader_product_exports":
return ProductProductShopinvaderSerializer(self)
return ProductProductShopinvaderSerializer()
else:
return super()._get_serializer()
1 change: 0 additions & 1 deletion shopinvader_search_engine/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import category
from . import product
15 changes: 5 additions & 10 deletions shopinvader_search_engine/schemas/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

class ShortShopinvaderCategory(BaseShortShopinvaderCategory, extends=True):
@classmethod
def from_shopinvader_category(
cls, odoo_rec, with_hierarchy=False, index=None, *args, **kwargs
):
obj = super().from_shopinvader_category(odoo_rec, *args, **kwargs)
def from_shopinvader_category(cls, odoo_rec, with_hierarchy=False):
obj = super().from_shopinvader_category(odoo_rec)
index = odoo_rec._context.get("index", False)
if with_hierarchy and index:
parent = odoo_rec.parent_id.filtered(
lambda parent, index=index: index
Expand All @@ -22,16 +21,12 @@ def from_shopinvader_category(
in child.se_binding_ids.mapped("index_id")
)
obj.parent = (
ShortShopinvaderCategory.from_shopinvader_category(
parent, *args, **kwargs
)
ShortShopinvaderCategory.from_shopinvader_category(parent)
if parent
else None
)
obj.childs = [
ShortShopinvaderCategory.from_shopinvader_category(
child, *args, **kwargs
)
ShortShopinvaderCategory.from_shopinvader_category(child)
for child in children
]
return obj
25 changes: 0 additions & 25 deletions shopinvader_search_engine/schemas/product.py

This file was deleted.

5 changes: 1 addition & 4 deletions shopinvader_search_engine/tools/category_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@


class ProductCategoryShopinvaderSerializer:
def __init__(self, index):
self.index = index

def serialize(self, record):
return ShopinvaderCategory.from_shopinvader_category(record, index=self.index)
return ShopinvaderCategory.from_shopinvader_category(record)
5 changes: 1 addition & 4 deletions shopinvader_search_engine/tools/product_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@


class ProductProductShopinvaderSerializer:
def __init__(self, index):
self.index = index

def serialize(self, record):
return ShopinvaderVariant.from_shopinvader_variant(record, index=self.index)
return ShopinvaderVariant.from_shopinvader_variant(record)

0 comments on commit ba61d55

Please sign in to comment.