From 09eca7a716cc872e2b16ae6fcc1dd03427b055a3 Mon Sep 17 00:00:00 2001
From: Alexei Rivera
Date: Mon, 5 Aug 2024 15:53:37 -0400
Subject: [PATCH] [MIG] website_sale_checkout_skip_payment: Migration to 17.0
---
.../__manifest__.py | 2 +-
.../controllers/main.py | 32 +++++--------
.../readme/CONTRIBUTORS.md | 1 +
.../readme/DESCRIPTION.md | 4 +-
.../static/description/index.html | 5 +-
...ite_sale_checkout_skip_payment_tour.esm.js | 26 ++++++++++
...website_sale_checkout_skip_payment_tour.js | 47 -------------------
.../views/res_config_settings_views.xml | 37 +++++++--------
.../views/website_sale_template.xml | 45 +++++++-----------
9 files changed, 79 insertions(+), 120 deletions(-)
create mode 100644 website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.esm.js
delete mode 100644 website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.js
diff --git a/website_sale_checkout_skip_payment/__manifest__.py b/website_sale_checkout_skip_payment/__manifest__.py
index 3b0b1bcdf9..1bf3a460af 100644
--- a/website_sale_checkout_skip_payment/__manifest__.py
+++ b/website_sale_checkout_skip_payment/__manifest__.py
@@ -5,7 +5,7 @@
{
"name": "Website Sale Checkout Skip Payment",
"summary": "Skip payment for logged users in checkout process",
- "version": "16.0.1.2.0",
+ "version": "17.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Tecnativa, Odoo Community Association (OCA)",
diff --git a/website_sale_checkout_skip_payment/controllers/main.py b/website_sale_checkout_skip_payment/controllers/main.py
index 5688e9d92e..dc74eaf997 100644
--- a/website_sale_checkout_skip_payment/controllers/main.py
+++ b/website_sale_checkout_skip_payment/controllers/main.py
@@ -2,25 +2,19 @@
# Copyright 2017 David Vidal
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
-from odoo import http
+from odoo import SUPERUSER_ID, http
from odoo.http import request
from odoo.addons.website_sale.controllers.main import WebsiteSale
class CheckoutSkipPaymentWebsite(WebsiteSale):
- @http.route()
- def shop_payment_get_status(self, sale_order_id, **post):
- # When skip payment step, the transaction not exists so only render
- # the waiting message in ajax json call
- if not request.website.checkout_skip_payment:
- return super().shop_payment_get_status(sale_order_id, **post)
- return {
- "recall": True,
- "message": request.website._render(
- "website_sale_checkout_skip_payment.order_state_message"
- ),
- }
+ def _get_shop_payment_values(self, order, **kwargs):
+ values = super()._get_shop_payment_values(order, **kwargs)
+ partner = values.get("partner")
+ if partner.skip_website_checkout_payment:
+ values["hide_payment_button"] = True
+ return values
@http.route()
def shop_payment_confirmation(self, **post):
@@ -31,15 +25,13 @@ def shop_payment_confirmation(self, **post):
return super().shop_payment_confirmation(**post)
order = request.env["sale.order"].sudo().browse(order_id)
try:
- order.with_context(mark_so_as_sent=True)._send_order_confirmation_mail()
+ order.with_context(send_email=True, mark_so_as_sent=True).with_user(
+ SUPERUSER_ID
+ ).action_confirm()
except Exception:
return request.render(
"website_sale_checkout_skip_payment.confirmation_order_error"
)
- # This could not finish (e.g.: sale_financial_risk exceeded)
- order.action_confirm()
request.website.sale_reset()
- return request.render(
- "website_sale.confirmation",
- {"order": order, "order_tracking_info": self.order_2_return_dict(order)},
- )
+ values = self._prepare_shop_payment_confirmation_values(order)
+ return request.render("website_sale.confirmation", values)
diff --git a/website_sale_checkout_skip_payment/readme/CONTRIBUTORS.md b/website_sale_checkout_skip_payment/readme/CONTRIBUTORS.md
index 1d9ef29609..30d0cbd101 100644
--- a/website_sale_checkout_skip_payment/readme/CONTRIBUTORS.md
+++ b/website_sale_checkout_skip_payment/readme/CONTRIBUTORS.md
@@ -6,3 +6,4 @@
- Martin Wilderoth \<\>
- [Studio73](https://www.studio73.es):
- Miguel Gandia \<\>
+- Alexei Rivera \<\>
diff --git a/website_sale_checkout_skip_payment/readme/DESCRIPTION.md b/website_sale_checkout_skip_payment/readme/DESCRIPTION.md
index d1d2673ef5..1b73e9da81 100644
--- a/website_sale_checkout_skip_payment/readme/DESCRIPTION.md
+++ b/website_sale_checkout_skip_payment/readme/DESCRIPTION.md
@@ -1,3 +1,3 @@
This module allows to logged users to checkout with no payment step. At
-the end of the checkout proccess the quotation is sent to the user email
-address and set to *Qoutation Sent* state.
+the end of the checkout process the quotation is sent to the user email
+address and set to *Quotation Sent* state.
diff --git a/website_sale_checkout_skip_payment/static/description/index.html b/website_sale_checkout_skip_payment/static/description/index.html
index 1c58f5af32..882af49d54 100644
--- a/website_sale_checkout_skip_payment/static/description/index.html
+++ b/website_sale_checkout_skip_payment/static/description/index.html
@@ -371,8 +371,8 @@ Website Sale Checkout Skip Payment
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
This module allows to logged users to checkout with no payment step. At
-the end of the checkout proccess the quotation is sent to the user email
-address and set to Qoutation Sent state.
+the end of the checkout process the quotation is sent to the user email
+address and set to Quotation Sent state.
diff --git a/website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.esm.js b/website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.esm.js
new file mode 100644
index 0000000000..d5be33e7ec
--- /dev/null
+++ b/website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.esm.js
@@ -0,0 +1,26 @@
+/** @odoo-module */
+
+import {registry} from "@web/core/registry";
+import tourUtils from "@website_sale/js/tours/tour_utils";
+
+registry.category("web_tour.tours").add("website_sale_checkout_skip_payment", {
+ test: true,
+ url: "/shop",
+ steps: () => [
+ ...tourUtils.addToCart({productName: "Storage Box"}),
+ tourUtils.goToCart({quantity: 1}),
+ tourUtils.goToCheckout(),
+ {
+ content: "Click Confirm Button",
+ trigger: "a[name='confirm_order_checkout_skip_payment']",
+ },
+ {
+ trigger: "h4:contains('Payment Information')",
+ },
+ {
+ content: "Check confirmation and that the cart has been left empty",
+ trigger: "a:has(.my_cart_quantity:containsExact(0))",
+ extra_trigger: "h4:contains('Payment Information')",
+ },
+ ],
+});
diff --git a/website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.js b/website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.js
deleted file mode 100644
index ea59773991..0000000000
--- a/website_sale_checkout_skip_payment/static/tests/tours/website_sale_checkout_skip_payment_tour.js
+++ /dev/null
@@ -1,47 +0,0 @@
-odoo.define("website_sale_checkout_skip_payment.tour", function (require) {
- "use strict";
-
- var tour = require("web_tour.tour");
- const tourUtils = require("website_sale.tour_utils");
-
- tour.register(
- "website_sale_checkout_skip_payment",
- {
- test: true,
- url: "/shop?search=Storage%20Box",
- },
- [
- {
- content: "select Storage Box",
- extra_trigger: ".oe_search_found",
- trigger: '.oe_product_cart a:contains("Storage Box")',
- },
- {
- content: "Add Storage Box into cart",
- trigger: "a:contains(ADD TO CART)",
- },
- tourUtils.goToCart(),
- {
- content: "go to checkout",
- extra_trigger: "#cart_products input.js_quantity:propValue(1)",
- trigger: 'a[href*="/shop/checkout"]',
- },
- {
- trigger: '.btn-primary:contains("Confirm")',
- },
- {
- trigger: ".btn:contains('Confirm')",
- extra_trigger: "b:contains('Billing & Shipping:')",
- },
- {
- trigger: "a[href='/shop']",
- extra_trigger: "strong:contains('Payment Information:')",
- },
- {
- content: "Check confirmation and that the cart has been left empty",
- trigger: "a:has(.my_cart_quantity:containsExact(0))",
- extra_trigger: "strong:contains('Payment Information:')",
- },
- ]
- );
-});
diff --git a/website_sale_checkout_skip_payment/views/res_config_settings_views.xml b/website_sale_checkout_skip_payment/views/res_config_settings_views.xml
index 9691c96f9d..84be6d68ca 100644
--- a/website_sale_checkout_skip_payment/views/res_config_settings_views.xml
+++ b/website_sale_checkout_skip_payment/views/res_config_settings_views.xml
@@ -4,27 +4,26 @@
res.config.settings
-
-
-
-
-
-
- Message shown to the user when the purchase is finished
+
+
+
+
+
+ Message shown to the user when the purchase is finished
+
+
-
+
diff --git a/website_sale_checkout_skip_payment/views/website_sale_template.xml b/website_sale_checkout_skip_payment/views/website_sale_template.xml
index ee90c4daa9..b38fb48042 100644
--- a/website_sale_checkout_skip_payment/views/website_sale_template.xml
+++ b/website_sale_checkout_skip_payment/views/website_sale_template.xml
@@ -3,7 +3,7 @@
-
+
@@ -27,7 +27,12 @@
name="csrf_token"
t-att-value="request.csrf_token()"
/>
-
+
Confirm
@@ -41,22 +46,23 @@
add="and not website.checkout_skip_payment"
/>
-
+
+
+
+ >tx_sudo.state in ['pending', 'done'] or (website.checkout_skip_payment and order.state == 'sale')
-
-
payment_tx_id.state == 'done' or (website.checkout_skip_payment and order.state == 'sale')
+ >tx_sudo.state == 'done' or website.checkout_skip_payment
Your order is waiting manual confirmation.
-
-
- not website.checkout_skip_payment
-
-
- Confirm
-
-
-
-
- not website.checkout_skip_payment
-
-
- Confirm
-
-