本文整理汇总了Python中trytond.pool.Pool.get_using_ps_id方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.get_using_ps_id方法的具体用法?Python Pool.get_using_ps_id怎么用?Python Pool.get_using_ps_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.get_using_ps_id方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_with_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_using_ps_id [as 别名]
def match_with_ps_data(self, address_record):
"""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_record: Objectified XML record sent by pystashop
:returns: True if address found else False
"""
Country = Pool().get('country.country')
Subdivision = Pool().get('country.subdivision')
fields_map = {
'prestashop_id': 'id',
'street': 'address1',
'streetbis': 'address2',
'zip': 'postcode',
'city': 'city',
}
for key, value in fields_map.items():
# A string match is needed on both sides because these fields might
# contains numbers which will be evaluated as number against
# string
if unicode(getattr(self, key)) != \
(unicode(getattr(address_record, value).pyval) or None):
return False
if self.name != u' '.join([
address_record.firstname.pyval,
address_record.lastname.pyval
]):
return False
if address_record.id_country:
# If no country is found on tryton address return False
if not self.country:
return False
if self.country and \
self.country != Country.get_using_ps_id(
address_record.id_country.pyval
):
return False
if address_record.id_state:
# If no subdivision is found on tryton address return False
if not self.subdivision:
return False
if self.subdivision != Subdivision.get_using_ps_id(
address_record.id_state.pyval
):
return False
# If this method reaches here, it means that every field has matched,
# hence return True
return True
示例2: create_for_party_using_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_using_ps_id [as 别名]
def create_for_party_using_ps_data(cls, party, address_record):
"""Create address from the address record given and link it to the
party.
:param address_record: Objectified XML record sent by pystashop
:param party: Active Record of Party
:returns: 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_record.id_country:
country = Country.get_using_ps_id(
address_record.id_country.pyval
)
if address_record.id_state:
subdivision = Subdivision.get_using_ps_id(
address_record.id_state.pyval
)
address, = cls.create([{
'prestashop_id': address_record.id.pyval,
'party': party.id,
'name': ' '.join([
address_record.firstname.pyval,
address_record.lastname.pyval
]),
'street': unicode(address_record.address1.pyval),
'streetbis': unicode(address_record.address2.pyval or ''),
'zip': unicode(address_record.postcode.pyval),
'city': address_record.city.pyval,
'country': country.id if country else None,
'subdivision': subdivision.id if subdivision else None,
}])
# Create phone and/or mobile as a contact mechanism(s)
contact_data = []
if address_record.phone:
contact_data.append({
'party': party.id,
'type': 'phone',
'value': unicode(address_record.phone.pyval),
})
if address_record.phone_mobile:
contact_data.append({
'party': party.id,
'type': 'mobile',
'value': unicode(address_record.phone_mobile.pyval),
})
ContactMechanism.find_or_create_using_dict(contact_data)
return address
示例3: create_using_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_using_ps_id [as 别名]
def create_using_ps_data(cls, customer_record):
"""Create a party from the customer record sent by prestashop client.
Also create the email sent with the party as a contact mechanism.
:param customer_record: Objectified XML record sent by pystashop
:returns: Active record of created party
"""
Language = Pool().get('ir.lang')
# Create the party with the email
party, = cls.create([{
'name': ' '.join([
customer_record.firstname.pyval,
customer_record.lastname.pyval
]),
'prestashop_id': customer_record.id.pyval,
'lang': Language.get_using_ps_id(
customer_record.id_lang.pyval
).id if hasattr(customer_record, 'id_lang') else None,
'contact_mechanisms': [('create', [{
'type': 'email',
'value': customer_record.email.pyval,
}])],
}])
return party
示例4: cache_prestashop_id
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_using_ps_id [as 别名]
def cache_prestashop_id(cls, prestashop_id):
"""Cache the value of subdivision corresponding to the prestashop_id
by creating a record in the cache model
:param prestashop_id: Prestashop ID
:returns: Active record of the subdivision cached
"""
SubdivisionPrestashop = Pool().get("country.subdivision.prestashop")
Country = Pool().get("country.country")
SaleChannel = Pool().get("sale.channel")
channel = SaleChannel(Transaction().context["current_channel"])
channel.validate_prestashop_channel()
client = channel.get_prestashop_client()
state_data = client.states.get(prestashop_id)
# The country should have been cached till now for sure
country = Country.get_using_ps_id(state_data.id_country.pyval)
subdivision = cls.search([("code", "=", country.code + "-" + state_data.iso_code.pyval)])
if not subdivision:
cls.raise_user_error("subdivision_not_found", (country.code + "-" + state_data.iso_code.pyval,))
SubdivisionPrestashop.create(
[{"subdivision": subdivision[0].id, "channel": channel.id, "prestashop_id": prestashop_id}]
)
return subdivision and subdivision[0] or None
示例5: cache_prestashop_id
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_using_ps_id [as 别名]
def cache_prestashop_id(cls, prestashop_id):
"""Cache the value of subdivision corresponding to the prestashop_id
by creating a record in the cache model
:param prestashop_id: Prestashop ID
:returns: Active record of the subdivision cached
"""
SubdivisionPrestashop = Pool().get('country.subdivision.prestashop')
Country = Pool().get('country.country')
SaleChannel = Pool().get('sale.channel')
channel = SaleChannel(Transaction().context['current_channel'])
channel.validate_prestashop_channel()
client = channel.get_prestashop_client()
state_data = client.states.get(prestashop_id)
# The country should have been cached till now for sure
country = Country.get_using_ps_id(state_data.id_country.pyval)
subdivision = cls.search([
# XXX: Sometime iso code can be integer like `Beijing:11`
(
'code', '=', country.code + '-' +
unicode(state_data.iso_code.pyval)
)
])
if not subdivision:
cls.raise_user_error(
'subdivision_not_found', (
country.code + '-' + state_data.iso_code.pyval,
)
)
SubdivisionPrestashop.create([{
'subdivision': subdivision[0].id,
'channel': channel.id,
'prestashop_id': prestashop_id,
}])
return subdivision and subdivision[0] or None
示例6: create_using_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_using_ps_id [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
示例7: create_using_ps_data
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_using_ps_id [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