2

I have created one custom model that contain three relation fields. Following is relations:

class SurveyCreate(models.Model):

    _name = 'create.survey’

    survey_name = fields.Many2one('survey.survey',string='Survey Title')
    pages_id = fields.One2many('survey.page','create_id_survey','Pages')
    questions_survey = fields.One2many('survey.question','create_id_survey','Questions')

and many2one fields created in survey.page & survey.question resp.

Follwing is xml file:


<group>
                    <field name="survey_name"/>
                </group>
                <group>
                    <field name="pages_id" mode="tree">
                        <tree editable="bottom">
                            <control>
                                <create string="Add page"/>
                            </control>
                            <field name="title"/>   
                            <field name="questions_id" widget="many2many_tags" options="{'no_create':True}" context="{'tree_view_ref':'survey_inherit.questions_survey'}"/> 
                        </tree>
                    </field>
                </group>
                <group> 
                    <field name="questions_survey" mode='tree'>
                        <control>
                            <create string="Add Question"/>
                        </control>
                        <tree name="questions_tree" editable="bottom">
                            <field name="question"/>
                            <field name="type"/>
                        </tree>                 
                    </field>
                </group>

As in screenshort when select on pages -> question that should be display in below questions field.

For this I take the reference of invoice creation form. In invoice creation form when you select product & after selecting tax then it will display in tax description of other info.

I have check coding as well but not understand how product tax display in tax description. Same thing i want to do in my custom module.

Can any one please help me . Any hint, other way appriciated.

enter image description here

sss
  • 107
  • 2
  • 12
  • Do you try to display the `question` field in `Questions` tags? – Kenly Dec 15 '19 at 08:51
  • Yes with help of @api.onchange. ```@api.onchange('pages_id') def page_onchange_question(self): print('In on change') self.questions_survey = self.env['survey.question'].search([('question','=','questions_id.question')]) print('self.questions_survey',self.questions_survey)```but question not display in Questions tag – sss Dec 16 '19 at 07:04

1 Answers1

1

To get the same display as account.tax you will need a name field which is used to display records in x2many fields.

If you want to keep question field and used it to display questions in questions_survey, you have to use _rec_name in survey.question model.

class SurveyQuestion(models.Model):
    _name = 'survey.question'
    _description = ''
    _rec_name = 'question'

Or you can override name_get method to display a custom value.

Kenly
  • 24,317
  • 7
  • 44
  • 60
  • I have add above lines in onchange method that solve my problem. questions = self.pages_id.questions_id self.questions_survey = questions – sss Dec 17 '19 at 05:20