Get data from different models 9

Is it possible in one view of tree view data, for example. (Project Task, Project Issue, Order Order), where create date = Today.

Example:

Example

Any simple solution?

+4
source share
3 answers

Try this example, return everything from the database:

In the .py file, add the code below:

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 the .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

+1
source

If you want to always display the entries that created the date, today you can do it.

1- first, use the tree view or any view in the backend, you must create one and only one model for it.

2-, , , .

3 - , , ,            () .

: . \addons\account\report\account_invoice_report.py

.

    _name = 'view.name'
    _auto = False 

overrid :

    # in odoo 10.0
    @api.model_cr
    def init(self):
        # drop the view first 
        tools.drop_view_if_exists(self.env.cr, self._table)

        # create the view.
        self.env.cr.execute("""CREATE or REPLACE VIEW %s as (
          you query here.
        )""" % self._table)

, , , .

+2

Model, .

, create_date , , view_mod, , , view_mod, , view_mod

+1
source

Source: https://habr.com/ru/post/1680284/


All Articles