本文整理汇总了Python中trytond.pool.Pool.find_or_create_for_party_using_magento_data方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.find_or_create_for_party_using_magento_data方法的具体用法?Python Pool.find_or_create_for_party_using_magento_data怎么用?Python Pool.find_or_create_for_party_using_magento_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.find_or_create_for_party_using_magento_data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_sale_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_for_party_using_magento_data [as 别名]
def get_sale_using_magento_data(cls, order_data):
"""
Return an active record of the sale from magento data
"""
Sale = Pool().get('sale.sale')
Party = Pool().get('party.party')
Address = Pool().get('party.address')
Currency = Pool().get('currency.currency')
Uom = Pool().get('product.uom')
Channel = Pool().get('sale.channel')
channel = Channel.get_current_magento_channel()
currency = Currency.search_using_magento_code(
order_data['order_currency_code']
)
if order_data['customer_id']:
party = Party.find_or_create_using_magento_id(
order_data['customer_id']
)
else:
firstname = order_data['customer_firstname'] or (
order_data['billing_address'] and
order_data['billing_address']['firstname']
)
lastname = order_data['customer_lastname'] or (
order_data['billing_address'] and
order_data['billing_address']['lastname']
)
party = Party.create_using_magento_data({
'firstname': firstname,
'lastname': lastname,
'email': order_data['customer_email'],
'customer_id': 0
})
party_invoice_address = None
if order_data['billing_address']:
party_invoice_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['billing_address']
)
party_shipping_address = None
if order_data['shipping_address']:
party_shipping_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['shipping_address']
)
unit, = Uom.search([('name', '=', 'Unit')])
tryton_action = channel.get_tryton_action(order_data['state'])
if not party_shipping_address:
# if there is no shipment address, this could be a digital
# delivery which won't need a shipment. No shipment_address is
# hence assumed as no shipment needed. So set the method as
# manual
shipment_method = 'manual'
else:
shipment_method = tryton_action['shipment_method']
return Sale(**{
'reference': channel.magento_order_prefix +
order_data['increment_id'],
'sale_date': order_data['created_at'].split()[0],
'party': party.id,
'currency': currency.id,
'invoice_address': party_invoice_address,
'shipment_address': party_shipping_address or party_invoice_address,
'magento_id': int(order_data['order_id']),
'channel': channel.id,
'invoice_method': tryton_action['invoice_method'],
'shipment_method': shipment_method,
'lines': [],
})
示例2: get_sale_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_for_party_using_magento_data [as 别名]
def get_sale_using_magento_data(cls, order_data):
"""
Return an active record of the sale from magento data
"""
Sale = Pool().get('sale.sale')
Party = Pool().get('party.party')
Address = Pool().get('party.address')
Currency = Pool().get('currency.currency')
Channel = Pool().get('sale.channel')
channel = Channel.get_current_magento_channel()
currency = Currency.search_using_magento_code(
order_data['order_currency_code']
)
if order_data['customer_id']:
party = Party.find_or_create_using_magento_id(
order_data['customer_id']
)
else:
firstname = order_data['customer_firstname'] or (
order_data['billing_address'] and
order_data['billing_address']['firstname']
) or (
order_data['shipping_address'] and
order_data['shipping_address']['firstname']
)
lastname = order_data['customer_lastname'] or (
order_data['billing_address'] and
order_data['billing_address']['lastname']
) or (
order_data['shipping_address'] and
order_data['shipping_address']['lastname']
)
party = Party.create_using_magento_data({
'firstname': firstname,
'lastname': lastname,
'email': order_data['customer_email'],
'customer_id': 0
})
party_invoice_address = None
if order_data['billing_address']:
party_invoice_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['billing_address']
)
party_shipping_address = None
if order_data['shipping_address']:
party_shipping_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['shipping_address']
)
tryton_action = channel.get_tryton_action(order_data['state'])
if not party_shipping_address:
# if there is no shipment address, this could be a digital
# delivery which won't need a shipment. No shipment_address is
# hence assumed as no shipment needed. So set the method as
# manual
shipment_method = 'manual'
else:
shipment_method = tryton_action['shipment_method']
timezone = pytz.timezone(channel.timezone)
sale_time = datetime.strptime(
order_data['created_at'], '%Y-%m-%d %H:%M:%S'
)
sale_time = timezone.localize(sale_time)
utc_sale_time = sale_time.astimezone(pytz.utc)
return Sale(**{
'reference': channel.magento_order_prefix +
order_data['increment_id'],
'sale_date': utc_sale_time.date(),
'party': party.id,
'currency': currency.id,
'invoice_address': party_invoice_address,
'shipment_address': party_shipping_address or party_invoice_address,
'magento_id': int(order_data['order_id']),
'channel': channel.id,
'invoice_method': tryton_action['invoice_method'],
'shipment_method': shipment_method,
'lines': [],
})
示例3: create_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_for_party_using_magento_data [as 别名]
def create_using_magento_data(cls, order_data):
"""
Create a sale from magento data
:param order_data: Order data from magento
:return: Active record of record created
"""
Party = Pool().get('party.party')
Address = Pool().get('party.address')
StoreView = Pool().get('magento.store.store_view')
Currency = Pool().get('currency.currency')
Uom = Pool().get('product.uom')
store_view = StoreView(Transaction().context.get('magento_store_view'))
instance = store_view.instance
currency = Currency.search_using_magento_code(
order_data['order_currency_code']
)
if order_data['customer_id']:
party = Party.find_or_create_using_magento_id(
order_data['customer_id']
)
else:
party = Party.create_using_magento_data({
'firstname': order_data['customer_firstname'],
'lastname': order_data['customer_lastname'],
'email': order_data['customer_email'],
'customer_id': 0
})
party_invoice_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['billing_address']
)
party_shipping_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['shipping_address']
)
unit, = Uom.search([('name', '=', 'Unit')])
tryton_state = MagentoOrderState.get_tryton_state(order_data['state'])
sale_data = {
'reference': instance.order_prefix + order_data['increment_id'],
'sale_date': order_data['created_at'].split()[0],
'party': party.id,
'currency': currency.id,
'invoice_address': party_invoice_address.id,
'shipment_address': party_shipping_address.id,
'magento_id': int(order_data['order_id']),
'magento_instance': instance.id,
'magento_store_view': store_view.id,
'invoice_method': tryton_state['invoice_method'],
'shipment_method': tryton_state['shipment_method'],
'lines': cls.get_item_line_data_using_magento_data(order_data)
}
if Decimal(order_data.get('shipping_amount')):
sale_data['lines'].append(
cls.get_shipping_line_data_using_magento_data(order_data)
)
if Decimal(order_data.get('discount_amount')):
sale_data['lines'].append(
cls.get_discount_line_data_using_magento_data(order_data)
)
sale, = cls.create([sale_data])
# Process sale now
sale.process_sale_using_magento_state(order_data['state'])
return sale
示例4: get_sale_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_for_party_using_magento_data [as 别名]
def get_sale_using_magento_data(cls, order_data):
"""
Return an active record of the sale from magento data
"""
Sale = Pool().get('sale.sale')
Party = Pool().get('party.party')
Address = Pool().get('party.address')
StoreView = Pool().get('magento.store.store_view')
Currency = Pool().get('currency.currency')
Uom = Pool().get('product.uom')
MagentoOrderState = Pool().get('magento.order_state')
store_view = StoreView(Transaction().context.get('magento_store_view'))
instance = store_view.instance
currency = Currency.search_using_magento_code(
order_data['order_currency_code']
)
if order_data['customer_id']:
party = Party.find_or_create_using_magento_id(
order_data['customer_id']
)
else:
party = Party.create_using_magento_data({
'firstname': order_data['customer_firstname'],
'lastname': order_data['customer_lastname'],
'email': order_data['customer_email'],
'customer_id': 0
})
party_invoice_address = None
if order_data['billing_address']:
party_invoice_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['billing_address']
)
party_shipping_address = None
if order_data['shipping_address']:
party_shipping_address = \
Address.find_or_create_for_party_using_magento_data(
party, order_data['shipping_address']
)
unit, = Uom.search([('name', '=', 'Unit')])
tryton_state = MagentoOrderState.get_tryton_state(order_data['state'])
if not party_shipping_address:
# if there is no shipment address, this could be a digital
# delivery which won't need a shipment. No shipment_address is
# hence assumed as no shipment needed. So set the method as
# manual
shipment_method = 'manual'
else:
shipment_method = tryton_state['shipment_method']
return Sale(**{
'reference': instance.order_prefix + order_data['increment_id'],
'sale_date': order_data['created_at'].split()[0],
'party': party.id,
'currency': currency.id,
'invoice_address': party_invoice_address,
'shipment_address': party_shipping_address or party_invoice_address,
'magento_id': int(order_data['order_id']),
'magento_instance': instance.id,
'magento_store_view': store_view.id,
'invoice_method': tryton_state['invoice_method'],
'shipment_method': shipment_method,
'lines': [],
})