This question has been flagged
1 Reply
5671 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

 

Avatar
Discard
Best Answer

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>

Avatar
Discard
Author

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

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

Author

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

Author

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 :-)