I'm working on a table that's inside a form. That table is filled automatically with the input of the first field that the user has to do. In the table there is only one column that the user has to enter data in and I made it possible for them to directly enter datas in the table instead of opening a new form. Those datas need to be checked using values hidden in the table, I just have to check if the value entered by the user respect some tolerances.
Now my problem is, for checking the values I need to know the ids of the values to be able to check with the rights tolerances but I can't get them if the user doesn't save the form.
So I have two questions : Is it possible to call a function just after saving ? I know I can override the "create" function but that's not what I want, I want a function to be called right after saving, thanks to that I would be able to know the ids and it would be possible to check the values. If that's not possible, my second question is : Is it possible to get the row number when the user enters its value in ? It would be useful to get the row number with api.onchange so I could simply loop into the rows until I find the right one and then use the datas that are there.
Thanks for your time
EDIT1 : Here the code I made to loop through the datas :
class ControlMeasure(models.Model):
"""
Modèle pour la mesure d'une pièce
"""
# Nom de la table
_name = 'spc.control.measure'
# Champs de la table
name = fields.Many2one(string='Name', related='control_point_id.measure_type_id', readonly=True)
value = fields.Float(string='Measured value')
validity = fields.Boolean(string='Validity', readonly=True)
nominal_value = fields.Float(string='Nominal value', related='control_point_id.nominal_value', readonly=True)
unit_id = fields.Many2one('product.uom', string='Unit', related='control_point_id.product_uom_id', readonly=True)
control_part_id = fields.Many2one('spc.control.part', string='Controled piece')
control_point_id = fields.Many2one('spc.control.point', string='Control point')
# Champs visuels
control_device_id = fields.Many2one('spc.control.device', string='Used device', related='control_point_id.control_device_id')
# Vérifie si la valeur mesurée est dans la tolérance
@api.multi
@api.onchange('value')
def is_valid(self):
# raise Exception('Appel réussi')
sql= """
SELECT p.nominal_value, p.inferior_tolerance, p.superior_tolerance FROM spc_control_point p
WHERE p.control_plan_id = %(ctrlid)s
"""
if self.control_part_id.control_plan_id == False:
raise Exception('False ' + str(self.control_part_id.control_plan_id))
else:
self.env.cr.execute(sql, {'ctrlid' : self.control_part_id.control_plan_id.id})
row = self.env.cr.fetchall()
for i in range(0, len(row)):
#raise Exception(str(self.value) + ' < ' + str(row[i][0]) + ' - ' + str(abs(row[i][1])) + ' or ' + str(self.value) + ' > ' + str(row[i][0]) + ' + ' + str(abs(row[i][2])))
if self.value < row[i][0] - abs(row[i][1]) or self.value > row[i][0] + abs(row[i][2]):
self.validity = False
else:
self.validity = True
Here the whole code works how I want except the loop that I don't know how to make it properly, I checked if the datas which are tested are the right ones and they are, the test itself works as I want, but as you see everytime I check all the rows and the end, only the last one count. That's why I came with the idea to get the row number where the user clicked but I don't know if it's possible to do it or even call a function after saving which would be easy because I would know the ids and I could check the datas after saving.