def test_60_reversed(self): records = self.partners self.assertGreater(len(records), 1) # check order self.assertEqual(list(reversed(records)), list(reversed(list(records)))) first = next(iter(records)) last = next(reversed(records)) self.assertEqual(first, records[0]) self.assertEqual(last, records[-1]) # check prefetching prefetch_ids = records.ids reversed_ids = [record.id for record in reversed(records)] self.assertEqual(list(first._prefetch_ids), prefetch_ids) self.assertEqual(list(last._prefetch_ids), reversed_ids) self.assertEqual(list(reversed(first._prefetch_ids)), reversed_ids) self.assertEqual(list(reversed(last._prefetch_ids)), prefetch_ids) # check prefetching across many2one field prefetch_ids = records.state_id.ids reversed_ids = list( unique(record.state_id.id for record in reversed(records) if record.state_id)) self.assertEqual(list(first.state_id._prefetch_ids), prefetch_ids) self.assertEqual(list(last.state_id._prefetch_ids), reversed_ids) self.assertEqual(list(reversed(first.state_id._prefetch_ids)), reversed_ids) self.assertEqual(list(reversed(last.state_id._prefetch_ids)), prefetch_ids) # check prefetching across x2many field prefetch_ids = records.child_ids.ids reversed_ids = list( unique(child.id for record in reversed(records) for child in record.child_ids)) self.assertEqual(list(first.child_ids._prefetch_ids), prefetch_ids) self.assertEqual(list(last.child_ids._prefetch_ids), reversed_ids) self.assertEqual(list(reversed(first.child_ids._prefetch_ids)), reversed_ids) self.assertEqual(list(reversed(last.child_ids._prefetch_ids)), prefetch_ids)
def test_scripts(args): """ Tries to launch standalone scripts tagged with @post_testing """ # load the registry once for script discovery registry = odoo.registry(args.database) for module_name in registry._init_modules: # import tests for loaded modules odoo.tests.loader.get_test_modules(module_name) # fetch and filter scripts to test funcs = list( unique(func for tag in args.standalone.split(',') for func in standalone_tests[tag])) start_time = time.time() for index, func in enumerate(funcs, start=1): with odoo.api.Environment.manage(): with odoo.registry(args.database).cursor() as cr: env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) _logger.info("Executing standalone script: %s (%d / %d)", func.__name__, index, len(funcs)) try: func(env) except Exception: _logger.error("Standalone script %s failed", func.__name__, exc_info=True) _logger.info("%d standalone scripts executed in %.2fs" % (len(funcs), time.time() - start_time))
def _trigger_list(self, at_list): """ Implementation of :meth:`~._trigger`. :param list[datetime.datetime] at_list: Execute the cron later, at precise moments in time. """ if not at_list: return self.ensure_one() now = datetime.utcnow().replace(second=0, microsecond=0) # compress the list to insert at most one trigger per minute at_list = list(unique(at.replace(second=0, microsecond=0) for at in at_list)) self.env['ir.cron.trigger'].sudo().create([ {'cron_id': self.id, 'call_at': at} for at in at_list ]) if _logger.isEnabledFor(logging.DEBUG): ats = ', '.join(map(str, at_list)) _logger.debug("will execute '%s' at %s", self.sudo().name, ats) if min(at_list) <= now: self._cr.postcommit.add(self._notifydb)
def action_view_pos_orders(self): self.ensure_one() pos_order_ids = list(unique(r['order_id'] for r in\ self.env['pos.order.line'].search_read([('reward_id', 'in', self.reward_ids.ids)], fields=['order_id']))) return { 'name': _("PoS Orders"), 'view_mode': 'tree,form', 'res_model': 'pos.order', 'type': 'ir.actions.act_window', 'domain': [('id', 'in', pos_order_ids)], 'context': dict(self._context, create=False), }