Search code examples
reportingqwebodoo-13

How to iterate fields in qweb reports odoo?


How do you iterate fields in qweb reports? since I have two classes, I want customer_id to iterate base on the tree view created.

Models:

Class A:
    _name = 'module.a'

    module_id = fields.Many2one(string='sale', comodel_name='sale.order')
    customer_id = fields.Many2one('res.partner', string="Customer Name")

Class B:
    _inherit = 'sale.order'
    module_ids = fields.One2many(string="Module B",
                    comodel_name='module.a', inverse_name='module_id')

xml template:

   <template id="module_template" inherit_id="sale.sale_order_portal_content">
     <xpath expr="//div[2]/section[1]" position="before">
        <section class="mt-5">
            <h3 class="">Customer</h3>
            <div t-foreach="module_ids" t-as="line">
                <span t-esc="line.customer_id"/>
            </div>
        </section>
     </xpath>
  </template>

I try to do this but it won't iterate the customer_id in qweb report. The thing that only shows is the h3 - "Customer".

Note: That I need this to be One2Many and ManytoOne to create a tree view that adds a customer.


Solution

  • William Draper

    Try to access this,

    <div t-foreach="sale_order.module_ids" t-as="line">
    
        <span t-esc="line.customer_id"/>
    
    </div>
    

    You have access to the field in the report level with its object ['sale_order'].

    Thanks