2
votes

My ticket has many comments and I created a view for my comment and make a One2Many field in ticket model. But it is not displaying my desired view. Here is my model

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

Here my second model

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

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

Here is my Ticket's View:

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

Here is my Comment's Form View:

<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>

Here is my Comment's Tree View:

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

1 Answers

3
votes

If your comment model have more than one tree view or form view, if you don't specify witch view you want to display Odoo will compute the one with the highest priority:

so just specify the id of the tree view in your one2many field

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

Or you can use embedded view:

<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>

Note: if you have only this two views this means that Odoo didn't load this views so check if the XML file is in the manifest file and make sure you upgrade your module.