mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 11:12:02 +02:00
Initial commit: Sale packages
This commit is contained in:
commit
14e3d26998
6469 changed files with 2479670 additions and 0 deletions
|
|
@ -0,0 +1,83 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import publicWidget from 'web.public.widget';
|
||||
import { _t } from 'web.core';
|
||||
import 'website_sale_delivery.checkout';
|
||||
|
||||
publicWidget.registry.websiteSaleDelivery.include({
|
||||
start: function () {
|
||||
this.onsiteOptions = document.querySelectorAll('.o_payment_option_card input[type=radio][data-is-onsite="1"]');
|
||||
if(this.onsiteOptions.length > 0){ // Falsy evaluation does not work with NodeList
|
||||
this.paymentOptions = document.querySelectorAll('.o_payment_option_card input[type=radio]');
|
||||
|
||||
this.warning = document.createElement('p');
|
||||
const boldMsg = document.createElement('b');
|
||||
boldMsg.innerText = _t('No suitable payment option could be found.');
|
||||
this.warning.innerText = _t('If you believe that it is an error, please contact the website administrator.');
|
||||
boldMsg.classList.add('d-block');
|
||||
this.warning.prepend(boldMsg);
|
||||
this.warning.classList.add('alert-warning', 'p-3', 'm-1', 'd-none');
|
||||
|
||||
this.paymentOptionsContainer = document.querySelector('#payment_method');
|
||||
this.paymentOptionsContainer.querySelector('div.card').prepend(this.warning);
|
||||
}
|
||||
return this._super.apply(this, ...arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Hides or shows a payment option card.
|
||||
* @param node the input element of the payment option card
|
||||
* @param enabled whether to show or hide the card
|
||||
* @private
|
||||
*/
|
||||
_setEnablePaymentOption(node, enabled) {
|
||||
if (enabled) {
|
||||
node.parentNode.parentNode.classList.remove('d-none');
|
||||
} else {
|
||||
node.parentNode.parentNode.classList.add('d-none');
|
||||
node.checked = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks all payment options and hides them if it is an onsite payment option and the delivery is not onsite.
|
||||
* @param {Event} ev the triggered document event
|
||||
* @private
|
||||
* @override
|
||||
*/
|
||||
_onCarrierClick: function (ev) {
|
||||
this._super(...arguments);
|
||||
|
||||
if(this.onsiteOptions.length === 0){ // Falsy evaluation does not work with NodeList
|
||||
return;
|
||||
}
|
||||
|
||||
this.warning.classList.add('d-none');
|
||||
|
||||
const input = ev.currentTarget.querySelector('input');
|
||||
let atLeastOneOptionAvailable = false;
|
||||
for (let option of this.paymentOptions) {
|
||||
if (option.dataset.isOnsite && input.dataset.deliveryType !== 'onsite') {
|
||||
this._setEnablePaymentOption(option, false);
|
||||
} else{
|
||||
if(option.dataset.isOnsite){
|
||||
this._setEnablePaymentOption(option, true);
|
||||
}
|
||||
atLeastOneOptionAvailable = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Jquery because the button does not behave nicely with vanilla dataset.
|
||||
let $payButton = $('button[name="o_payment_submit_button"]');
|
||||
let disabledReasons = $payButton.data('disabled_reasons') || {};
|
||||
disabledReasons.noOptionAvailableOnsite = false;
|
||||
|
||||
if (!atLeastOneOptionAvailable) {
|
||||
this.warning.classList.remove('d-none');
|
||||
disabledReasons.noOptionAvailableOnsite = true;
|
||||
} else if (this.paymentOptions.length === 1) {
|
||||
$(this.paymentOptions[0]).click(); // Make sure the option is selected if that's the only one, because the input is hidden in that case.
|
||||
}
|
||||
$payButton.data('disabled_reasons', disabledReasons);
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import tour from 'web_tour.tour'
|
||||
import wTourUtils from 'website.tour_utils';
|
||||
import wsTourUtils from 'website_sale.tour_utils';
|
||||
|
||||
tour.register('onsite_payment_tour', {
|
||||
test: true,
|
||||
url: '/web',
|
||||
},
|
||||
[
|
||||
...wsTourUtils.addToCart({productName: 'Product Consumable'}),
|
||||
wsTourUtils.goToCart(),
|
||||
wTourUtils.clickOnElement('Proceed to checkout', 'a:contains(Process Checkout)'),
|
||||
...wsTourUtils.fillAdressForm(),
|
||||
wTourUtils.clickOnElement('Example shipping On Site', '.o_delivery_carrier_select:contains("Example shipping On Site")'),
|
||||
wTourUtils.clickOnElement('pay button', 'button[name="o_payment_submit_button"]:visible:not(:disabled)'),
|
||||
{
|
||||
content: "Check if the payment is successful",
|
||||
trigger: 'p:contains(Your order has been saved. Please come to the store to pay for your products)',
|
||||
},
|
||||
|
||||
// Test multi products (Either physical or not)
|
||||
...wsTourUtils.addToCart({productName: 'Product Consumable'}),
|
||||
...wsTourUtils.addToCart({productName: 'Product Service'}),
|
||||
wsTourUtils.goToCart({quantity: 2}),
|
||||
wTourUtils.clickOnElement('Go to payment page', 'a:contains("Process Checkout")'),
|
||||
...wsTourUtils.fillAdressForm(),
|
||||
wTourUtils.clickOnElement('"Pay in store when picking the product"', '.o_delivery_carrier_select:contains("Example shipping On Site")'),
|
||||
wTourUtils.clickOnElement('Pay button', 'button[name="o_payment_submit_button"]:visible:not(:disabled)'),
|
||||
{
|
||||
content: "Check if the payment is successful",
|
||||
trigger: 'p:contains(Your order has been saved. Please come to the store to pay for your products)',
|
||||
},
|
||||
|
||||
// Test without any physical product (option pay on site should not appear)
|
||||
...wsTourUtils.addToCart({productName: 'Product Service'}),
|
||||
wsTourUtils.goToCart(),
|
||||
wTourUtils.clickOnElement('Go to payment page', 'a:contains("Process Checkout")'),
|
||||
...wsTourUtils.fillAdressForm(),
|
||||
{
|
||||
content: 'Assert pay on site is NOT an option',
|
||||
trigger: 'body:not(:contains("Test Payment Provider"))',
|
||||
},
|
||||
]
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue