-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] Category parent/child and level + se_index_record filter by index
- Loading branch information
Showing
8 changed files
with
68 additions
and
30 deletions.
There are no files selected for viewing
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,9 +1,36 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductCategory(models.Model): | ||
_name = "product.category" | ||
_inherit = ["product.category", "se.indexable.record"] | ||
|
||
shopinvader_parent_id = fields.Many2one( | ||
"product.category", | ||
"Shopinvader Parent", | ||
compute="_compute_parent_category", | ||
) | ||
shopinvader_child_ids = fields.Many2many( | ||
"product.category", | ||
"Shopinvader Childs", | ||
compute="_compute_child_category", | ||
) | ||
|
||
@api.depends_context("index") | ||
@api.depends("parent_id", "parent_id.se_binding_ids") | ||
def _compute_parent_category(self): | ||
for record in self: | ||
record.shopinvader_parent_id = record.parent_id._filter_by_index() | ||
|
||
@api.depends_context("index") | ||
@api.depends("child_id", "child_id.se_binding_ids") | ||
def _compute_child_category(self): | ||
for record in self: | ||
record.shopinvader_child_ids = record.child_id._filter_by_index() | ||
|
||
def _get_parent(self): | ||
self.ensure_one() | ||
return self.shopinvader_parent_id |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import models | ||
|
||
|
||
class SeIndexableRecord(models.AbstractModel): | ||
|
||
_inherit = "se.indexable.record" | ||
|
||
def _filter_by_index(self): | ||
index = self._context.get("index", False) | ||
records = self | ||
if index: | ||
records = records.filtered( | ||
lambda rec, index=index: index in rec.se_binding_ids.mapped("index_id") | ||
) | ||
return records |
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