本文整理汇总了Python中trytond.pool.Pool.create_from方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.create_from方法的具体用法?Python Pool.create_from怎么用?Python Pool.create_from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.create_from方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_or_create_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_from [as 别名]
def find_or_create_using_magento_data(cls, product_data):
"""
Find or create a product template using magento data provided.
This method looks for an existing template using the magento ID From
data provided. If found, it returns the template found, else creates
a new one and returns that
:param product_data: Product Data From Magento
:returns: Browse record of product found/created
"""
Product = Pool().get("product.product")
Listing = Pool().get("product.product.channel_listing")
Channel = Pool().get("sale.channel")
channel = Channel.get_current_magento_channel()
products = Product.search([("code", "=", product_data["sku"])])
listings = Listing.search([("product.code", "=", product_data["sku"]), ("channel", "=", channel)])
if not products:
product = Product.create_from(channel, product_data)
else:
product, = products
if not listings:
Listing.create_from(channel, product_data)
return product
示例2: import_product
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_from [as 别名]
def import_product(self, sku, product_data=None):
"""
Import specific product for this magento channel
Downstream implementation for channel.import_product
"""
Product = Pool().get('product.product')
Listing = Pool().get('product.product.channel_listing')
if self.source != 'magento':
return super(Channel, self).import_product(sku, product_data)
if not sku:
# SKU is required can not continue
return
# Sanitize SKU
sku = sku.strip()
products = Product.search([
('code', '=', sku),
])
listings = Listing.search([
('product.code', '=', sku),
('channel', '=', self)
])
if not products or not listings:
# Either way we need the product data from magento. Make that
# dreaded API call.
with magento.Product(
self.magento_url, self.magento_api_user,
self.magento_api_key
) as product_api:
product_data = product_api.info(sku, identifierType="sku")
# XXX: sanitize product_data, sometimes product sku may
# contain trailing spaces
product_data['sku'] = product_data['sku'].strip()
# Create a product since there is no match for an existing
# product with the SKU.
if not products:
product = Product.create_from(self, product_data)
else:
product, = products
if not listings:
Listing.create_from(self, product_data)
else:
product = products[0]
return product
示例3: import_product
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_from [as 别名]
def import_product(self, sku):
"""
Import specific product for this amazon channel
Downstream implementation for channel.import_product
:param sku: Product Seller SKU from Amazon
:returns: Active record of Product Created
"""
Product = Pool().get('product.product')
Listing = Pool().get('product.product.channel_listing')
if self.source != 'amazon_mws':
return super(SaleChannel, self).import_product(sku)
# Check if there is a poduct with the seller SKU
# The SKU on the product could be different from that of the
# listing. Say older SKUs or Amazon assigned SKUs.
exisiting_listings = Listing.search([
('product_identifier', '=', sku),
('channel', '=', self),
])
if exisiting_listings:
return exisiting_listings[0].product
products = Product.search([('code', '=', sku)])
product_api = self.get_amazon_product_api()
if not products:
# Create a product since there is no match for an existing
# product with the SKU.
product_data = product_api.get_matching_product_for_id(
self.amazon_marketplace_id, 'SellerSKU', [sku]
).parsed
products = [Product.create_from(self, product_data)]
product, = products
listings = Listing.search([
('product', '=', product),
('channel', '=', self),
])
if not listings:
product_data = product_api.get_matching_product_for_id(
self.amazon_marketplace_id, 'SellerSKU', [sku]
).parsed
Listing(
product=product,
channel=self,
product_identifier=sku,
asin=product_data['Products']['Product']['Identifiers']["MarketplaceASIN"]["ASIN"]["value"], # noqa
).save()
return product
示例4: get_ps_main_product
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_from [as 别名]
def get_ps_main_product(cls, channel, product_data):
"""
Return prestashop main product
"""
Template = Pool().get('product.template')
Listing = Pool().get('product.product.channel_listing')
SiteLang = Pool().get('prestashop.site.lang')
# The name of a product can be in multiple languages
# If the name is in more than one language, create the record with
# name in first language (if a corresponding one exists on tryton) and
# updates the rest of the names in different languages by switching the
# language in context
# Same applies to description as well
name_in_langs = product_data.name.getchildren()
desc_in_langs = product_data.description.getchildren()
name_in_first_lang = name_in_langs.pop(0)
desc_in_first_lang = desc_in_langs[0]
site_lang = SiteLang.search_using_ps_id(
int(name_in_first_lang.get('id'))
)
variant_data = {
'code': unicode(product_data.reference.pyval),
'list_price': round_price(str(product_data.price)),
'cost_price': round_price(str(product_data.wholesale_price)),
}
# Product name and description can be in different first languages
# So create the variant with description only if the first language is
# same on both
if name_in_first_lang.get('id') == desc_in_first_lang.get('id'):
desc_in_first_lang = desc_in_langs.pop(0)
variant_data['description'] = desc_in_first_lang.pyval
# For a product in prestashop, create a template and a product in
# tryton.
with Transaction().set_context(language=site_lang.language.code):
template_values = cls.extract_product_values_from_ps_data(
channel, name_in_first_lang.pyval, product_data
)
template_values.update({
'products': [('create', [variant_data])],
})
template, = Template.create([template_values])
product, = template.products
# If there is only lang for name, control wont go to this loop
for name_in_lang in name_in_langs:
# Write the name in other languages
site_lang = SiteLang.search_using_ps_id(
int(name_in_lang.get('id'))
)
if not site_lang:
continue
with Transaction().set_context(language=site_lang.language.code):
Template.write([template], {
'name': name_in_lang.pyval,
})
# If there is only lang for description which has already been used,
# control wont go to this loop
for desc_in_lang in desc_in_langs:
# Write the description in other languages
site_lang = SiteLang.search_using_ps_id(
int(desc_in_lang.get('id'))
)
if not site_lang:
continue
with Transaction().set_context(language=site_lang.language.code):
cls.write(template.products, {
'description': desc_in_lang.pyval,
})
Listing.create_from(channel, product_data)
return product
示例5: import_product
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_from [as 别名]
def import_product(self, sku, product_data=None):
"""
Import specific product for this amazon channel
Downstream implementation for channel.import_product
:param sku: Product Seller SKU from Amazon
:returns: Active record of Product Created
"""
Product = Pool().get('product.product')
Listing = Pool().get('product.product.channel_listing')
if self.source != 'amazon_mws':
return super(SaleChannel, self).import_product(
sku, product_data
)
# Check if there is a poduct with the seller SKU.
# Products being sold as AFN and MFN will have same ASIN.
# ASIN is unique only in a marketplace, so search asin
# with channel.
exisiting_listings = Listing.search([
('asin', '=', product_data['ASIN']),
('channel', '=', self),
])
if exisiting_listings:
exisiting_listing, = exisiting_listings
# Update Listing to respect FBA Design
if product_data['FulfillmentChannel'] == 'AFN' and \
not exisiting_listing.fba_code:
exisiting_listing.fba_code = sku
exisiting_listing.save()
return exisiting_listing.product
products = Product.search([('code', '=', sku)])
product_api = self.get_amazon_product_api()
full_product_data = None
if not products:
# Create a product since there is no match for an existing
# product with the SKU.
full_product_data = full_product_data or \
product_api.get_matching_product_for_id(
self.amazon_marketplace_id, 'SellerSKU', [sku]
).parsed
products = [Product.create_from(self, full_product_data)]
product, = products
listings = Listing.search([
('product', '=', product),
('channel', '=', self),
])
if not listings:
full_product_data = full_product_data or \
product_api.get_matching_product_for_id(
self.amazon_marketplace_id, 'SellerSKU', [sku]
).parsed
Listing(
product=product,
channel=self,
product_identifier=sku,
fba_code=sku if product_data['FulfillmentChannel'] == 'AFN' else None, # noqa
asin=full_product_data['Products']['Product']['Identifiers']["MarketplaceASIN"]["ASIN"]["value"], # noqa
).save()
return product
示例6: import_product
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_from [as 别名]
def import_product(self, order_row_record):
"""
Import specific product for this prestashop channel
Downstream implementation for channel.import_product
"""
if self.source != 'prestashop':
return super(Channel, self).import_product(order_row_record)
Product = Pool().get('product.product')
Listing = Pool().get('product.product.channel_listing')
client = self.get_prestashop_client()
product_data = None
if order_row_record.product_reference.pyval:
sku = unicode(order_row_record.product_reference.pyval)
else:
# XXX: Sometime SKU may not come in order_line_data pull
# product_data and get sku
if order_row_record.product_attribute_id.pyval != 0:
product_data = product_data or client.combinations.get(
order_row_record.product_attribute_id.pyval
)
else:
product_data = product_data or client.products.get(
order_row_record.product_id.pyval
)
sku = product_data.reference.pyval
products = Product.search([
('code', '=', sku),
])
listings = Listing.search([
('product_identifier', '=', sku),
('channel', '=', self)
])
if not products or not listings:
# XXX: Fetch product data if it is not already being fetched
if not product_data and \
order_row_record.product_attribute_id.pyval != 0:
# Its a combination product
product_data = client.combinations.get(
order_row_record.product_attribute_id.pyval
)
elif not product_data:
# Its a main product
product_data = client.products.get(
order_row_record.product_id.pyval
)
if not products:
product = Product.create_from(self, product_data)
else:
product = products[0]
if not listings:
Listing.create_from(self, product_data)
else:
product = products[0]
return product