-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fastapi: add base service for exposing search/get
- Loading branch information
1 parent
df80e08
commit 901f86b
Showing
4 changed files
with
28 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import models | ||
from . import fastapi_dispatcher | ||
from . import services | ||
from . import utils |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
# 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 | ||
from odoo.exceptions import MissingError | ||
from odoo.osv import expression | ||
|
||
|
||
class FilteredDomainAdapter: | ||
def __init__(self, model: models.BaseModel, base_domain: list): | ||
self._model = model | ||
self._base_domain = base_domain | ||
|
||
def get(self, record_id: int) -> models.BaseModel: | ||
record = self._model.browse(record_id).filtered_domain(self._base_domain) | ||
if record: | ||
return record | ||
else: | ||
raise MissingError(_("The record do not exist")) | ||
|
||
def search_with_count(self, domain: list, limit, offset): | ||
domain = expression.AND([self._base_domain, domain]) | ||
|
||
count = self._model.search_count(domain) | ||
return count, self._model.search(domain, limit=limit, offset=offset) |