'Call the scheduler to check the procurement order. This is intented to be done for all existing companies at
the same time, so we\'re running all the methods as SUPERUSER to avoid intercompany and access rights issues.
@param use_new_cursor: if set, use a dedicated cursor and auto-commit after processing each procurement.
This is appropriate for batch jobs only.
@return:  Dictionary of values'

@api.model
def run_scheduler(self, use_new_cursor=False, company_id=False):

    try:
        if use_new_cursor:
            cr = registry(self._cr.dbname).cursor()
            self = self.with_env(self.env(cr=cr))
        ProcurementSudo = self.env['procurement.order'].sudo()
        procurements = ProcurementSudo.search(([('state', '=', 'confirmed')] + ((company_id and [('company_id', '=', company_id)]) or [])))
        while procurements:
            procurements.run(autocommit=use_new_cursor)
            if use_new_cursor:
                self.env.cr.commit()
            procurements = ProcurementSudo.search(([('id', 'not    in', procurements.ids), ('state', '=', 'confirmed')] + ((company_id and [('company_id', '=', company_id)]) or [])))
        procurements = ProcurementSudo.search(([('state', '=', 'running')] + ((company_id and [('company_id', '=', company_id)]) or [])))
        while procurements:
            procurements.check(autocommit=use_new_cursor)
            if use_new_cursor:
                self.env.cr.commit()
            procurements = ProcurementSudo.search(([('id', 'not    in', procurements.ids), ('state', '=', 'running')] + ((company_id and [('company_id', '=', company_id)]) or [])))
    finally:
        if use_new_cursor:
            try:
                self.env.cr.close()
            except Exception:
                pass
    return {}
