title: Odoo - init function is not working
body: <p>I am working in a sample module and i am creating a view in which i wanted to display record based on criteria and from multiple models. Which are already being created.</p>
  
  <p><strong><code>Pending Accounts</code></strong></p>
  
  <pre class="lang-py prettyprint-override"><code>class PendingAccounts(models.Model):
      _name = 'amgl.pending_accounts'
      _description = 'Pending Account'
  
      name = fields.Char()
      first_name = fields.Char(string="First Name")
      last_name = fields.Char(string="Last Name")
      quantity_expected = fields.Float(string="Quantity Expected")
      quantity_received = fields.Float(string="Quantity Received")
      possible_reason = fields.Many2one('amgl.product_reason',string='Possible Reason')
      possible_solution = fields.Many2one('amgl.product_solution', string='Possible Solution')
      notes = fields.Html(string='Notes')
  
      @api.model_cr
      def init(self):
          tools.drop_view_if_exists(self._cr, 'pending_accounts')
          self._cr.execute("""
              CREATE VIEW pending_accounts AS (
                  SELECT c.name AS first_name,
                  c.last_name AS last_name,
                  o.total_received_qty AS quantity_received,
                  o.total_qty AS quantity_expected
                  FROM amgl_order AS o
                  INNER JOIN amgl_customer AS c ON c.id = o.customer_id
                  WHERE o.is_pending = True
              )""")
  </code></pre>
  
  <p><strong><code>Pending Accounts View</code></strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;odoo&gt;
  &lt;data&gt;
      &lt;record id="amgl.pending_accounts_action_window" model="ir.actions.act_window"&gt;
          &lt;field name="name"&gt;Pending Accounts&lt;/field&gt;
          &lt;field name="type"&gt;ir.actions.act_window&lt;/field&gt;
          &lt;field name="res_model"&gt;amgl.pending_accounts&lt;/field&gt;
          &lt;field name="view_mode"&gt;tree,form&lt;/field&gt;
          &lt;field name="help" type="html"&gt;
            &lt;p class="oe_view_nocontent_create"&gt;
              &lt;!-- Add Text Here --&gt;
            &lt;/p&gt;&lt;p&gt;
              &lt;!-- More details about what a user can do with this object will be OK --&gt;
            &lt;/p&gt;
          &lt;/field&gt;
      &lt;/record&gt;
      &lt;record id="amgl.pending_accounts_form" model="ir.ui.view"&gt;
          &lt;field name="name"&gt;Pending Accounts Form&lt;/field&gt;
          &lt;field name="model"&gt;amgl.pending_accounts&lt;/field&gt;
          &lt;field name="arch" type="xml"&gt;
              &lt;form string="Pending Inventories"&gt;
                  &lt;sheet&gt;
                      &lt;group&gt;
                          &lt;field name="first_name"/&gt;
                          &lt;field name="last_name"/&gt;
                          &lt;field name="quantity_expected"/&gt;
                          &lt;field name="quantity_received"/&gt;
                          &lt;field name="possible_reason"/&gt;
                          &lt;field name="possible_solution"/&gt;
                          &lt;field name="notes"/&gt;
                      &lt;/group&gt;
                  &lt;/sheet&gt;
              &lt;/form&gt;
          &lt;/field&gt;
      &lt;/record&gt;
  
      &lt;record id="amgl.pending_accounts_tree" model="ir.ui.view"&gt;
          &lt;field name="name"&gt;Pending Account&lt;/field&gt;
          &lt;field name="model"&gt;amgl.pending_accounts&lt;/field&gt;
          &lt;field name="arch" type="xml"&gt;
              &lt;tree string="Pending Accounts"&gt;
                  &lt;field name="first_name"/&gt;
                  &lt;field name="last_name"/&gt;
                  &lt;field name="quantity_expected"/&gt;
                  &lt;field name="quantity_received"/&gt;
                  &lt;field name="possible_reason"/&gt;
                  &lt;field name="possible_solution"/&gt;
                  &lt;field name="notes"/&gt;
              &lt;/tree&gt;
          &lt;/field&gt;
      &lt;/record&gt;
  &lt;/data&gt;
  &lt;/odoo&gt;
  </code></pre>
  
  <p>So i created a model and added query to get all those records in <code>init</code> method of model. But its not showing any records in tree view.I also run the query in pgadmin and there is a records coming against this query as shown in attachment.
  <a href="https://i.stack.imgur.com/vkLBf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vkLBf.png" alt="enter image description here"></a></p>
  
  <p>I am facing following error now,</p>
  
  <pre><code>Traceback (most recent call last):
      File "/home/ahsan/v10/odoo/http.py", line 638, in _handle_exception
      return super(JsonRequest, self)._handle_exception(exception)
      File "/home/ahsan/v10/odoo/http.py", line 675, in dispatch
      result = self._call_function(**self.params)
      File "/home/ahsan/v10/odoo/http.py", line 331, in _call_function
      return checked_call(self.db, *args, **kwargs)
      File "/home/ahsan/v10/odoo/service/model.py", line 101, in wrapper
      return f(dbname, *args, **kwargs)
      File "/home/ahsan/v10/odoo/http.py", line 324, in checked_call
      result = self.endpoint(*a, **kw)
      File "/home/ahsan/v10/odoo/http.py", line 933, in __call__
      return self.method(*args, **kw)
      File "/home/ahsan/v10/odoo/http.py", line 504, in response_wrap
      response = f(*args, **kw)
      File "/home/ahsan/v10/addons/web/controllers/main.py", line 827, in 
      search_read
      return self.do_search_read(model, fields, offset, limit, domain, sort)
      File "/home/ahsan/v10/addons/web/controllers/main.py", line 849, in 
      do_search_read
      offset=offset or 0, limit=limit or False, order=sort or False)
      File "/home/ahsan/v10/odoo/models.py", line 4681, in search_read
      records = self.search(domain or [], offset=offset, limit=limit, order=order)
      File "/home/ahsan/v10/odoo/models.py", line 1518, in search
      res = self._search(args, offset=offset, limit=limit, order=order, count=count)
      File "/home/ahsan/v10/odoo/models.py", line 4242, in _search
      self._cr.execute(query_str, where_clause_params)
      File "/home/ahsan/v10/odoo/sql_db.py", line 141, in wrapper
      return f(self, *args, **kwargs)
      File "/home/ahsan/v10/odoo/sql_db.py", line 218, in execute
      res = self._obj.execute(query, params)
      ProgrammingError: column amgl_pending_accounts.id does not exist
      LINE 1: SELECT "amgl_pending_accounts".id FROM "amgl_pending_account...
  </code></pre>