Reputation: 2186
Is it possible in one tree view load data from eg. (Project Task, Project Issue, Purchase Order) where create date = Today.
Example:
Any simple solution?
Upvotes: 4
Views: 1817
Reputation: 2358
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:
Upvotes: 1
Reputation: 14721
If you just want always to show the records that there create date is today you can do this.
1- first in backend to use tree view or any view you should create one and only one model for it.
2- when you need to show more then one model in the same tree view or as we can say you want to show a result of a query.
3- create a model that create a view in database instead of a table means the model is extracting data from the view (query) in database .
Example: see module \addons\account\report\account_invoice_report.py
To prevent the model from creating a table in database.
_name = 'view.name'
_auto = False
Then to create the view overrid the method :
# 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)
and now the the model will extract data from the view hope this is what yo want.
Upvotes: 2
Reputation: 769
If you want to load data from one single Model
then you can use action domain to filter.
If you want to load data from three different model where their create_date
is today, you can make one simple model for example view_mod
and put there all the interesting fields you want to view and then for each model you should create their corresponding view_mod
record and then again you need to filter with action domain to see all the view_mod
records created today
Upvotes: 1