Hi
How can I list all of parent’s children with many2one/one2many relationship in a list view?
The model CourseSeries has a field course_product_ids, which has many children of CourseProduct (one2many).
I want to list now all these children (from course_product_ids) in a list view when I click on the Kanban view (just these from the parent). In the database the relations are saved correctly, but my list view does not show the children.
class CourseSeries(models.Model):
_name = 'ia.course.series'
_description = 'Shows course series per customer'
_rec_name = 'title'
course_id = fields.Char(string='Course ID')
title = fields.Char(string='Titel')
mandant_id = fields.Many2one('res.partner', string='Kunde', required=True)
course_product_ids = fields.One2many('ia.course.product' ,'course_series_id', string='Kursprodukten')
class CourseProduct(models.Model):
_name = 'ia.course.product'
_inherit = 'ia.product'
_description = 'Product'
_rec_name = 'course_series_id'
authors = fields.Char(string='Autoren')
subTitle = fields.Char(string='Untertitel')
abstract = fields.Char(string='abstract')
print_code = fields.Char(string='Print Code')
course_series_id = fields.Many2one('ia.course.series',default=lambda self: self.env.context.get('default_course_product_ids'), required=True)
class Product(models.Model):
_name = 'ia.product'
_description = 'Super class of product'
product_type = fields.Char(string='Produkttyp')
product_idenfication = fields.Char(string='Produktidentifikation')
active = fields.Boolean()
title = fields.Char('Titel')
publish_date = fields.Date()
language_code = fields.Selection(selection=[('de', 'DE'), ('fr', 'FR')])
The Kanban view below (id: kanban_view_ia_course_series, course_series_views.xml) calls the act_course_series_2_course_product and at last it will call the list view (id: view_tree_ia_course_product).
<!--Calls all course products from parent course series -->
<record id="act_course_series_2_course_product" model="ir.actions.act_window">
<field name="name">Course Products</field>
<field name="res_model">ia.course.product</field>
<field name="view_mode">tree,form</field>
<field name="context">{
'search_default_course_series_id': [active_id],
'default_course_series_id': active_id,
}</field>
<field name="view_id" ref="view_tree_ia_course_product" />
</record>
<!--Course Series Kanban view -->
<record id="kanban_view_ia_course_series" model="ir.ui.view">
<field name="name">course.series.kanban</field>
<field name="model">ia.course.series</field>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban class="oe_background_grey o_kanban_dashboard o_course_series o_emphasize">
<field name="mandant_id" />
<field name="title" />
<field name="course_id" />
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_global_click o_has_icon">
<div class="o_course_series_kanban_main">
<div class="o_kanban_card_manage_pane">
<div
class="o_kanban_card_manage_section o_kanban_manage_reports">
<div>
<a type="edit">Settings</a>
</div>
<div>
<a name="" type="action">Course Product</a>
</div>
<div>
<a name="" type="delete">Remove</a>
</div>
</div>
</div>
<a class="o_kanban_manage_toggle_button o_left" href="#">
<i class="fa fa-ellipsis-v" />
</a>
</div>
<div class="o_course_series_kanban_boxes">
<a class="o_course_series_kanban_box"
name="%(act_course_series_2_course_product)d" type="action" >
<div>
<div class="o_kanban_card_content">
<div class="o_kanban_primary_left">
<div class="o_primary">
<field name="mandant_id" />
</div>
</div>
</div>
<field name="title" />
<field name="course_id" />
</div>
</a>
</div>
</div>
This list view (course_product.xml) should show all product record, but nothing is shown.
<!-- Course Product Tree view -->
<record id="view_tree_ia_course_product" model="ir.ui.view">
<field name="name">ia.course.product.tree.view</field>
<field name="model">ia.course.product</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Course Series Tree View">
<field name="authors" />
<field name="print_code" />
</tree>
</field>
</record>
Thanks for any hint.