def refresh_materialized_view_job(session, model_name, ids): model_instance = session.pool[model_name] handler = ConnectorSessionHandler(session.cr.dbname, session.uid, session.context) with handler.session() as session: result = model_instance.refresh_materialized_view(session.cr, session.uid, ids, context=session.context) return result
def job_purchase_schedule_procurements(session, model_name, ids, context=None): model_instance = session.pool[model_name] handler = ConnectorSessionHandler(session.cr.dbname, session.uid, session.context) with handler.session() as session: result = model_instance.purchase_schedule_procurements(session.cr, session.uid, ids, context=context) return result
def job_redistribute_procurements_in_lines(session, model_name, dict_procs_lines, context=None): model_instance = session.pool[model_name] handler = ConnectorSessionHandler(session.cr.dbname, session.uid, session.context) with handler.session() as session: result = model_instance.redistribute_procurements_in_lines( session.cr, session.uid, dict_procs_lines, context=context) return result
def job_create_draft_lines(session, model_name, dict_lines_to_create, context=None): model_instance = session.pool[model_name] handler = ConnectorSessionHandler(session.cr.dbname, session.uid, session.context) with handler.session() as session: result = model_instance.create_draft_lines(session.cr, session.uid, dict_lines_to_create, context=context) return result
class test_connector_session_handler(common.TransactionCase): """ Test ConnectorSessionHandler (without original cr and pool) """ def setUp(self): super(test_connector_session_handler, self).setUp() self.context = {'lang': 'fr_FR'} self.session_hdl = ConnectorSessionHandler( DB, ADMIN_USER_ID, context=self.context) def test_empty_session(self): """ Create a session without transaction """ self.assertEqual(self.session_hdl.db_name, DB) self.assertEqual(self.session_hdl.uid, ADMIN_USER_ID) self.assertEqual(self.session_hdl.context, self.context) def test_with_session(self): """ Create a session from the handler """ with self.session_hdl.session() as session: pool = openerp.modules.registry.RegistryManager.get(DB) self.assertIsNotNone(session.cr) self.assertEqual(session.pool, pool) self.assertEqual(session.context, self.session_hdl.context) def test_with_session_cr(self): """ Create a session from the handler and check if Cursor is usable. """ with self.session_hdl.session() as session: session.cr.execute("SELECT id FROM res_users WHERE login=%s", ('admin',)) self.assertEqual(session.cr.fetchone(), (ADMIN_USER_ID,)) def test_with_session_twice(self): """ Check if 2 sessions can be opened on the same session """ with self.session_hdl.session() as session: with self.session_hdl.session() as session2: self.assertNotEqual(session, session2)
def job_purchase_schedule(session, model_name, compute_all_products, compute_supplier_ids, compute_product_ids, jobify, context=None): model_instance = session.pool[model_name] handler = ConnectorSessionHandler(session.cr.dbname, session.uid, session.context) with handler.session() as session: result = model_instance.launch_purchase_schedule(session.cr, session.uid, compute_all_products, compute_supplier_ids, compute_product_ids, jobify, context=context) return result
def setUp(self): super(test_connector_session_handler, self).setUp() self.context = {'lang': 'fr_FR'} self.session_hdl = ConnectorSessionHandler(DB, ADMIN_USER_ID, context=self.context)
def job_update_supply_chain_controls(session, model_name, ids, context=None): model_instance = session.pool[model_name] handler = ConnectorSessionHandler(session.cr.dbname, session.uid, session.context) with handler.session() as session: result = model_instance.update_supply_chain_control(session.cr, session.uid, ids, context=context) return result
def setUp(self): super(test_connector_session_handler, self).setUp() self.context = {"lang": "fr_FR"} self.session_hdl = ConnectorSessionHandler(common.get_db_name(), ADMIN_USER_ID, context=self.context)
def setUp(self): super(test_connector_session_handler, self).setUp() self.context = {'lang': 'fr_FR'} self.session_hdl = ConnectorSessionHandler( DB, ADMIN_USER_ID, context=self.context)