Hi there and thank you in advance.
I try to implement a simple template system for analyses in my laboratory module. The goal is to define a function that creates ‘parameter’ records that are linked to my ‘analysis’ record via One2Many when a template is chosen.
The ‘Analysis’ model looks like this.
class Analysis(ModelSQL, ModelView):
'Analysis'
__name__ = 'toxicology.analysis'
name = fields.Char('Analysis Name')
analysis_template = fields.Many2One('toxicology.analysis_template', 'Analysis Template')
parameter = fields.One2Many('toxicology.parameter', 'analysis', 'Parameter')
The function that is supposed to work looks like this:
@fields.depends('analysis_template')
def on_change_with_parameter(self):
if self.analysis_type:
pool = Pool()
Parameter = pool.get('toxicology.parameter')
parameters = []
for parameter in self.analysis_template.parameter:
parameters.append({
'analysis': self.id,
'analyte': parameter.analyte,
'result': parameter.result,
'uom': parameter.uom and parameter.uom.id,
})
Parameter.create(parameters)
I do however end up with the following error message “Fault: cannot execute nextval() in a read-only transaction” which indicates that this is approach is not meant to write to the database.
Is there any way I can achieve this?