forked from alaguraj/odoo-testing-addons
add Uber delivery webhook and quote controllers and update docker-compose container naming
This commit is contained in:
parent
b89e103ad5
commit
f20c554391
@ -47,32 +47,40 @@ class UberDeliveryController(http.Controller):
|
|||||||
return {'success': False, 'error': 'Uber not configured'}
|
return {'success': False, 'error': 'Uber not configured'}
|
||||||
|
|
||||||
company = request.website.company_id
|
company = request.website.company_id
|
||||||
# Match POS Format: "Street, City State Zip, Country"
|
# Build clean pickup address using State CODE (e.g. ON for Ontario)
|
||||||
state_code = company.state_id.code or company.state_id.name or ""
|
p_state = company.state_id.code or company.state_id.name or ""
|
||||||
pickup_address = f"{company.street}, {company.city} {state_code} {company.zip}, {company.country_id.name}"
|
pickup_address = f"{company.street}, {company.city} {p_state} {company.zip}, {company.country_id.name}"
|
||||||
|
|
||||||
# User entered address
|
# User entered address
|
||||||
street = address_data.get('street', '').strip()
|
street = address_data.get('street', '').strip()
|
||||||
street2 = address_data.get('street2', '').strip()
|
street2 = address_data.get('street2', '').strip()
|
||||||
full_street = f"{street}, {street2}" if street2 else street
|
full_street = f"{street}, {street2}" if street2 else street
|
||||||
|
|
||||||
# Clean state (Try for code if possible, fall back to name)
|
# Clean state (Try for code if possible)
|
||||||
state_name = address_data.get('state', '').split('(')[0].strip()
|
state_input = address_data.get('state', '').split('(')[0].strip()
|
||||||
|
state_record = request.env['res.country.state'].sudo().search([
|
||||||
|
'|', ('name', '=ilike', state_input), ('code', '=ilike', state_input)
|
||||||
|
], limit=1)
|
||||||
|
state_to_send = state_record.code if state_record else state_input
|
||||||
|
|
||||||
# Construct dropoff string in POS format: "Street, City State Zip, Country"
|
# Construct dropoff string in exact POS format: "Street, City State Zip, Country"
|
||||||
city = address_data.get('city', '').strip()
|
city = address_data.get('city', '').strip()
|
||||||
zip_code = address_data.get('zip', '').strip()
|
zip_code = address_data.get('zip', '').strip()
|
||||||
country = address_data.get('country', 'Canada').strip()
|
country = address_data.get('country', 'Canada').strip()
|
||||||
|
# Canada country code is CA
|
||||||
|
country_code = "Canada"
|
||||||
|
country_record = request.env['res.country'].sudo().search([
|
||||||
|
'|', ('name', '=ilike', country), ('code', '=ilike', country)
|
||||||
|
], limit=1)
|
||||||
|
if country_record: country_code = country_record.name
|
||||||
|
|
||||||
dropoff_address = f"{full_street}, {city} {state_name} {zip_code}, {country}"
|
dropoff_address = f"{full_street}, {city} {state_to_send} {zip_code}, {country_code}"
|
||||||
|
|
||||||
_logger.info("Uber Quote Request - Pickup: %s | Dropoff: %s", pickup_address, dropoff_address)
|
_logger.info("Uber Direct API Call - Pickup: '%s' | Dropoff: '%s'", pickup_address, dropoff_address)
|
||||||
|
|
||||||
result = config.get_uber_quote(pickup_address, dropoff_address)
|
result = config.get_uber_quote(pickup_address, dropoff_address)
|
||||||
|
|
||||||
if result.get('success'):
|
if result.get('success'):
|
||||||
# Clear old delivery fee if different? Or just update.
|
|
||||||
# In Odoo website_sale, we usually want to add it to the cart
|
|
||||||
order.sudo()._add_uber_delivery_fee(result['fee_amount'])
|
order.sudo()._add_uber_delivery_fee(result['fee_amount'])
|
||||||
return {
|
return {
|
||||||
'success': True,
|
'success': True,
|
||||||
@ -80,4 +88,5 @@ class UberDeliveryController(http.Controller):
|
|||||||
'eta': result.get('estimated_arrival'),
|
'eta': result.get('estimated_arrival'),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
_logger.warning("Uber Quote Failed: %s", result.get('error'))
|
||||||
return result
|
return result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user