Skip to main content
Odoo Community Association

Shopinvader Router Helper

Beta License: AGPL-3 shopinvader/odoo-shopinvader

Base helper for all shopinvader routers.

Simple Usage

The helper can be used as-is for a simple inheritable router logic:

@router.get("/name-type/{name}/{type}")
async def name_type(
    name: str, type: str, env: Annotated[Environment, Depends(odoo_env)]
  ):
  helper = env["shopinvader.router.name_type.helper"].new(dict(
      name=name, type=type
  ))
  return helper.fetch_data()


class RouterHelperNameType(VirtualModel):
    _inherit = "shopinvader.router.helper"
    _name = "shopinvader.router.name_type.helper"

    name = fields.Char()
    type = fields.Selection(
        selection=[("type_1", "Type 1"), ("type_2", "Type 2")],
        default="type_1",
    )

    def fetch_data(self):
      return requests.get("https://my.api/{}/{}".format(self.name, self.type))

CRUD Usage

The helper can also be used to implement a full CRUD logic. For that, you need to define the model to use and the domain to restrict the records operations on.

@router.post("/items/")
async def create_item(
    item: ItemCreate, env: Annotated[Environment, Depends(odoo_env)]
  ):
  helper = env["shopinvader.router.item.helper"].new()
  return helper.create(item.dict())

@router.get("/items/")
async def read_items(
    env: Annotated[Environment, Depends(odoo_env)]
  ):
  helper = env["shopinvader.router.item.helper"].new()
  return helper.search()

@router.get("/items/{item_id}")
async def read_item(
    item_id: int, env: Annotated[Environment, Depends(odoo_env)]
  ):
  helper = env["shopinvader.router.item.helper"].new()
  return helper.get(item_id)

@router.put("/items/{item_id}")
async def update_item(
    item_id: int, item: ItemUpdate, env: Annotated[Environment, Depends(odoo_env)]
  ):
  helper = env["shopinvader.router.item.helper"].new()
  return helper.write(item_id, item.dict())

@router.delete("/items/{item_id}")
async def delete_item(
    item_id: int, env: Annotated[Environment, Depends(odoo_env)]
  ):
  helper = env["shopinvader.router.item.helper"].new()
  return helper.unlink(item_id)

class RouterHelperItem(VirtualModel):
    _inherit = "shopinvader.router.helper"
    _name = "shopinvader.router.item.helper"

    _model = "my.item.model"

    def _domain(self):
        domain = [('api_available', '=', True)]
        domain.append(('partner_id', '=', self.partner_id.id))
        return domain

TODO

  • Check helper usage with fastapi dependency injection system for cleaner code.

  • More utils (pdf export, file handling, …).

Table of contents

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Akretion

Contributors

Maintainers

This module is part of the shopinvader/odoo-shopinvader project on GitHub.

You are welcome to contribute.

Metadata

Release files for odoo-addon-shopinvader-router-helper 18.0.1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for odoo-addon-shopinvader-router-helper 18.0.1.0.2
File Interpreter ABI Platform
odoo_addon_shopinvader_router_helper-18.0.1.0.2-py3-none-any.whl Python 3 none any Details

Release files / odoo_addon_shopinvader_router_helper-18.0.1.0.2-py3-none-any.whl

Download URL odoo_addon_shopinvader_router_helper-18.0.1.0.2-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
479c8b8119ec6fc9c2238ca63546e280e8cb9d1caa7b3a3a15c33fc2270035bd
BLAKE2b-256 checksum
How to use checksums
9cb9824c27a3e298bfc0dc52b7014faece82e0eb2c6f5a4235413a5b566183f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

18.0.1.0.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page