Skip to main content

Base Rest Base Structure

This addon aims to provide a basic service and controller structure to simplify a rest custom implemenation in other odoo modules.

Usage

On our custom module. When we need to expose an specific model we’ll create a service extending from the base ones.

from odoo.addons.component.core import Component
from odoo.addons.base_rest_base_structure.models.api_services_utils import APIServicesUtils

class CustomModelService(Component):
    _inherit = "base.rest.private_abstract_service"
    _name = "custom_module.custom_model.services"
    _usage = "custom-endpoint"
    _description = """
        Custom Model Service
    """

def get(self, _id):
    record = self.env["custom_module.custom_model"].search(
        [("id", "=", _id)]
    )
    if record:
        record.ensure_one()
        utils = APIServicesUtils.get_instance()
        # Define here all fields to be passed to the response
        attributes = ["name"]
        # Define here all many2one fields to be passed to the response
        rel_attributes = {
          "rel_model_id" : "name"
        }
        return utils.generate_get_dictionary(record,attributes,rel_attributes)
    else:
      raise wrapJsonException(
        NotFound(_("No reward record for id %s") % _id)
      )

def create(self, **params):
    utils = APIServicesUtils.get_instance()
    # define all fields that the API receive
    attributes = ["name"]
    create_dict = utils.generate_create_dictionary(params,attributes)
    record = self.env["custom_module.custom_model"].create(create_dict)
    return {"_id": record.id}

# rest of methods defined below

Changelog

12.0.1.0.0

First official version.

Bug Tracker

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

Credits

Based on the initial work of Robin Keunen <robin@coopiteasy.be> for easy_my_coop_api module and on base_rest_demo from OCA rest-api. Trying to decople this functionallity from easy_my_coop vertical-cooperative infraestructure.

Authors

  • Coodpevs Treball SCCL

  • Coop It Easy

Contributors

Maintainers

This module is maintained by Coopdevs Treball SCCL.

Metadata

Release files for odoo14-addon-base-rest-base-structure 14.0.0.0.1

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 odoo14-addon-base-rest-base-structure 14.0.0.0.1
File Interpreter ABI Platform
odoo14_addon_base_rest_base_structure-14.0.0.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / odoo14_addon_base_rest_base_structure-14.0.0.0.1-py2.py3-none-any.whl

Download URL odoo14_addon_base_rest_base_structure-14.0.0.0.1-py2.py3-none-any.whl
Size 7.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
66941524f852aa4517a84f60b00f4d696011635f728b028665a7b6853a81b950
BLAKE2b-256 checksum
How to use checksums
14a699188b90ec07041467b3a104dfe302b072f83ed4f4a2061bad9af5fcb4d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

14.0.0.0.1 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