forked from alaguraj/odoo-testing-addons
implement Uber Direct integration with configuration model, API client, and webhook controller, and update Docker container naming conventions.
This commit is contained in:
parent
511f50f25a
commit
f3999ef122
@ -47,43 +47,44 @@ class UberDeliveryController(http.Controller):
|
||||
return {'success': False, 'error': 'Uber not configured'}
|
||||
|
||||
company = request.website.company_id
|
||||
# Build clean pickup address - check for False/None values
|
||||
p_street = company.street or ""
|
||||
p_city = company.city or ""
|
||||
p_state = company.state_id.code or company.state_id.name or ""
|
||||
p_zip = company.zip or ""
|
||||
p_country = company.country_id.name or "Canada"
|
||||
|
||||
# Format: "Street, City State Zip, Country"
|
||||
pickup_address = f"{p_street}, {p_city} {p_state} {p_zip}, {p_country}".replace(" ", " ").strip(", ")
|
||||
# Build STRUCTURED pickup address (Object) mapping POS exactly
|
||||
pickup_address = {
|
||||
"street_address": [company.street or ""],
|
||||
"city": company.city or "",
|
||||
"state": company.state_id.code if company.state_id else "",
|
||||
"zip_code": company.zip or "",
|
||||
"country": company.country_id.code or "CA"
|
||||
}
|
||||
|
||||
# User entered address
|
||||
street = address_data.get('street', '').strip()
|
||||
street2 = address_data.get('street2', '').strip()
|
||||
# User entered address fields
|
||||
street = (address_data.get('street') or '').strip()
|
||||
street2 = (address_data.get('street2') or '').strip()
|
||||
full_street = f"{street}, {street2}" if street2 else street
|
||||
|
||||
# Clean state (Try for code if possible)
|
||||
state_input = (address_data.get('state') or '').split('(')[0].strip()
|
||||
state_record = request.env['res.country.state'].sudo().search([
|
||||
('country_id.code', '=', 'CA'),
|
||||
'|', ('name', '=ilike', state_input), ('code', '=ilike', state_input)
|
||||
], limit=1)
|
||||
state_to_send = state_record.code if state_record else state_input
|
||||
state_code = state_record.code if state_record else "ON"
|
||||
|
||||
# Construct dropoff string
|
||||
city = address_data.get('city', '').strip()
|
||||
zip_code = address_data.get('zip', '').strip()
|
||||
country = address_data.get('country', 'Canada').strip()
|
||||
# Build STRUCTURED dropoff address (Object)
|
||||
dropoff_address = {
|
||||
"street_address": [full_street],
|
||||
"city": address_data.get('city', '').strip(),
|
||||
"state": state_code,
|
||||
"zip_code": address_data.get('zip', '').strip(),
|
||||
"country": "CA"
|
||||
}
|
||||
|
||||
country_record = request.env['res.country'].sudo().search([
|
||||
'|', ('name', '=ilike', country), ('code', '=ilike', country)
|
||||
], limit=1)
|
||||
country_name = country_record.name if country_record else "Canada"
|
||||
# For logging, still create strings
|
||||
p_str = f"{pickup_address['street_address'][0]}, {pickup_address['city']} {pickup_address['state']}"
|
||||
d_str = f"{dropoff_address['street_address'][0]}, {dropoff_address['city']} {dropoff_address['state']}"
|
||||
_logger.info("WEBSITE UBER QUOTE (STRUCTURED) -\nPickup: [%s]\nDropoff: [%s]", p_str, d_str)
|
||||
|
||||
dropoff_address = f"{full_street}, {city} {state_to_send} {zip_code}, {country_name}".replace(" ", " ").strip(", ")
|
||||
|
||||
_logger.info("Uber Direct API Call - Pickup: '%s' | Dropoff: '%s'", pickup_address, dropoff_address)
|
||||
|
||||
result = config.get_uber_quote(pickup_address, dropoff_address)
|
||||
# POS ENCODING: The POS sends these as JSON-encoded STRINGS
|
||||
result = config.get_uber_quote(json.dumps(pickup_address), json.dumps(dropoff_address))
|
||||
|
||||
if result.get('success'):
|
||||
order.sudo()._add_uber_delivery_fee(result['fee_amount'])
|
||||
|
||||
@ -47,7 +47,6 @@ class SaleOrder(models.Model):
|
||||
})
|
||||
|
||||
self.write({'carrier_id': carrier.id})
|
||||
self._amount_all()
|
||||
else:
|
||||
_logger.warning("Uber: No delivery carrier found to apply fee")
|
||||
|
||||
|
||||
@ -162,15 +162,26 @@ class UberConfig(models.Model):
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
# Ensure at least one dummy item if none provided (Uber Direct sometimes requires this)
|
||||
if not items:
|
||||
items = [{
|
||||
"name": "Food Delivery",
|
||||
"quantity": 1,
|
||||
"size": "small"
|
||||
}]
|
||||
|
||||
payload = {
|
||||
"pickup_address": pickup_address,
|
||||
"dropoff_address": dropoff_address,
|
||||
"manifest_items": items
|
||||
}
|
||||
if items:
|
||||
payload["manifest_items"] = items
|
||||
|
||||
_logger.info("Uber Direct Payload: %s", json.dumps(payload, indent=2))
|
||||
|
||||
try:
|
||||
response = requests.post(api_url, headers=headers, json=payload)
|
||||
_logger.info("Uber Direct Raw Response (%s): %s", response.status_code, response.text)
|
||||
|
||||
if response.status_code != 200:
|
||||
# Log detailed error for debugging
|
||||
_logger.error("Uber Quote Error: %s - %s", response.status_code, response.text)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user