Skip to Content
Menu
This question has been flagged
1 Reply
1613 Views

hey i am adding a custom field in survey.page which will add all  the values of a specific custom field form survey.question. For this i am creating a new addon. Now the problem is that i need to add the field in survey.page so i have to inherit it but i also want the function to run every time so i need @api.depends too and for that i need to inherit survey.question too. But inheriting two of them together is not working as it requires _name and by keeping the same _name as _inherit still wont get overridden.  Kindly help. Here is the code

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

survey_score = fields.Integer(string='Total Score',compute='_compute_total_score',store=True)

@api.depends('total_marks')
@api.one
def _compute_total_score(self):
records = self.env["survey.question"].search([('page_id', '=', self.id)])
self.survey_score = sum(records.mapped('total_marks'))
Avatar
Discard
Best Answer

Hi,

I suppose the code you've shared belongs to your new addon module.
When you inherit two models, you need to define a new _name for your new model, for instance _name = "my.new.model"

Avatar
Discard
Author

Thanks for your reply but sir i am not not creating a new model, i am adding a compute field in survey.page.