【问题标题】:How to display One2many field's view in my custom view?如何在我的自定义视图中显示 One2many 字段的视图?
【发布时间】:2019-09-30 07:44:55
【问题描述】:

我的工单有很多 cmets,我为我的评论创建了一个视图,并在工单模型中创建了一个 One2Many 字段。但它没有显示我想要的视图。这是我的模型

    class Ticket(model.Model):
      _name = 'Tickets'
      comment_ids = fields.One2many('comments', 'comment_id')

这是我的第二个模型

class Comments(models.Model):
_name = 'comments'

comment = fields.Text(string="Comment")
comment_id = fields.Char(string='Comment Id')

这是我的票证视图:

<notebook>
    <page name="body" string="Body">
        <field name="comment_ids" />    
    </page>
</notebook>

这是我的评论表单视图:

<form>
   <div class="form-group">
      <label name="comment">Comment:</label>
      <textarea class="form-control" rows="5" />
   </div>
   <button type="submit" class="btn btn-primary">Submit</button>
</form>

这是我的评论树视图:

<tree>
   <field name = 'comment_id'/>
   <field name = 'comment'/>
</tree>

【问题讨论】:

    标签: forms view tree odoo one2many


    【解决方案1】:

    如果您的评论模型有多个树视图或表单视图,如果您不指定 您要显示的女巫视图 Odoo 将计算具有最高优先级的视图:

    因此,只需在您的 one2many 字段中指定 tree viewid

    <field name="comment_ids" context="{'tree_view_ref': 'your_app.tree_view_xml_id', 'form_view_ref': 'your_app.form_view_xml_id'}"/>
    

    或者你可以使用嵌入式视图:

    <field name="comment_ids">
            <tree>
                <field name = 'comment_id'/>
                <field name = 'comment'/>
            </tree>
            <form>
               <div class="form-group">
                  <label name="comment">Comment:</label>
                  <textarea class="form-control" rows="5" />
               </div>
               <button type="submit" class="btn btn-primary">Submit</button>
            </form>
        </field>
    

    注意:如果您只有这两个视图,这意味着 Odoo 没有加载此视图,因此请检查 XML 文件是否在 manifest 文件中并确保您 @987654328 @你的模块。

    【讨论】:

    • 我可以联系你吗?我在哪里可以直接邮寄给您或其他?
    猜你喜欢
    • 2018-04-03
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多