| 1 |
|
| 2 |
|
| 3 |
from odoo import _ |
| 4 |
from odoo.exceptions import ValidationError |
| 5 |
|
| 6 |
from odoo.addons.website_sale.controllers.payment import PaymentPortal |
| 7 |
|
| 8 |
|
| 9 |
class OnSitePaymentPortal(PaymentPortal): |
| 10 |
|
| 11 |
def _validate_transaction_for_order(self, transaction, sale_order): |
| 12 |
""" Override of `website_sale` to ensure the on-site payment provider is not used without |
| 13 |
the in-store pickup delivery method. |
| 14 |
|
| 15 |
This also sets the warehouse of the selected pickup location on the sales order. |
| 16 |
|
| 17 |
:param payment.transaction transaction: The transaction used to make the payment. |
| 18 |
:param sale.order sale_order: The sales order to pay. |
| 19 |
:return: None |
| 20 |
:raises ValidationError: If the user tries to pay on site without the in-store pickup |
| 21 |
delivery method. |
| 22 |
""" |
| 23 |
super()._validate_transaction_for_order(transaction, sale_order) |
| 24 |
|
| 25 |
|
| 26 |
provider = transaction.provider_id |
| 27 |
if ( |
| 28 |
sale_order.carrier_id.delivery_type != 'in_store' |
| 29 |
and provider.code == 'custom' |
| 30 |
and provider.custom_mode == 'on_site' |
| 31 |
): |
| 32 |
raise ValidationError( |
| 33 |
_("You can only pay on site when selecting the pick up in store delivery method.") |
| 34 |
) |