Odoo Help

2

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

By
Cyrus Waithaka
on 9/14/14, 11:04 AM 1,730 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 (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
11081
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

Top 10 Odoo contributor On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com 
Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)
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

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 E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/14/14, 11:04 AM
Seen: 1730 times
Last updated: 3/18/15, 6:41 PM