Odoo Help

2

1
6 Answers
3
Avatar

Gustavo

--Gustavo--
1000
| 2 2 6
Buenos Aires, Argentina
--Gustavo--

Python developer, big fan of sailing

Gustavo
18/04/13 19:29

What you can do is a third model that is populated by a SQL View that joins the two models. That's the best way to relate models in a view

3
duh386
25/04/13 16:18

Thank you, I forgot about this possibility. I have tried to do this, and it is working. If you are interesting, this is example of code (it is data from crm module. Report contains phonecalls, meeting and lead events on one calendar view):

report.py:

from osv import fields,osv
import tools

class crm_summary(osv.osv):
<tab indent must be started here>
_name = "crm.summary"
_auto = False

_columns = {
    'type': fields.char('Type', size=128, readonly=True),
    'name': fields.char('Name', size=512, readonly=True),
    'date': fields.datetime('Date', readonly=True),
}

_order = "date DESC"

def init(self, cr):
    tools.sql.drop_view_if_exists(cr, 'crm_summary')
    cr.execute("""
        CREATE view crm_summary as
          (SELECT l.id || 'l' as id,
          'lead' as type,
          l.title_action as name,
          l.date_action as date
          FROM crm_lead l
          GROUP BY l.id, type, l.title_action, l.date_action
          )
          UNION
          (SELECT c.id || 'c' as id, 
          'call' as type,
          c.name as name,
          c.date as date
          FROM crm_phonecall c
          GROUP BY c.id, type, c.name, c.date
          )
          UNION(
          SELECT m.id || 'm' as id, 
          'meeting' as type,
          m.name as name,
          m.date as date
          FROM crm_meeting m
          GROUP BY m.id, type, m.name, m.date
          )

    """)
<tab indent must be ended here>
crm_summary()

report.xml:

<record id="crm_summary_calendar" model="ir.ui.view">
        <field name="name">Crm summary calendar</field>
        <field name="model">crm.summary</field>
        <field name="type">calendar</field>
        <field name="arch" type="xml">
            <calendar string="Crm summary" color="type" date_start="date">
                <field name="name"/>
            </calendar>
        </field>
    </record>
1 Comment
PY
31/07/15 04:12

This doesn't work: the ids seems to overlap, and the tree view show only the last model added by union directive.

0
Avatar

IT Libertas

--IT Libertas--
988
| 4 3 9
Saint Petersburg, Federação Russa
--IT Libertas--

Visit us: https://odootools.com/

IT Libertas is a team of developers and automation experts to help you to unlock Odoo ERP system's potential. We have been communicating with end users to whom the software became a main business tool since 2012. As a result, we are proud of dozens of successful Odoo apps developed.

We are open for new ideas and challenges to create the best Odoo tools for business needs all over the world

IT Libertas
03/07/16 08:49

Have a look at the app https://apps.odoo.com/apps/modules/9.0/joint_calendar/

0
PY
31/07/15 04:45

Building on @duh386 answer.

Ids would overlap, here's my solution:

"""CREATE VIEW my_summary AS
SELECT *, row_number() OVER (ORDER BY name ASC) AS id
FROM
(
SELECT
              foo.name AS name,
FROM
                foo
UNION
SELECT
bar.name AS name, 
FROM
                bar
)
AS
summary
"""
This creates an unique id for each row in the view.
0
Avatar

Bonnet Denis

--Bonnet Denis--
956
| 5 6 10
St avé, França
--Bonnet Denis--

CEO/ODOO expert at Talyes.in

Bonnet Denis
13/05/13 08:02

You can use Super_calendar module. you can see it here. https://launchpad.net/server-env-tools

Ask a Question
Writer
Tags
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now