python - Is it possible to make a transaction in Odoo v10? If yes, How to do it? -
well, have many operations inside function. there loop has self.create()
function inside, , inside there still loop containing create
function , on... depends on each other id.
here sample of code (minified)
@api.multi def create_report(self): id_report = none reports = [resumereport(resume) resume in data] # tab containing many reports created repo = self.env["module1"].search([("date", "=", str(date))]) if repo: r in repo: id_report = r else: id_report = self.env["module1"].create({ 'name': name }) rep in report: self.env["module2"].create({ 'report_id': id_report.id, 'name': name })
so want put code under transaction. pretty big sql operation, when error occurs, want rollbacked , cancel operations (transaction!). otherwise commit it. don't know if there possibility in odoo 10 had not found doc transaciton.
could me please?
solved
@api.multi def create_report(self): self._cr.autocommit(false) try: id_report = none reports = [resumereport(resume) resume in data] # tab containing many reports created repo = self.env["module1"].search([("date", "=", str(date))]) if repo: r in repo: id_report = r else: id_report = self.env["module1"].create({ 'name': name }) rep in report: self.env["module2"].create({ 'report_id': id_report.id, 'name': name }) self._cr.commit() except: self._cr.rollback()
Comments
Post a Comment