跳转到主要内容

提供基础控制器和服务,以简化自定义API实现。

项目描述

此插件旨在为其他Odoo模块中的REST自定义实现提供基本服务和控制器结构。

用法

在我们的自定义模块中。当我们需要公开特定的模型时,我们将创建一个继承自基础服务的服务。

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

变更日志

12.0.1.0.0

第一个官方版本。

错误跟踪器

错误在GitLab Issues上跟踪。如果遇到问题,请检查是否已经报告了您的问题。如果您是第一个发现它的人,请帮助我们通过提供详细且受欢迎的反馈来解决问题。

鸣谢

基于Robin Keunen对easy_my_coop_api模块的初始工作,以及OCA rest-api的base_rest_demo。尝试从这个功能中分离出easy_my_coop垂直合作基础设施。

作者

  • Coodpevs Treball SCCL

  • Coop It Easy

贡献者

维护者

此模块由Coopdevs Treball SCCL维护。

项目详情


下载文件

为您的平台下载文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

此版本没有可用的源分布文件。请参阅生成分布存档的教程

构建分布

由...