0
votes

When click on save button gives me odoo server error shown in screenshot and at backed following error display.

2019-12-14 12:36:25,426 4067 ERROR work_span odoo.sql_db: bad query: INSERT INTO "survey_page" ("id", "create_uid", "create_date", "write_uid", "write_date", "create_id_survey", "sequence", "title") VALUES (nextval('survey_page_id_seq'), 1, (now() at time zone 'UTC'), 1, (now() at time zone 'UTC'), 1, 10, 'test1') RETURNING id ERROR: null value in column "survey_id" violates not-null constraint DETAIL: Failing row contains (5, 1, test1, null, 10, null, 1, 2019-12-14 12:36:25.421912, 1, 2019-12-14 12:36:25.421912).

enter image description here

UPDATE Description: I am trying to display survey title, survey page, survey question in one form for that I have create my custom model. Custom model inherit survey.survey,survey.page,survey.question and also contain two one2many field.

Following is my code:

py file

class SurveyCreate(models.Model):

    _name = 'create.survey'

    _inherit = ['survey.survey','survey.page','survey.question']

    pages_id = fields.One2many('survey.page','create_id_survey','Pages')
    questions_survey = fields.One2many('survey.question','create_id_survey','Questions')
    survey_id = fields.Many2one('survey.survey', string='Survey',required=False) 
    page_id = fields.Many2one('survey.page', string='Survey page', required=False)

Xml file

            <sheet>

                <group>
                    <field name="title"/>
                </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" context="{'tree_view_ref':'survey_inherit.survey_create_form','default_page_id':active_id}"/>                        
                        </tree>
                    </field>
                </group>
                <group> 
                    <field name="questions_survey" mode='tree'>         
                        <tree name="questions_tree" editable="bottom">
                            <control>
                                <create string="Add Question"/>
                            </control>
                            <field name="question"/>
                            <field name="type"/>
                        </tree>                 
                    </field>
                </group>

                <group>
                    <group>
                        <field name="question"/>
                   </group>

                   <group>
                        <field name="type"/>
                   </group>
                </group>            


            </sheet>
        </form>

as per @Atul suggestion make changes but same error occur Following screenshot for 1.Form View 2.Error after click on save button

enter image description here

enter image description here

2
The error is clear. You are not specifying the value of survey_id, and the column cannot be NULL.Martin
Please add the definition of pages (one2many field) and how you fill it with values.Kenly

2 Answers

1
votes

It seems you have created a custom survey action model. and trying to use survey.page as one2many or many2many field on it.

when you add the page and try to save the record it is preventing because in default survey module survey_id field is mandatory. you can have two options to resolve this issue.

  1. inherit the survey.page and Overwrite the field and make it non-required.

    survey_id = fields.Many2one('survey.survey', string='Survey', required=False)

  2. Populate the value of survey_id by default (you can use ir.config_parameter)

hope this helps!

Edit: 19th December 2019

You do not need to inherit the create.survey from any model if you do not required to change anything on the default survey mode.

class SurveyCreate(models.Model):
    _name = 'create.survey'
    _inherit = ['survey.survey','survey.page','survey.question']

Remove the below line from your class.

_inherit = ['survey.survey','survey.page','survey.question']

Instead create a new class for survey.page and overwrite the field like

class SurveyPage(models.Model):
    _name = 'survey.page'

    survey_id = fields.Many2one('survey.survey', string='Survey', required=False)
0
votes

Looks like you've created a menu/action for a model which is only used in One2many fields, so the form view of that model is not showing the relation's inverse field (survey_id). In One2many fields there is no need to show this field, because Odoo is doing some black magic for them.

So the best way IMO is to create your own form view for that model. You also have to specify this form view as default on your menu action.