'Call the scheduler in order to check the running procurements (super method), to check the minimum stock rules
and the availability of moves. This function is intended to be run for all the companies at the same time, so
we run functions as SUPERUSER to avoid intercompanies and access rights issues.'

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

    super(ProcurementOrder, self).run_scheduler(use_new_cursor=use_new_cursor, company_id=company_id)
    try:
        if use_new_cursor:
            cr = registry(self._cr.dbname).cursor()
            self = self.with_env(self.env(cr=cr))
        self.sudo()._procure_orderpoint_confirm(use_new_cursor=use_new_cursor, company_id=company_id)
        confirmed_moves = self.env['stock.move'].search([('state', '=', 'confirmed')], limit=None, order='priority    desc,    date_expected    asc')
        for x in xrange(0, len(confirmed_moves.ids), 100):
            self.env['stock.move'].browse(confirmed_moves.ids[x:(x + 100)]).action_assign()
            if use_new_cursor:
                self._cr.commit()
        if use_new_cursor:
            self._cr.commit()
    finally:
        if use_new_cursor:
            try:
                self._cr.close()
            except Exception:
                pass
    return {}
