Odoo Help

Welcome!

This community 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.

2

Place two models on one view

By
duh386
on 4/18/13, 6:07 PM 5,346 views

Hello all. I need to do some interesting feature, and I hope you help me. I have some models with dates, for example project, task, resource.leaves, my custom models, etc. And my customer wants to see all this records on one gantt-view. For example, if I need to place task, I need to see resource.leaves to prevent placing task in busy employee's time. Openerp documentation says it is impossible. But this is nesessary feature, and in spite of documentation I will trying to realize this. May be somebody already released this, or have been trying to release - I will glad to see your experience.

2

Gustavo

--Gustavo--
950
| 2 1 4
Buenos Aires, Argentina
--Gustavo--

Python developer, big fan of sailing

Gustavo
On 4/18/13, 7:29 PM

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
On 4/25/13, 4:18 PM

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>

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

PY
on 7/31/15, 4:12 AM
0
IT Libertas
On 7/3/16, 8:49 AM

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

0
PY
On 7/31/15, 4:45 AM

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

Bonnet Denis

--Bonnet Denis--
925
| 5 6 8
Vannes, France
--Bonnet Denis--

Engeneer at MGS Consulting Ouest at Vannes, FRANCE

Bonnet Denis
On 5/13/13, 8:02 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/18/13, 6:07 PM
Seen: 5346 times
Last updated: 7/3/16, 8:49 AM