本文整理汇总了Python中trytond.pool.Pool.find_or_create_using_ps_data方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.find_or_create_using_ps_data方法的具体用法?Python Pool.find_or_create_using_ps_data怎么用?Python Pool.find_or_create_using_ps_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.find_or_create_using_ps_data方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_using_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_ps_data [as 别名]
def create_using_ps_data(cls, combination_record):
"""Create a variant from the product record sent by prestashop client
First look if this product already exists. If yes, it returns the same.
Else create a new one. This search process is delegated to
`get_product_using_ps_data`.
:param product_record: Objectified XML record sent by pystashop
:returns: Active record of created product
"""
Template = Pool().get('product.template')
SaleChannel = Pool().get('sale.channel')
channel = SaleChannel(Transaction().context['current_channel'])
channel.validate_prestashop_channel()
client = channel.get_prestashop_client()
template = Template.find_or_create_using_ps_data(
client.products.get(combination_record.id_product.pyval)
)
product, = cls.create([{
'template': template.id,
'code': combination_record.reference.pyval or None,
'prestashop_combination_ids': [('create', [{
'prestashop_combination_id': combination_record.id.pyval,
}])]
}])
return product
示例2: import_orders
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_ps_data [as 别名]
def import_orders(self):
"""
Downstream implementation of channel.import_orders
Import orders for the current prestashop channel
Import only those orders which are updated after the
`last prestashop order import time` as set in the prestashop channel
:returns: The list of active records of sales imported
"""
if self.source != 'prestashop':
return super(Channel, self).import_orders()
Sale = Pool().get('sale.sale')
self.validate_prestashop_channel()
if not self.prestashop_order_states:
self.raise_user_error('order_states_not_imported')
# Localize to the site timezone
utc_time_now = datetime.utcnow()
site_tz = pytz.timezone(self.prestashop_timezone)
time_now = site_tz.normalize(pytz.utc.localize(utc_time_now))
client = self.get_prestashop_client()
with Transaction().set_context(current_channel=self.id):
if self.last_order_import_time:
# In tryton all time stored is in UTC
# Convert the last import time to timezone of the site
last_order_import_time = site_tz.normalize(
pytz.utc.localize(self.last_order_import_time)
)
orders_to_import = client.orders.get_list(
filters={
'date_upd': '{0},{1}'.format(
last_order_import_time.strftime(
'%Y-%m-%d %H:%M:%S'
),
time_now.strftime('%Y-%m-%d %H:%M:%S')
)
}, date=1, display='full'
)
else:
# FIXME: This wont scale if there are thousands of orders
orders_to_import = client.orders.get_list(display='full')
self.write([self], {
'last_order_import_time': utc_time_now
})
sales_imported = []
for order in orders_to_import:
# TODO: Use import_order here
sales_imported.append(Sale.find_or_create_using_ps_data(order))
return sales_imported
示例3: import_product
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_ps_data [as 别名]
def import_product(self, order_row_record):
"""
Import specific product for this prestashop channel
Downstream implementation for channel.import_product
"""
Product = Pool().get('product.product')
Template = Pool().get('product.template')
# TODO: Products need to be searched using SKU instead of
# prestashop order ID
if self.source != 'prestashop':
return super(Channel, self).import_product(order_row_record)
client = self.get_prestashop_client()
# If the product sold is a variant, then get product from
# product.product
if order_row_record.product_attribute_id.pyval != 0:
product = Product.get_product_using_ps_id(
order_row_record.product_attribute_id.pyval
) or Product.find_or_create_using_ps_data(
client.combinations.get(
order_row_record.product_attribute_id.pyval
)
)
else:
template = Template.get_template_using_ps_id(
order_row_record.product_id.pyval
) or Template.find_or_create_using_ps_data(
client.products.get(
order_row_record.product_id.pyval
)
)
product = template.products[0]
return product
示例4: create_using_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_ps_data [as 别名]
def create_using_ps_data(cls, order_record):
"""Create an order from the order record sent by prestashop client
:param order_record: Objectified XML record sent by pystashop
:returns: Active record of created sale
"""
Party = Pool().get('party.party')
Address = Pool().get('party.address')
Line = Pool().get('sale.line')
SaleChannel = Pool().get('sale.channel')
Currency = Pool().get('currency.currency')
SiteOrderState = Pool().get('prestashop.site.order_state')
ChannelException = Pool().get('channel.exception')
channel = SaleChannel(Transaction().context['current_channel'])
channel.validate_prestashop_channel()
client = channel.get_prestashop_client()
if not client:
cls.raise_user_error('prestashop_site_not_found')
party = Party.find_or_create_using_ps_data(
client.customers.get(order_record.id_customer.pyval)
)
# Get the sale date and convert the time to UTC from the application
# timezone set on channel
sale_time = datetime.strptime(
order_record.date_add.pyval, '%Y-%m-%d %H:%M:%S'
)
channel_tz = pytz.timezone(channel.prestashop_timezone)
sale_time_utc = pytz.utc.normalize(channel_tz.localize(sale_time))
inv_address = Address.find_or_create_for_party_using_ps_data(
party,
client.addresses.get(order_record.id_address_invoice.pyval),
)
ship_address = Address.find_or_create_for_party_using_ps_data(
party,
client.addresses.get(order_record.id_address_delivery.pyval),
)
sale_data = {
'reference': str(order_record.id.pyval),
'description': order_record.reference.pyval,
'sale_date': sale_time_utc.date(),
'party': party.id,
'invoice_address': inv_address.id,
'shipment_address': ship_address.id,
'prestashop_id': order_record.id.pyval,
'currency': Currency.get_using_ps_id(
order_record.id_currency.pyval
).id,
}
ps_order_state = SiteOrderState.search_using_ps_id(
order_record.current_state.pyval
)
sale_data['invoice_method'] = ps_order_state.invoice_method
sale_data['shipment_method'] = ps_order_state.shipment_method
sale_data['channel'] = channel.id
lines_data = []
for order_line in order_record.associations.order_rows.iterchildren():
lines_data.append(
Line.get_line_data_using_ps_data(order_line)
)
if Decimal(str(order_record.total_shipping)):
lines_data.append(
Line.get_shipping_line_data_using_ps_data(order_record)
)
if Decimal(str(order_record.total_discounts)):
lines_data.append(
Line.get_discount_line_data_using_ps_data(order_record)
)
sale_data['lines'] = [('create', lines_data)]
sale, = cls.create([sale_data])
# Create channel exception if order total does not match
if sale.total_amount != Decimal(
str(order_record.total_paid_tax_excl)
):
ChannelException.create([{
'origin': '%s,%s' % (sale.__name__, sale.id),
'log': 'Order total does not match.',
'channel': sale.channel.id,
}])
return sale
sale.process_state_using_ps_data(ps_order_state)
return sale
示例5: create_using_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_ps_data [as 别名]
def create_using_ps_data(cls, order_record):
"""Create an order from the order record sent by prestashop client
:param order_record: Objectified XML record sent by pystashop
:returns: Active record of created sale
"""
Party = Pool().get("party.party")
Address = Pool().get("party.address")
Line = Pool().get("sale.line")
SaleChannel = Pool().get("sale.channel")
Currency = Pool().get("currency.currency")
ChannelException = Pool().get("channel.exception")
channel = SaleChannel(Transaction().context["current_channel"])
channel.validate_prestashop_channel()
client = channel.get_prestashop_client()
if not client:
cls.raise_user_error("prestashop_site_not_found")
party = Party.find_or_create_using_ps_data(client.customers.get(order_record.id_customer.pyval))
# Get the sale date and convert the time to UTC from the application
# timezone set on channel
sale_time = datetime.strptime(order_record.date_add.pyval, "%Y-%m-%d %H:%M:%S")
channel_tz = pytz.timezone(channel.prestashop_timezone)
sale_time_utc = pytz.utc.normalize(channel_tz.localize(sale_time))
inv_address = Address.find_or_create_for_party_using_ps_data(
party, client.addresses.get(order_record.id_address_invoice.pyval)
)
ship_address = Address.find_or_create_for_party_using_ps_data(
party, client.addresses.get(order_record.id_address_delivery.pyval)
)
sale_data = {
"reference": str(order_record.id.pyval),
"channel_identifier": str(order_record.id.pyval),
"description": order_record.reference.pyval,
"sale_date": sale_time_utc.date(),
"party": party.id,
"invoice_address": inv_address.id,
"shipment_address": ship_address.id,
"currency": Currency.get_using_ps_id(order_record.id_currency.pyval).id,
}
tryton_action = channel.get_tryton_action(unicode(order_record.current_state.pyval)) # current state is int
sale_data["invoice_method"] = tryton_action["invoice_method"]
sale_data["shipment_method"] = tryton_action["shipment_method"]
sale_data["channel"] = channel.id
lines_data = []
for order_line in order_record.associations.order_rows.iterchildren():
lines_data.append(Line.get_line_data_using_ps_data(order_line))
if Decimal(str(order_record.total_shipping)):
lines_data.append(Line.get_shipping_line_data_using_ps_data(order_record))
if Decimal(str(order_record.total_discounts)):
lines_data.append(Line.get_discount_line_data_using_ps_data(order_record))
sale_data["lines"] = [("create", lines_data)]
sale, = cls.create([sale_data])
# Create channel exception if order total does not match
if sale.total_amount != Decimal(str(order_record.total_paid_tax_excl)):
ChannelException.create(
[
{
"origin": "%s,%s" % (sale.__name__, sale.id),
"log": "Order total does not match.",
"channel": sale.channel.id,
}
]
)
return sale
sale.process_to_channel_state(unicode(order_record.current_state.pyval)) # Current state is int
return sale