Skip to Content
Menu
This question has been flagged
2 Replies
1696 Views

Hello. I have a survey and I want to fetch the answers once customer has filled it and display them inside my custom view.

Odoo version: 16


Within my custom model I have the following code to link it with the survey answers:

answer_ids = fields.One2many('survey.user_input', 'order_id', string="Survey answers")
answers= fields.One2many(
related="answer_ids.user_input_line_ids",
string="Answers",
readonly=True
)


And here is my extension of survey.user_input model:

class CustomSurveyInput(models.Model):
_inherit = ['survey.user_input']

order_id = fields.Many2one('crm.lead', string="Order")


And finally here is the part of the view that tries to show those answers inside a notebook page:

page string="Answers"
​field
name="answers"
​tree
​field
name="question_id"/
​field
name="display_name"/
​/tree
​/field
/page



The notebook tab correctly appears with the Question and Display Name fields but the answers of the survey which I have filled do not populate it and I do not know why. I've looked for a tutorial in Youtube but couldn't find one for this problem. Additionally I have asked ChatGPT for help but it is not getting me further. Any help appreciated and sorry if this is a noob question, I have only recently started learning Odoo.

Avatar
Discard

The thing it's that without a complete scenario and code I will be guessing, but just something to ask... Your custom model it's `crm.lead`? it needs to be because your field `order_id` is a many2one to ``crm.lead

Author

Yes Axel the custom model representing an order inherits the 'crm.lead' and builds upon it.

The idea is that I have extended 'crm.lead' with some custom fields, regex checks etc., and I have also customer model which is an extension of 'res.partner'. I have created a survey which is sent to the customer and once the fill it out I could see their answers inside custom view where I have most of the information from the extended 'crm.lead' that I want to have readily available. I chose to leave most of the code out since I have tested it works and thought it would make it even more difficult to identify the problem (also some of the code is in Finnish so I would have to translate it).

The code doesn't show any errors nor does it crash so I am thinking the problem is due to the logic, but I just can't figure out why the answers to the survey don't show inside the notebook page "Answers".

Best Answer

Hello Turi, I think you're looking for this:


survey_id = fields.Many2one('survey.user_input', string="Survey")

answers= fields.One2many(related="survey_id.user_input_line_ids", string="Answers") 


(PS: related fields are bydefault readonly)


I hope this will help you with your question

Avatar
Discard
Best Answer

I think you are missing some logic around your own solution.

It's not the same to have a custom model lets say custom.module​ that inherit from crm.lead​ using a field 

class CustomModule(models.Model)
    _name = 'custom.module'
    _inherits = {'crm.lead': 'order_id'}

Than extending the model to add some fields:

class CrmLead(models.Model)
    _inherit = 'crm.lead'

The issue I think could be that you aren't pointing to the same order_id value of the crm.lead model because it's not the same that you create a lead using an extension inheritance automatically when you create the record of custom.module than selecting that same lead that was used for the survey answers and will give you properly the values and records you are looking for

Avatar
Discard