本文整理汇总了Python中openerp.addons.connector.session.ConnectorSession类的典型用法代码示例。如果您正苦于以下问题:Python ConnectorSession类的具体用法?Python ConnectorSession怎么用?Python ConnectorSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConnectorSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_change_context_uninitialized
def test_change_context_uninitialized(self):
""" Change the context on a session not initialized with a context """
session = ConnectorSession(self.cr, self.uid)
test_key = "test_key"
with session.change_context({test_key: "value"}):
self.assertEqual(session.context.get("test_key"), "value")
self.assertNotIn(test_key, session.context)
示例2: test_connector_session
class test_connector_session(common.TransactionCase):
""" Test ConnectorSession """
def setUp(self):
super(test_connector_session, self).setUp()
self.context = {'lang': 'fr_FR'}
self.session = ConnectorSession(self.cr,
self.uid,
context=self.context)
def test_change_user(self):
"""
Change the user and check if it is reverted correctly at the end
"""
original_uid = self.session.uid
new_uid = 2
with self.session.change_user(new_uid):
self.assertEqual(self.session.uid, new_uid)
self.assertEqual(self.session.uid, original_uid)
def test_model_with_transaction(self):
"""
Create a session with a model name, we should be able to access
the model from a transaction
"""
res_users = self.registry('res.users').search_count(self.cr,
self.uid,
[])
sess_res_users_obj = self.session.pool.get('res.users')
sess_res_users = sess_res_users_obj.search_count(self.cr,
self.uid,
[])
self.assertEqual(sess_res_users, res_users)
def test_change_context(self):
"""
Change the context and check if it is reverted correctly at the end
"""
test_key = 'test_key'
self.assertNotIn(test_key, self.session.context)
with self.session.change_context({test_key: 'value'}):
self.assertIn(test_key, self.session.context)
self.assertNotIn(test_key, self.session.context)
# change the context on a session not initialized with a context
session = ConnectorSession(self.cr, self.uid)
with session.change_context({test_key: 'value'}):
self.assertIn(test_key, session.context)
self.assertNotIn(test_key, session.context)
示例3: import_product_product
def import_product_product(self):
try:
print ":::::::::::"
new_cr = sql_db.db_connect(self.env.cr.dbname).cursor()
uid, context = self.env.uid, self.env.context
with api.Environment.manage():
self.env = api.Environment(new_cr, uid, context)
self.test_connection()
session = ConnectorSession(self.env.cr, self.env.uid,
context=self.env.context)
self.import_products_from_date = datetime.now()
products = shopify.Product.find()
for product in products:
vals_product_tmpl = {}
dict_attr = product.__dict__['attributes']
if not session.search('product.template',
[('shopify_product_id',
'=', dict_attr['id'])]):
image_urls = [getattr(i, 'src') for i in product.images]
if len(image_urls) > 0:
photo = base64.encodestring(urllib2.urlopen(image_urls[0]).read())
vals_product_tmpl.update({'image_medium': photo})
custom_collection = shopify.CustomCollection.find(product_id=dict_attr['id'])
if custom_collection:
for categ in custom_collection:
product_cate_obj = session.search('product.category',
[('shopify_product_cate_id',
'=', categ.__dict__['attributes']['id'])])
if product_cate_obj:
vals_product_tmpl.update({'categ_id': product_cate_obj[0]})
vals_product_tmpl.update({'name': dict_attr['title'],
'type': 'consu',
'shopify_product_id': dict_attr['id'],
'description': dict_attr['body_html'],
'state': 'add'})
product_tid = session.create('product.template', vals_product_tmpl)
new_cr.commit()
variants = dict_attr['variants']
for variant in variants:
dict_variant = variant.__dict__['attributes']
u = session.create('product.product',
{'product_tmpl_id': product_tid,
'product_sfy_variant_id': dict_variant['id']})
new_cr.commit()
except:
raise Warning(_('Facing a problems while importing product!'))
finally:
self.env.cr.close()
示例4: test_change_context
def test_change_context(self):
"""
Change the context and check if it is reverted correctly at the end
"""
test_key = 'test_key'
self.assertNotIn(test_key, self.session.context)
with self.session.change_context({test_key: 'value'}):
self.assertIn(test_key, self.session.context)
self.assertNotIn(test_key, self.session.context)
# change the context on a session not initialized with a context
session = ConnectorSession(self.cr, self.uid)
with session.change_context({test_key: 'value'}):
self.assertIn(test_key, session.context)
self.assertNotIn(test_key, session.context)
示例5: test_from_env
def test_from_env(self):
""" ConnectorSession.from_env(env) """
session = ConnectorSession.from_env(self.env)
self.assertEqual(session.cr, self.env.cr)
self.assertEqual(session.uid, self.env.uid)
self.assertEqual(session.context, self.env.context)
self.assertEqual(session.pool, self.env.registry)
示例6: test_connector_session
class test_connector_session(common.TransactionCase):
""" Test ConnectorSession """
def setUp(self):
super(test_connector_session, self).setUp()
self.context = {'lang': 'fr_FR'}
self.session = ConnectorSession(self.cr,
self.uid,
context=self.context)
def test_change_user(self):
"""
Change the user and check if it is reverted correctly at the end
"""
original_uid = self.session.uid
new_uid = 2
with self.session.change_user(new_uid):
self.assertEqual(self.session.uid, new_uid)
self.assertEqual(self.session.uid, original_uid)
def test_model_with_transaction(self):
"""
Create a session with a model name, we should be able to access
the model from a transaction
"""
res_users = self.registry('res.users')
self.assertEqual(self.session.pool.get('res.users'), res_users)
示例7: button_import
def button_import(self):
"""
Analyze the imports in order to create the letter's lines
"""
if not self.manual_import:
# when letters are in a folder on NAS redefine method
for letters_import in self:
letters_import.state = 'pending'
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
ilh.import_letters_job.delay(
session, self._name, letters_import.id)
else:
letters_import._run_analyze()
return True
else:
# when letters selected by user, save them on NAS and call
# super method
for letters_import in self:
if letters_import.data and self.env.context.get(
'async_mode', True):
for attachment in letters_import.data:
self._save_imported_letter(attachment)
return super(ImportLettersHistory, self).button_import()
示例8: process_reconciliations
def process_reconciliations(self, mv_line_dicts):
""" Launch reconciliation in a job. """
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
process_reconciliations_job.delay(
session, self._name, mv_line_dicts)
else:
self._process_reconciliations(mv_line_dicts)
示例9: process_messages
def process_messages(self):
new_messages = self.filtered(lambda m: m.state in ('new', 'failure'))
new_messages.write({'state': 'pending', 'failure_reason': False})
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
process_messages_job.delay(session, self._name, self.ids)
else:
self._process_messages()
return True
示例10: _reset_open_invoices
def _reset_open_invoices(self):
""" Launch the task in asynchrnous job by default. """
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
reset_open_invoices_job.delay(
session, self._name, self.ids)
else:
self._reset_open_invoices_job()
return True
示例11: import_sale_orders
def import_sale_orders(self):
session = ConnectorSession.from_env(self.env)
for backend in self:
sale_order_import_batch.delay(
session,
'cdiscount.sale.order',
backend.id,
priority=1) # executed as soon as possible
return True
示例12: write
def write(self, cr, uid, ids, vals, context=None):
if not hasattr(ids, '__iter__'):
ids = [ids]
# magento_qty maybe 0, also need to be updated
if "magento_qty" in vals:
for record_id in ids:
session = ConnectorSession(cr, uid, context=context)
if session.context.get('connector_no_export'):
continue
if session.browse('magento.product.product', record_id).no_stock_sync:
continue
inventory_fields = list(set(vals).intersection(INVENTORY_FIELDS))
if inventory_fields:
export_product_inventory.delay(session, 'magento.product.product',
record_id, fields=inventory_fields,
priority=20)
return super(magento_product_product, self).write(cr, uid, ids, vals,
context=context)
示例13: clean_invoices
def clean_invoices(self):
""" By default, launch asynchronous job to perform the task.
Context value async_mode set to False can force to perform
the task immediately.
"""
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
clean_generate_job.delay(session, self._name, self.ids)
else:
self._clean_generate_invoices()
return True
示例14: setUp
def setUp(self):
super(test_job_storage_multi_company, self).setUp()
self.pool = openerp.modules.registry.RegistryManager.get(common.DB)
self.session = ConnectorSession(self.cr, self.uid, context={})
self.queue_job = self.registry('queue.job')
grp_connector_manager = self.ref("connector.group_connector_manager")
User = self.registry('res.users')
Company = self.registry('res.company')
Partner = self.registry('res.partner')
self.other_partner_id_a = Partner.create(
self.cr, self.uid,
{"name": "My Company a",
"is_company": True,
"email": "[email protected]",
})
self.other_company_id_a = Company.create(
self.cr, self.uid,
{"name": "My Company a",
"partner_id": self.other_partner_id_a,
"rml_header1": "My Company Tagline",
"currency_id": self.ref("base.EUR")
})
self.other_user_id_a = User.create(
self.cr, self.uid,
{"partner_id": self.other_partner_id_a,
"company_id": self.other_company_id_a,
"company_ids": [(4, self.other_company_id_a)],
"login": "my_login a",
"name": "my user",
"groups_id": [(4, grp_connector_manager)]
})
self.other_partner_id_b = Partner.create(
self.cr, self.uid,
{"name": "My Company b",
"is_company": True,
"email": "[email protected]",
})
self.other_company_id_b = Company.create(
self.cr, self.uid,
{"name": "My Company b",
"partner_id": self.other_partner_id_b,
"rml_header1": "My Company Tagline",
"currency_id": self.ref("base.EUR")
})
self.other_user_id_b = User.create(
self.cr, self.uid,
{"partner_id": self.other_partner_id_b,
"company_id": self.other_company_id_b,
"company_ids": [(4, self.other_company_id_b)],
"login": "my_login_b",
"name": "my user 1",
"groups_id": [(4, grp_connector_manager)]
})
示例15: clean_invoices
def clean_invoices(self, since_date=None, to_date=None, keep_lines=None):
""" By default, launch asynchronous job to perform the task.
Context value async_mode set to False can force to perform
the task immediately.
"""
if self.env.context.get('async_mode', True):
session = ConnectorSession.from_env(self.env)
clean_invoices_job.delay(
session, self._name, self.ids, since_date, to_date,
keep_lines)
else:
self._clean_invoices(since_date, to_date, keep_lines)