Skip to content

Commit

Permalink
[MIG] website_sale_checkout_skip_payment: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeirivera87 committed Sep 10, 2024
1 parent a30bcf0 commit 18c5d1e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 115 deletions.
2 changes: 1 addition & 1 deletion website_sale_checkout_skip_payment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
32 changes: 12 additions & 20 deletions website_sale_checkout_skip_payment/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@
# Copyright 2017 David Vidal <[email protected]>
# 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):
Expand All @@ -31,15 +25,13 @@ def shop_payment_confirmation(self, **post):
return super().shop_payment_confirmation(**post)

Check warning on line 25 in website_sale_checkout_skip_payment/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_checkout_skip_payment/controllers/main.py#L25

Added line #L25 was not covered by tests
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(

Check warning on line 32 in website_sale_checkout_skip_payment/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_checkout_skip_payment/controllers/main.py#L31-L32

Added lines #L31 - L32 were not covered by tests
"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)
1 change: 1 addition & 0 deletions website_sale_checkout_skip_payment/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- Martin Wilderoth \<<[email protected]>\>
- [Studio73](https://www.studio73.es):
- Miguel Gandia \<<[email protected]>\>
- Alexei Rivera \<<[email protected]>\>
4 changes: 2 additions & 2 deletions website_sale_checkout_skip_payment/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ <h1 class="title">Website Sale Checkout Skip Payment</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/e-commerce/tree/17.0/website_sale_checkout_skip_payment"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/e-commerce-17-0/e-commerce-17-0-website_sale_checkout_skip_payment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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 <em>Qoutation Sent</em> state.</p>
the end of the checkout process the quotation is sent to the user email
address and set to <em>Quotation Sent</em> state.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -434,6 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Miguel Gandia &lt;<a class="reference external" href="mailto:miguel&#64;studio73.es">miguel&#64;studio73.es</a>&gt;</li>
</ul>
</li>
<li>Alexei Rivera &lt;<a class="reference external" href="mailto:arivera&#64;archeti.com">arivera&#64;archeti.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
odoo.define("website_sale_checkout_skip_payment.tour", function (require) {
"use strict";
/** @odoo-module */

var tour = require("web_tour.tour");
const tourUtils = require("website_sale.tour_utils");
import {registry} from "@web/core/registry";
import tourUtils from "@website_sale/js/tours/tour_utils";

tour.register(
"website_sale_checkout_skip_payment",
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(),
{
test: true,
url: "/shop?search=Storage%20Box",
content: "Click Confirm Button",
trigger: "a[name='confirm_order_checkout_skip_payment']",
},
[
{
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:')",
},
]
);
{
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')",
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="website.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath
expr="//div[@id='website_settings']/div[@id='social_default_image_setting']"
position="after"
>
<div class="col-12 o_setting_box" id="sale_checkout_skip_message">
<div class="o_setting_right_pane">
<label
string="Sale Checkout Skip Message"
for="website_sale_checkout_skip_message"
/>
<span
class="fa fa-lg fa-globe"
title="Values set here are website-specific."
groups="website.group_multi_website"
/>
<div class="text-muted">
Message shown to the user when the purchase is finished
<xpath expr="//block[@id='website_shop_checkout']" position="inside">
<setting id="sale_checkout_skip_message">
<label
string="Sale Checkout Skip Message"
for="website_sale_checkout_skip_message"
/>
<span
class="fa fa-lg fa-globe"
title="Values set here are website-specific."
groups="website.group_multi_website"
/>
<div class="text-muted">
Message shown to the user when the purchase is finished
</div>
<div class="content-group">
<div class="row mt16">
<field name="website_sale_checkout_skip_message" />
</div>
<field name="website_sale_checkout_skip_message" />
</div>
</div>
</setting>
</xpath>
</field>
</record>
Expand Down
45 changes: 16 additions & 29 deletions website_sale_checkout_skip_payment/views/website_sale_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Copyright 2017 Sergio Teruel <[email protected]>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<template id="payment" inherit_id="website_sale.payment" priority="25">
<xpath expr="//div[hasclass('js_payment')]" position="after">
<xpath expr="//t[@name='website_sale_non_free_cart']" position="before">
<div class="d-flex justify-content-between">
<div class="float-left mt-2" t-if="website.checkout_skip_payment">
<a role="button" href="/shop/cart" class="btn btn-secondary">
Expand All @@ -27,7 +27,12 @@
name="csrf_token"
t-att-value="request.csrf_token()"
/>
<a role="button" class="btn btn-primary a-submit" href="#">
<a
role="button"
name="confirm_order_checkout_skip_payment"
class="btn btn-primary a-submit"
href="#"
>
<span>Confirm <span class="fa fa-chevron-right" /></span>
</a>
</form>
Expand All @@ -41,22 +46,23 @@
add="and not website.checkout_skip_payment"
/>
</xpath>
<xpath expr="//div[hasclass('js_payment')]" position="attributes">
</template>
<template id="confirmation" inherit_id="website_sale.confirmation">
<xpath
expr='//div[@t-if="tx_sudo.state in [&apos;pending&apos;, &apos;done&apos;]"]'
position="attributes"
>
<attribute
name="t-if"
separator=" "
add="and not website.checkout_skip_payment"
/>
>tx_sudo.state in ['pending', 'done'] or (website.checkout_skip_payment and order.state == 'sale')</attribute>
</xpath>
</template>
<template id="confirmation" inherit_id="website_sale.confirmation">
<xpath
expr='//t[@t-if="payment_tx_id.state == &apos;done&apos;"]'
expr='//t[@t-if="tx_sudo.state == &apos;done&apos;"]'
position="attributes"
>
<attribute
name="t-if"
>payment_tx_id.state == 'done' or (website.checkout_skip_payment and order.state == 'sale')</attribute>
>tx_sudo.state == 'done' or website.checkout_skip_payment</attribute>
</xpath>
<xpath
expr="//t[@t-call='website_sale.payment_confirmation_status']"
Expand All @@ -82,23 +88,4 @@
<p>Your order is waiting manual confirmation.</p>
<br />
</template>
<template id="cart" inherit_id="website_sale.cart">
<xpath expr="//a[hasclass('btn-primary')]//t[2]/span[1]" position="attributes">
<attribute name="t-if">not website.checkout_skip_payment</attribute>
</xpath>
<xpath expr="//a[hasclass('btn-primary')]//t[2]/span[1]" position="after">
<span t-if="website.checkout_skip_payment">Confirm</span>
</xpath>
</template>
<template id="short_cart_summary" inherit_id="website_sale.short_cart_summary">
<xpath
expr="//a[hasclass('btn-secondary')]//t[2]/span[1]"
position="attributes"
>
<attribute name="t-if">not website.checkout_skip_payment</attribute>
</xpath>
<xpath expr="//a[hasclass('btn-secondary')]//t[2]/span[1]" position="after">
<span t-if="website.checkout_skip_payment">Confirm</span>
</xpath>
</template>
</odoo>

0 comments on commit 18c5d1e

Please sign in to comment.