Thanks to the help of smart people on this site, I now have a nice One2many field in my module that allows me to add multiple order lines just like in the sales module. It works quite well, but now for convenience, I would like to be able to see a certain field within that One2many field in my tree and calendar views. However, when I try to display that field with the method described below, all I get is the number of records. In particular, I want it to display all of the products that were added to the order lines. Here is the relevant code:
models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.addons import decimal_precision as dp
class mymodule_base(models.Model):
_name = 'mymodule.mymodule'
_description = 'My Module'
operations = fields.One2many('mymodule.line', 'order_id', 'Operation Lines')
class mymodule_line(models.Model):
_name = 'mymodule.line'
_description = 'Order Line'
order_id = fields.Many2one('mymodule.mymodule')
product_id = fields.Many2one('product.template', string='Repair / Part', required=False)
views.xml
<record id="mymodule.calendar" model="ir.ui.view">
<field name="name">MyModule Calendar</field>
<field name="model">mymodule.mymodule</field>
<field name="arch" type="xml">
<calendar string="Repairs" date_start="date_received" date_stop="date_due" color="state">
<field name="operations">
<field name="product_id"/>
</field>
</calendar>
</field>
</record>
<record model="ir.ui.view" id="mymodule.list">
<field name="name">MyModule list</field>
<field name="model">mymodule.mymodule</field>
<field name="arch" type="xml">
<tree>
<field name="operations">
<field name="product_id"/>
</field>
</tree>
</field>
</record>
Here is an image of what my list view looks like with the above code: List View
I would greatly appreciate any help. Please let me know if I need to further clarify what I'm trying to do.
EDIT I have tried Juan's suggestion, but I still only see numbers, not the product names, in my view. Here is what I did. I am not sure if I followed the instructions correctly.
Under mymodule.line
product_name = fields.Char(related='product_id.name', store=True)
Under list view
<field name="operations" widget="one2many_list" mode="tree">
<field name="product_id" invisible="True"/>
<field name="product_name"/>
</field>
It doesn't seem to matter whether or not I include these two lines under the operations definition.
<field name="product_id" invisible="True"/>
<field name="product_name"/>
I still get the same result.
EDIT 2 I have tried adding a related field under mymodule.mymodule as such:
product_name = fields.Char(related='operations.product_id.name')
Then, I define this field in my list view like so:
<field name="product_name"/>
And this gives me almost what I want, except it only displays the name of one product, not all of them.