Search code examples
odoo-9odoo-10odoo

Get data from different model odoo 9


Is it possible in one tree view load data from eg. (Project Task, Project Issue, Purchase Order) where create date = Today.

Example:

Example

Any simple solution?


Solution

  • Try this example, return all from database:

    In .py file add below code:

    class CustomReport(models.Model):
        _name = "my.report"
        _description = "my report"
        _auto = False
    
    
        name = fields.Char(string='Name', readonly=True)
    
        def init(self, cr):
            tools.drop_view_if_exists(cr, self._table)
            cr.execute("""CREATE or REPLACE VIEW my_report as 
                            SELECT
                            id,
                            concat(name,' | ', description) as name
                            from project_task 
                            UNION ALL 
                            SELECT 
                            id,
                            concat(name,' | ', amount_total) as name
                            from purchase_order
                            UNION ALL 
                            SELECT 
                            id,
                            concat(number,' | ', residual) as name 
                            from account_invoice
                            """)
    

    In .xml file add:

    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
        <record id="view_my_report_tree" model="ir.ui.view">
            <field name="name">my.report.tree</field>
            <field name="model">my.report</field>
            <field name="arch" type="xml">
                <graph string="Name" type="bar">
                    <field name="id" type="row" />
                    <field name="name" type="row" />
                </graph>
            </field>
        </record>
    
    
        <record id="action_my_report" model="ir.actions.act_window">
            <field name="name">Name</field>
            <field name="res_model">my.report</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree</field>
        </record>
    
        <menuitem name="My report" action="action_my_report" id="menu_my_report"/>
    
    </odoo>
    

    Resault:

    enter image description here