跳转到主要内容

提供基础控制器和服务,简化其他Odoo模块中的自定义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维护。

项目详情


下载文件

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

源分布

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

构建的分发

odoo12_addon_base_rest_base_structure-12.0.1.0.3-py2.py3-none-any.whl (7.1 kB 查看哈希值)

上传于 Python 2 Python 3

由以下支持