Reputation: 1168
My below method for value insertion in one2many field works with the onchange method and the compute method with depends decorator. But my requirement not full-fill with depends decorator. My method should work with view load. At present method calls, and I tested it with print on the terminal but still value not updated in o2many field.
survey_user_input = fields.One2many('customer.survey', 'partner_id', compute='user_survey_output')
@api.one
def user_survey_output(self):
print('TESSSSSSSSSSSSSSSSSSSS')
Survey_user_input = self.env['survey.user_input']
s_list = []
value = {}
for val in self:
User_input = Survey_user_input.search(['|', ('partner_id', '=', val.id), ('email', '=', val.email)])
for rec in User_input:
data = {'partner_id': val.id,
'user_input_id': rec.id,
'survey_id': rec.survey_id.id,
'date_create': rec.date_create,
'deadline': rec.deadline,
'type': rec.type,
'state': rec.state,
}
s_list.append((0, 0, data))
value.update(survey_user_input=s_list)
print('LLLLLLLLLLLLLLL', value)
return {'value': value}
Thanks in advance.
Upvotes: 1
Views: 922
Reputation: 26688
survey_user_input
is a computed field, so it must assign the computed value to the field.
If it uses the values of other fields, it should specify those fields using depends()
(The email
field is used in the search
method).
@api.depends('email')
def user_survey_output(self):
Survey_user_input = self.env['survey.user_input']
for val in self:
s_list = []
# Loop body used to fill "s_list"
val.survey_user_input = s_list
Upvotes: 2