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

Open a View in Pop Up in a one to many relationship

By
Cyrus Waithaka
on 9/14/14, 11:04 AM 1,206 views

Hi good people.

I am creating an addon to add a questionnaire to the partners view. I want this to be done under a "Questionnaire" tab that I have added to the partners view.

I have created the questionnaire model as follows

class customer_questionnaire(osv.osv):

  _name = "customer.questionnaire"

_columns = {
    #'partner': fields.many2one('res.partner', 'Partner', ondelete='cascade', select=1),
    'name': fields.char('Name', size=15, required=True), #several fields

I then extend Partners object as follows to add a questionnaire field:

class Partner(osv.osv):
    '''Partner'''
    _inherit = 'res.partner'
    _columns = {
    'questionnaire': fields.one2many('customer.questionnaire', 'partner', 'Confidential Questionnaire', help="Click to view/edit user's confidential questionnaire."),
    }

Here is the view that is adding the tab under customers page and a questionnaire field with a tree:

<page string='Questionnaire'>
                        <separator string="Customer Questionnaire" colspan="4" />
                        <field name="questionnaire" nolabel="1" colspan="4" readonly="1">
                            <tree string="Questionnaires">
                                <field name="work_hours" />
                                <field name="commute" />
                            </tree>
                            <form string="Questionnaires">
                                <field name="work_hours" />
                                <field name="commute" />
                            </form>
                        </field>
                    </page>

This still doesnt open the questionnaire view in pop up. I suppose I am missing something. What am I doing wrong? Can someone please outline the steps that I need to follow to open the questionnaire when I click on a row in the tab. Like how the contacts tab under company customers is made.

Thank you

 

1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 9/14/14, 1:38 PM

Hello Cyrus,

There are several mistakes which you need to correct.
1. You have to uncomment partner many2one field in customer.questionnaire object.
2. I don't see any fields named "work_hours" and "commute". Instead of them, you have to define "name" field in xml (or create appropriate field in py under customer.questionnaire object)
3. You have to remove readonly attribute from xml.

Corrected code:

Corrected code:

class customer_questionnaire(osv.osv):
    _name = "customer.questionnaire"
    _columns = {
        'partner': fields.many2one('res.partner', 'Partner', ondelete='cascade', select=1),
        'name': fields.char('Name', size=15, required=True), #several fields
    }

<page string='Questionnaire'>
    <separator string="Customer Questionnaire" colspan="4"/>
    <field name="questionnaire" nolabel="1" colspan="4">
        <tree string="Questionnaires">
            <field name="name"/>
        </tree>
        <form string="Questionnaires">
            <field name="name" />
        </form>
    </field>
</page>

Hi Sudhir, Thank you for your answer. Sorry, I did not paste the entire code. But I have tried your suggestions with no luck. Is the pop up created automatically once I add the relationship field on the view or am I required to define a function that creates the pop up? Here is the entire xml https://www.dropbox.com/s/1vs55p0r18hxzbk/customer_questionaire.xml?dl=0 and then my .py file https://www.dropbox.com/s/9it6dr1drhfqxv9/customer_questionaire.py?dl=0

Cyrus Waithaka
on 9/15/14, 3:17 AM

Yes, system creates pop by default. You just have to define o2m field in xml.

Sudhir Arya (SA)
on 9/15/14, 3:32 AM

It's creating the tab and the tree view fine but clicking on the field/rows does not generate the pop up. I have shared a link to download my code. please check it out from this link https://www.dropbox.com/sh/ius9524594pk7l6/AAC5P9UCP1ePmhWmhbjkP9cLa?dl=0 Thank you in advance

Cyrus Waithaka
on 9/15/14, 3:57 AM

It works now. An add item button is automatically added if you do the relationships properly. The readonly attribute was the issue. I however do not have enough points to vote your answer. Thank you anyway Sudhir :-)

Cyrus Waithaka
on 9/15/14, 8:49 AM

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: 9/14/14, 11:04 AM
Seen: 1206 times
Last updated: 3/18/15, 6:41 PM