Skip to main content

Standard helper for shopinvader routers

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file odoo_addon_shopinvader_router_helper-18.0.1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for odoo_addon_shopinvader_router_helper-18.0.1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 479c8b8119ec6fc9c2238ca63546e280e8cb9d1caa7b3a3a15c33fc2270035bd
MD5 c93e485a83f3c6fe0c6df9bed32e4074
BLAKE2b-256 9cb9824c27a3e298bfc0dc52b7014faece82e0eb2c6f5a4235413a5b566183f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page