def abc_confirm_invoice(self, lines, packages, data, params, res): """Confirm invoice. Split into its own function to not lock the invoice sequence.""" invoice = params.get('invoice') if invoice and invoice.state == 'draft': self.env.cr.commit() env = None try: # Ne cursor doesn't time out when requesting lock. # Could be bad I guess? Works for now. # TODO: Look into setting a more reasonable lock wait time. new_cr = Registry(self.env.cr.dbname).cursor() new_cr.autocommit(True) env = api.Environment(new_cr, self.env.uid, self.env.context) # Validate invoice invoice.signal_workflow('invoice_open') res['invoice']['name'] = invoice.number res['messages'].append(u"Created and confirmed invoice %s." % invoice.number) res['results']['invoice'] = 'confirmed' # Commit to unlock the invoice sequence env.cr.commit() except Exception as e: res['warnings'].append( (_(u"Failed to confirm invoice %s!") % (invoice and (invoice.number or invoice.name) or 'Unknown'), '%s\n\nTraceback:\n%s' % (e.message or 'Unknown Error', traceback.format_exc()))) finally: if env: env.cr.close()