Skip to content

Commit

Permalink
fixup! fastapi: add base service for exposing search/get
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Oct 16, 2023
1 parent df80e08 commit 901f86b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 52 deletions.
1 change: 1 addition & 0 deletions fastapi/__init__.py
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
1 change: 0 additions & 1 deletion fastapi/services/__init__.py

This file was deleted.

51 changes: 0 additions & 51 deletions fastapi/services/fastapi_service_base.py

This file was deleted.

27 changes: 27 additions & 0 deletions fastapi/utils.py
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)

0 comments on commit 901f86b

Please sign in to comment.