[IMP] survey: little optimization for user_input_line creation/update
Before: The method _get_mark called Model.exists() just after calling Model.browse This process makes 2 calls to database to do almost the same thing Now: Removed the method _get_mark and directly call Model.browse FP feedback Task 2066646
This commit is contained in:
committed by
Thibault Delavallée
parent
f1b9ce5462
commit
247bc4aaa1
@@ -253,23 +253,18 @@ class SurveyUserInputLine(models.Model):
|
||||
if not fields_type.get(uil.answer_type, True):
|
||||
raise ValidationError(_('The answer must be in the right type'))
|
||||
|
||||
def _get_mark(self, value_suggested):
|
||||
label = self.env['survey.label'].browse(int(value_suggested))
|
||||
mark = label.answer_score if label.exists() else 0.0
|
||||
return mark
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
for vals in vals_list:
|
||||
value_suggested = vals.get('value_suggested')
|
||||
if value_suggested:
|
||||
vals.update({'answer_score': self._get_mark(value_suggested)})
|
||||
vals.update({'answer_score': self.env['survey.label'].browse(int(value_suggested)).answer_score})
|
||||
return super(SurveyUserInputLine, self).create(vals_list)
|
||||
|
||||
def write(self, vals):
|
||||
value_suggested = vals.get('value_suggested')
|
||||
if value_suggested:
|
||||
vals.update({'answer_score': self._get_mark(value_suggested)})
|
||||
vals.update({'answer_score': self.env['survey.label'].browse(int(value_suggested)).answer_score})
|
||||
return super(SurveyUserInputLine, self).write(vals)
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user