本文整理汇总了Python中trytond.pool.Pool.get_current_magento_channel方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.get_current_magento_channel方法的具体用法?Python Pool.get_current_magento_channel怎么用?Python Pool.get_current_magento_channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.get_current_magento_channel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_or_create_using_magento_id
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def find_or_create_using_magento_id(
cls, magento_id, parent=None
):
"""
Find or Create Category Using Magento ID of Category
:param category_data: Category Data from Magento
:param parent: Browse record of Parent if present, else None
:returns: Active record of category found/created
"""
Channel = Pool().get('sale.channel')
category = cls.find_using_magento_id(magento_id)
if not category:
channel = Channel.get_current_magento_channel()
with magento.Category(
channel.magento_url, channel.magento_api_user,
channel.magento_api_key
) as category_api:
category_data = category_api.info(magento_id)
category = cls.create_using_magento_data(
category_data, parent
)
return category
示例2: find_or_create_using_magento_increment_id
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def find_or_create_using_magento_increment_id(cls, order_increment_id):
"""
This method tries to find the sale with the order increment ID
first and if not found it will fetch the info from magento and
create a new sale with the data from magento using
create_using_magento_data
:param order_increment_id: Order increment ID from magento
:type order_increment_id: string
:returns: Active record of sale order created/found
"""
Channel = Pool().get('sale.channel')
channel = Channel.get_current_magento_channel()
sale = cls.find_using_magento_increment_id(order_increment_id)
if not sale:
with magento.Order(
channel.magento_url, channel.magento_api_user,
channel.magento_api_key
) as order_api:
order_data = order_api.info(order_increment_id)
sale = cls.create_using_magento_data(order_data)
return sale
示例3: update_from_magento
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def update_from_magento(self):
"""
Update product using magento ID for that product
:returns: Active record of product updated
"""
Channel = Pool().get('sale.channel')
SaleChannelListing = Pool().get('product.product.channel_listing')
channel = Channel.get_current_magento_channel()
with magento.Product(
channel.magento_url, channel.magento_api_user,
channel.magento_api_key
) as product_api:
channel_listing, = SaleChannelListing.search([
('product', '=', self.id),
('channel', '=', channel.id),
])
product_data = product_api.info(
channel_listing.product_identifier,
identifierType="productID"
)
return self.update_from_magento_using_data(product_data)
示例4: find_or_create_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [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
示例5: export_to_magento
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def export_to_magento(self, category):
"""Export the current product to the magento category corresponding to
the given `category` under the current magento_channel in context
:param category: Active record of category to which the product has
to be exported
:return: Active record of product
"""
Channel = Pool().get('sale.channel')
SaleChannelListing = Pool().get('product.product.channel_listing')
channel = Channel.get_current_magento_channel()
if not category.magento_ids:
self.raise_user_error(
'invalid_category', (category.complete_name,)
)
listing = SaleChannelListing.search([
('channel', '=', channel.id),
('product', '=', self.id),
])
if listing:
self.raise_user_error(
'invalid_product', (self.name,)
)
if not self.products[0].code:
self.raise_user_error(
'missing_product_code', (self.name,)
)
with magento.Product(
channel.magento_url, channel.magento_api_user,
channel.magento_api_key
) as product_api:
# We create only simple products on magento with the default
# attribute set
# TODO: We have to call the method from core API extension
# because the method for catalog create from core API does not seem
# to work. This should ideally be from core API rather than
# extension
magento_id = product_api.call(
'ol_catalog_product.create', [
'simple',
int(Transaction().context['magento_attribute_set']),
self.products[0].code,
self.get_product_values_for_export_to_magento(
[category], [channel]
)
]
)
SaleChannelListing.create([{
'product_identifier': str(magento_id),
'channel': channel.id,
'product': self.id,
'magento_product_type': 'simple',
}])
return self
示例6: create_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def create_using_magento_data(cls, product_data):
"""
Create a new product with the `product_data` from magento.This method
also looks for the category of the product. If found, it uses that
category to assign the product to. If no category is found, it assigns
the product to `Unclassified Magento Product` category
:param product_data: Product Data from Magento
:returns: Browse record of product created
"""
Template = Pool().get('product.template')
Category = Pool().get('product.category')
Channel = Pool().get('sale.channel')
channel = Channel.get_current_magento_channel()
# Get only the first category from the list of categories
# If no category is found, put product under unclassified category
# which is created by default data
if product_data.get('categories'):
category = Category.find_or_create_using_magento_id(
int(product_data['categories'][0])
)
else:
categories = Category.search([
('name', '=', 'Unclassified Magento Products')
])
category = categories[0]
product_template_values = cls.extract_product_values_from_data(
product_data
)
product_template_values.update({
'products': [('create', [{
'description': product_data.get('description'),
'code': product_data['sku'],
'list_price': Decimal(
product_data.get('special_price') or
product_data.get('price') or
0.00
),
'cost_price': Decimal(product_data.get('cost') or 0.00),
'channel_listings': [('create', [{
'product_identifier': product_data['product_id'],
'channel': channel.id,
'magento_product_type': product_data['type'],
}])],
}])],
'category': category.id,
})
product_template, = Template.create([product_template_values])
return product_template.products[0]
示例7: get_price
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def get_price(self, name):
"""Calculate the price of the product for quantity set in record
:param name: Name of field
"""
Channel = Pool().get("sale.channel")
if not Transaction().context.get("current_channel"):
return 0
channel = Channel.get_current_magento_channel()
product = self.product_listing.product
return channel.price_list.compute(None, product, product.list_price, self.quantity, channel.default_uom)
示例8: do_export_
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def do_export_(self, action):
"""
Handles the transition
"""
Channel = Pool().get('sale.channel')
channel = Channel.get_current_magento_channel()
product_templates = channel.export_inventory_to_magento()
action['pyson_domain'] = PYSONEncoder().encode(
[('id', 'in', map(int, product_templates))])
return action, {}
示例9: update_from_magento
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def update_from_magento(self):
"""
Update product using magento ID for that product
:returns: Active record of product updated
"""
Channel = Pool().get("sale.channel")
SaleChannelListing = Pool().get("product.product.channel_listing")
channel = Channel.get_current_magento_channel()
with magento.Product(channel.magento_url, channel.magento_api_user, channel.magento_api_key) as product_api:
channel_listing, = SaleChannelListing.search([("product", "=", self.id), ("channel", "=", channel.id)])
product_data = product_api.info(channel_listing.product_identifier)
return self.update_from_magento_using_data(product_data)
示例10: create_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def create_using_magento_data(cls, order_data):
"""
Create a sale from magento data. If you wish to override the creation
process, it is recommended to subclass and manipulate the returned
unsaved active record from the `get_sale_using_magento_data` method.
:param order_data: Order data from magento
:return: Active record of record created
"""
ChannelException = Pool().get('channel.exception')
Channel = Pool().get('sale.channel')
channel = Channel.get_current_magento_channel()
state_data = channel.get_tryton_action(order_data['state'])
# Do not import if order is in cancelled or draft state
if state_data['action'] == 'do_not_import':
return
sale = cls.get_sale_using_magento_data(order_data)
sale.save()
sale.lines = list(sale.lines)
sale.add_lines_using_magento_data(order_data)
sale.save()
sale.create_payment_using_magento_data(order_data['payment'])
# Process sale now
tryton_action = channel.get_tryton_action(order_data['state'])
try:
sale.process_to_channel_state(order_data['state'])
except UserError, e:
# Expecting UserError will only come when sale order has
# channel exception.
# Just ignore the error and leave this order in draft state
# and let the user fix this manually.
ChannelException.create([{
'origin': '%s,%s' % (sale.__name__, sale.id),
'log': "Error occurred on transitioning to state %s.\nError "
"Message: %s" % (tryton_action['action'], e.message),
'channel': sale.channel.id,
}])
示例11: get_sale_line_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def get_sale_line_using_magento_data(self, item):
"""
Get sale.line data from magento data.
"""
SaleLine = Pool().get('sale.line')
ChannelException = Pool().get('channel.exception')
Channel = Pool().get('sale.channel')
Uom = Pool().get('product.uom')
channel = Channel.get_current_magento_channel()
sale_line = None
unit, = Uom.search([('name', '=', 'Unit')])
if not item['parent_item_id']:
# If its a top level product, create it
try:
product = channel.get_product(item['sku'])
except xmlrpclib.Fault, exception:
if exception.faultCode == 101:
# Case when product doesnot exist on magento
# create magento exception
ChannelException.create([{
'origin': '%s,%s' % (self.__name__, self.id),
'log': "Product #%s does not exist" %
item['product_id'],
'channel': self.channel.id
}])
product = None
else:
raise
sale_line = SaleLine(**{
'sale': self.id,
'magento_id': int(item['item_id']),
'description': item['name'] or product.name,
'unit_price': Decimal(item['price']),
'unit': unit.id,
'quantity': Decimal(item['qty_ordered']),
'note': item.get('comments'),
'product': product,
})
if item.get('tax_percent') and Decimal(item.get('tax_percent')):
taxes = channel.get_taxes(
Decimal(item['tax_percent']) / 100
)
sale_line.taxes = taxes
示例12: extract_product_values_from_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def extract_product_values_from_data(cls, product_data):
"""
Extract product values from the magento data, used for both
creation/updation of product. This method can be overwritten by
custom modules to store extra info to a product
:param: product_data
:returns: Dictionary of values
"""
Channel = Pool().get("sale.channel")
channel = Channel.get_current_magento_channel()
return {
"name": product_data.get("name") or ("SKU: " + product_data.get("sku")),
"default_uom": channel.default_uom.id,
"salable": True,
"sale_uom": channel.default_uom.id,
}
示例13: export_tracking_info_to_magento
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def export_tracking_info_to_magento(self):
"""
Export tracking info to magento for the specified shipment.
:param shipment: Browse record of shipment
:return: Shipment increment ID
"""
MagentoCarrier = Pool().get('magento.instance.carrier')
Channel = Pool().get('sale.channel')
Shipment = Pool().get('stock.shipment.out')
channel = Channel.get_current_magento_channel()
assert self.tracking_number
assert self.carrier
carriers = MagentoCarrier.search([
('channel', '=', channel.id),
('carrier', '=', self.carrier.id)
])
if not carriers:
# The carrier linked to this shipment is not found mapped to a
# magento carrier.
return
# Add tracking info to the shipment on magento
with magento.Shipment(
channel.magento_url, channel.magento_api_user,
channel.magento_api_key
) as shipment_api:
shipment_increment_id = shipment_api.addtrack(
self.magento_increment_id,
carriers[0].code,
carriers[0].title,
self.tracking_number,
)
Shipment.write([self], {
'is_tracking_exported_to_magento': True
})
return shipment_increment_id
示例14: extract_product_values_from_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def extract_product_values_from_data(cls, product_data):
"""
Extract product values from the magento data, used for both
creation/updation of product. This method can be overwritten by
custom modules to store extra info to a product
:param: product_data
:returns: Dictionary of values
"""
Channel = Pool().get('sale.channel')
channel = Channel.get_current_magento_channel()
return {
'name': product_data.get('name') or
('SKU: ' + product_data.get('sku')),
'default_uom': channel.default_uom.id,
'salable': True,
'sale_uom': channel.default_uom.id,
}
示例15: export_tracking_info_to_magento
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_current_magento_channel [as 别名]
def export_tracking_info_to_magento(self):
"""
Export tracking info to magento for the specified shipment.
:param shipment: Browse record of shipment
:return: Shipment increment ID
"""
MagentoCarrier = Pool().get('magento.instance.carrier')
Channel = Pool().get('sale.channel')
Shipment = Pool().get('stock.shipment.out')
channel = Channel.get_current_magento_channel()
assert self.tracking_number
assert self.carrier
try:
carrier, = MagentoCarrier.search([
('channel', '=', channel.id),
('carrier', '=', self.carrier.id)
])
except ValueError:
# No mapping carrier found use custom
code, title = 'custom', self.carrier.rec_name
else:
code, title = carrier.get_magento_mapping()
# Add tracking info to the shipment on magento
with magento.Shipment(
channel.magento_url, channel.magento_api_user,
channel.magento_api_key
) as shipment_api:
shipment_increment_id = shipment_api.addtrack(
self.magento_increment_id, code, title, self.tracking_number
)
Shipment.write([self], {
'is_tracking_exported_to_magento': True
})
return shipment_increment_id