Files
odoo_source/addons/website_sale_picking/controllers/main.py
T
Bastien Dosimont 5b5150dfa5 [ADD] website_sale_onsite : Asking to pay/ship at physical store
Task-id : 2791237
PR : https://github.com/odoo/odoo/pull/87636

Allows customers to see a list of delivery carriers as shops in the website page;
A delivery carrier may now be an onsite one, which means the client comes to the corresponding store to pickup the products.

Also adds a payment acquirer based on wire transfer, for paying on site.
The customer can only pay on site if he also comes to pick the product on site

Notes :

- If a warehouse is set on a delivery carrier, the sales order will take it's address.

closes odoo/odoo#87636

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2022-05-25 09:45:07 +02:00

26 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _
from odoo.addons.website_sale.controllers.main import PaymentPortal
from odoo.exceptions import ValidationError
from odoo.http import request
class PaymentPortalOnsite(PaymentPortal):
def _validate_transaction_for_order(self, transaction, sale_order_id):
"""
Throws a ValidationError if the user tries to pay on site without also using an onsite delivery carrier
Also sets the sale order's warhouse id to the carrier's if it exists
"""
sale_order = request.env['sale.order'].browse(sale_order_id)
super()._validate_transaction_for_order(transaction, sale_order)
# This should never be triggered unless the user intentionally forges a request.
if transaction.acquirer_id.is_onsite_acquirer and sale_order.carrier_id.delivery_type != 'onsite':
raise ValidationError(_('You cannot pay onsite if the delivery is not onsite'))
if sale_order.carrier_id.delivery_type == 'onsite' and sale_order.carrier_id.warehouse_id:
sale_order.warehouse_id = sale_order.carrier_id.warehouse_id