I have a problem when using the l10n_es_aeat_sii_oca module. After a while I could locate the problem, and it is in this peace of code:
try:
...
except Exception as fault:
new_cr = Registry(self.env.cr.dbname).cursor()
env = api.Environment(new_cr, self.env.uid, self.env.context)
document = env[document._name].browse(document.id)
doc_vals.update({
"aeat_send_failed": True,
"aeat_send_error": repr(fault)[:60],
"sii_return": repr(fault),
"aeat_content_sent": json.dumps(inv_dict, indent=4),
})
document.write(doc_vals)
new_cr.commit()
new_cr.close()
raise ValidationError(fault) from fault
If the exception is raised, a new cursor is created and the document values are modified through this new DB cursor. I don't know the reason for creating a new DB cursor, I guess this is in order to fill in the document fields with the values and avoid them to be removed by the ROLLBACK of the ValidationError, is that the reason?
The problem is that when the workflow reaches the line new_cr.commit(), it stops and stays loading forever. Why?
If I modify the code and do this:
try:
...
except Exception as fault:
document = self.env[document._name].browse(document.id)
doc_vals.update({
"aeat_send_failed": True,
"aeat_send_error": repr(fault)[:60],
"sii_return": repr(fault),
"aeat_content_sent": json.dumps(inv_dict, indent=4),
})
document.write(doc_vals)
raise ValidationError(fault) from fault
Everything seems to work well, but this is not the solution I want, since I guess I would lose all the information because of the ROLLBACK. How can I find out why new_cr.commit() loads forever?