本文整理汇总了Python中openerp.addons.connector.session.ConnectorSession.write方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectorSession.write方法的具体用法?Python ConnectorSession.write怎么用?Python ConnectorSession.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openerp.addons.connector.session.ConnectorSession
的用法示例。
在下文中一共展示了ConnectorSession.write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_product_categories
# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import write [as 别名]
def import_product_categories(self):
try:
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.import_categories_from_date = datetime.now()
self.test_connection()
session = ConnectorSession(self.env.cr, self.env.uid,
context=self.env.context)
product_category_ids = session.search('product.category', [('name',
'=', 'Shopify Products')])
if not product_category_ids:
category_id = session.create('product.category',
{'name': 'Shopify Products'})
new_cr.commit()
shopify_collection = shopify.CustomCollection.find()
if shopify_collection:
for category in shopify_collection:
vals = {}
dict_category = category.__dict__['attributes']
if product_category_ids:
vals.update({'parent_id': product_category_ids[0]})
else:
vals.update({'parent_id': category_id})
vals.update({'name': dict_category['title'],
'description': dict_category['body_html'],
'write_uid': self.env.uid,
'shopify_product_cate_id': dict_category['id']})
product_cate_id = session.search('product.category',
[('shopify_product_cate_id',
'=', dict_category['id'])])
if not product_cate_id:
session.create('product.category', vals)
new_cr.commit()
else:
session.write('product.category', product_cate_id[0], vals)
new_cr.commit()
except:
raise Warning(_('Facing a problems while importing product categories!'))
finally:
self.env.cr.close()