Mani
Mani

Reputation: 2655

How to create a manual view in odoo?

The below view is not created. What is the issue?

Method:

      def daily_flash_report_tree(self, cr, uid, ids, context=None):
          sql = """
            CREATE OR REPLACE VIEW report_view AS (
              SELECT 
                   id,name,job
                from   
                   sales_summary limit 10
             ) 

        """

        cr.execute(sql)

        return {
            'name': "Daily Flash Report",
            'view_type': 'form',
            'view_mode': 'tree',
            'res_model': 'daliy.flash.report',
            'type': 'ir.actions.act_window',
            'context': {"search_default_group_period": 1},
        }

Object:

class daily_flah_report_new(osv.osv):

    _name = "daliy.flash.report"
    _auto = False

    _columns = {
        'name': fields.char('Name'),
        'job': fields.char('Job'),
    }

View:

<record id="drill_flash_report_flash" model="ir.ui.view">
    <field name="name">Report</field>
    <field name="model">daliy.flash.report</field>
     <field name="arch" type="xml">
         <tree>
            <field name="name"   />
            <field name="job"   />
         </tree>
     </field>
</record>

<record id="drill_flash_report_action" model="ir.actions.act_window">
        <field name="name">Net Revenue</field>
        <field name="res_model">daliy.flash.report</field>
        <field name="type">ir.actions.act_window</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree</field>
        <field name="context">{"search_default_group_period": 1}</field>
</record>

Upvotes: 0

Views: 864

Answers (1)

Hoang
Hoang

Reputation: 76

please notice that you created view named "report_view"

       CREATE OR REPLACE VIEW report_view AS (
          SELECT 
               id,name,job
            from   
               sales_summary limit 10
         ) 

Because your object is daliy.flash.report so your default table of your object is daliy_flash_report

_name = "daliy.flash.report"
_auto = False

They are different, you should make sure name of table of object is same as name of the view. Solution: choose 1 or 2.

  1. You should create view named daliy_flash_report by below comment
   CREATE OR REPLACE VIEW daliy_flash_report AS (
      SELECT 
           id,name,job
        from   
           sales_summary limit 10
     )
  1. Use attribute _table in your object to indicate table name.
    class daily_flah_report_new(osv.osv):
       _name = "daliy.flash.report"
       _auto = False
       _table = "report_view"

Good luck

Upvotes: 1

Related Questions