Odoo15开发手册-10.c服务器端开发-自定义设置

自定义设置

有时用户会需要从设置选项中配置某些属性的选项。Odoo 中当前提供了更多设置选项。在本节中,让我们讨论如何为我们的自定义模块添加自定义设置。

为此考虑一个存储教育组织的所有学生记录的模型。可能有一些组织需要在创建学生时向其发送电子邮件。但他们中的一些人可能不需要同样的东西。让我们创建一个设置选项,我们可以在其中启用或禁用该功能。为此,首先创建一个名为education_organisation的模块和一个用于存储学生记录的模型。

from odoo import fields, models
class Student(models.Model):
   _name = "student.student"
   _description = "Student"
   name = fields.Char(string="Name", required=True)
   phone = fields.Char(string="Phone Number")
   email = fields.Char(string="Email", required=True)

仅为学生模型添加基本字段。现在我们要继承 res.config.settings模型来添加自定义设置选项。

class ResConfigSettings(models.TransientModel):
   _inherit = 'res.config.settings'
   # mail send configurator
   send_mail = fields.Boolean(string="Notify Student", default=True,
                              help="Check to Send a mail to Student on "
                                   "creating a Student")

在配置菜单下为设置创建新菜单并定义操作。

行动记录


   Settings
   ir.actions.act_window
   res.config.settings
   
   form
   inline
   {'module' : education_organisation}

创建动作记录时要记住的一件事是上下文。有必要在动作上下文中传递{'module' : education_organisation}

现在让我们看看如何继承res.config.settings的表单视图来显示自定义字段。


   
       res.config.settings.view.form.inherit.organisation
   
    res.config.settings
   
   
   
       
           
               

Notify Student

通过继承现有视图将新的布尔字段添加到表单中。但是当我们访问视图时,只有我们的自定义字段才会在我们的菜单下显示。为了使这成为可能,您必须将模型名称传递给data-key 属性。否则,它将显示在主设置选项下显示的相同设置选项。

要记住的一件事是模型res.config.settings是一个瞬态模型。即模型中的数据不是数据库持久的。所以我们必须编写一些额外的函数来保存和检索视图的数据。

发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章