| 1 |
|
| 2 |
|
| 3 |
from odoo.http import request, route |
| 4 |
|
| 5 |
from odoo.addons.website_sale.controllers.delivery import Delivery |
| 6 |
|
| 7 |
|
| 8 |
class InStoreDelivery(Delivery): |
| 9 |
|
| 10 |
@route() |
| 11 |
def website_sale_get_pickup_locations(self, zip_code=None, **kwargs): |
| 12 |
""" Override of `website_sale` to set the pickup in store delivery method on the order in |
| 13 |
order to retrieve pickup locations when called from the product page. If there is no order |
| 14 |
create a temporary one to display pickup locations. |
| 15 |
""" |
| 16 |
if kwargs.get('product_id'): |
| 17 |
order_sudo = request.cart |
| 18 |
in_store_dm = request.website.sudo().in_store_dm_id |
| 19 |
if not order_sudo: |
| 20 |
|
| 21 |
temp_order = request.env['sale.order'].new({'carrier_id': in_store_dm.id}) |
| 22 |
return temp_order.sudo()._get_pickup_locations(zip_code, **kwargs) |
| 23 |
elif order_sudo.carrier_id.delivery_type != 'in_store': |
| 24 |
order_sudo.set_delivery_line(in_store_dm, in_store_dm.product_id.list_price) |
| 25 |
return super().website_sale_get_pickup_locations(zip_code, **kwargs) |
| 26 |
|
| 27 |
@route('/shop/set_click_and_collect_location', type='jsonrpc', auth='public', website=True) |
| 28 |
def shop_set_click_and_collect_location(self, pickup_location_data): |
| 29 |
""" Set the pickup location and the in-store delivery method on the current order or created |
| 30 |
one. |
| 31 |
|
| 32 |
This route is called from location selector on /product and is distinct from |
| 33 |
/website_sale/set_pickup_location as the latter is only called from the checkout page after |
| 34 |
the delivery method is selected. |
| 35 |
|
| 36 |
:param str pickup_location_data: The JSON-formatted pickup location data. |
| 37 |
:return: None |
| 38 |
""" |
| 39 |
order_sudo = request.cart or request.website._create_cart() |
| 40 |
if order_sudo.carrier_id.delivery_type != 'in_store': |
| 41 |
in_store_dm = request.website.sudo().in_store_dm_id |
| 42 |
order_sudo.set_delivery_line(in_store_dm, in_store_dm.product_id.list_price) |
| 43 |
order_sudo._set_pickup_location(pickup_location_data) |
| 44 |
|
| 45 |
def _get_additional_delivery_context(self): |
| 46 |
""" Override of `website_sale` to include the default pickup location data for in-store |
| 47 |
delivery methods with a single warehouse. """ |
| 48 |
res = super()._get_additional_delivery_context() |
| 49 |
order_sudo = request.cart |
| 50 |
if request.website.sudo().in_store_dm_id: |
| 51 |
res.update(order_sudo._prepare_in_store_default_location_data()) |
| 52 |
return res |
| 53 |
|
| 54 |
@classmethod |
| 55 |
def _get_delivery_methods_express_checkout(cls, order_sudo): |
| 56 |
"""Override to exclude `in_store` delivery methods from exress checkout delivery options.""" |
| 57 |
dm_rate_mapping = super()._get_delivery_methods_express_checkout(order_sudo) |
| 58 |
for dm in list(dm_rate_mapping): |
| 59 |
if dm.delivery_type == 'in_store': |
| 60 |
del dm_rate_mapping[dm] |
| 61 |
return dm_rate_mapping |