本文整理汇总了Python中trytond.pool.Pool.search_using_magento_code方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.search_using_magento_code方法的具体用法?Python Pool.search_using_magento_code怎么用?Python Pool.search_using_magento_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.search_using_magento_code方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_for_party_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_magento_code [as 别名]
def create_for_party_using_magento_data(cls, party, address_data):
"""
Create address from the address record given and link it to the
party.
:param party: Party active record
:param address_data: Dictionary of address data from magento
:return: Active record of created address
"""
Country = Pool().get('country.country')
Subdivision = Pool().get('country.subdivision')
ContactMechanism = Pool().get('party.contact_mechanism')
country = None
subdivision = None
if address_data['country_id']:
country = Country.search_using_magento_code(
address_data['country_id']
)
if address_data['region']:
subdivision = Subdivision.search_using_magento_region(
address_data['region'], country
)
address, = cls.create([{
'party': party.id,
'name': ' '.join([
address_data['firstname'], address_data['lastname']
]),
'street': address_data['street'],
'zip': address_data['postcode'],
'city': address_data['city'],
'country': country and country.id or None,
'subdivision': subdivision and subdivision.id or None,
}])
# Create phone as contact mechanism
if address_data.get('telephone') and not ContactMechanism.search([
('party', '=', party.id),
('type', 'in', ['phone', 'mobile']),
('value', '=', address_data['telephone']),
]):
ContactMechanism.create([{
'party': party.id,
'type': 'phone',
'value': address_data['telephone'],
}])
return address
示例2: create_for_party_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_magento_code [as 别名]
def create_for_party_using_magento_data(cls, party, address_data):
"""
Create address from the address record given and link it to the
party.
:param party: Party active record
:param address_data: Dictionary of address data from magento
:return: Active record of created address
"""
Country = Pool().get("country.country")
Subdivision = Pool().get("country.subdivision")
ContactMechanism = Pool().get("party.contact_mechanism")
country = None
subdivision = None
if address_data["country_id"]:
country = Country.search_using_magento_code(address_data["country_id"])
if address_data["region"]:
subdivision = Subdivision.search_using_magento_region(address_data["region"], country)
address, = cls.create(
[
{
"party": party.id,
"name": " ".join([address_data["firstname"], address_data["lastname"]]),
"street": address_data["street"],
"zip": address_data["postcode"],
"city": address_data["city"],
"country": country and country.id or None,
"subdivision": subdivision and subdivision.id or None,
}
]
)
# Create phone as contact mechanism
if address_data.get("telephone") and not ContactMechanism.search(
[("party", "=", party.id), ("type", "in", ["phone", "mobile"]), ("value", "=", address_data["telephone"])]
):
ContactMechanism.create([{"party": party.id, "type": "phone", "value": address_data["telephone"]}])
return address
示例3: match_with_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_magento_code [as 别名]
def match_with_magento_data(self, address_data):
"""
Match the current address with the address_record.
Match all the fields of the address, i.e., streets, city, subdivision
and country. For any deviation in any field, returns False.
:param address_data: Dictionary of address data from magento
:return: True if address matches else False
"""
Country = Pool().get('country.country')
Subdivision = Pool().get('country.subdivision')
# Check if the name matches
if self.name != ' '.join(
[address_data['firstname'], address_data['lastname']]
):
return False
# Find country and subdivision based on magento data
country = None
subdivision = None
if address_data['country_id']:
country = Country.search_using_magento_code(
address_data['country_id']
)
if address_data['region']:
subdivision = Subdivision.search_using_magento_region(
address_data['region'], country
)
if not all([
self.street == (address_data['street'] or None),
self.zip == (address_data['postcode'] or None),
self.city == (address_data['city'] or None),
self.country == country,
self.subdivision == subdivision,
]):
return False
return True
示例4: get_sale_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_magento_code [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': [],
})
示例5: create_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_magento_code [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
示例6: get_sale_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_magento_code [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': [],
})
示例7: get_sale_using_magento_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_magento_code [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': [],
})