[IMP] website_sale_payment_terms: remember term choice and restore Return to Cart button

H5924
This commit is contained in:
Cedric Collins
2021-10-23 15:49:24 -05:00
parent 94bbc7c8e9
commit 2ed501ce2f
3 changed files with 27 additions and 56 deletions

View File

@@ -9,7 +9,7 @@ class WebsiteSalePaymentTerms(WebsiteSaleDelivery):
def payment(self, **post): def payment(self, **post):
order = request.website.sale_get_order() order = request.website.sale_get_order()
payment_term_id = post.get('payment_term_id') payment_term_id = post.get('payment_term_id')
if order.amount_total <= request.website.payment_deposit_threshold: if order.amount_total > request.website.payment_deposit_threshold:
if payment_term_id: if payment_term_id:
payment_term_id = int(payment_term_id) payment_term_id = int(payment_term_id)
if order: if order:

View File

@@ -24,58 +24,21 @@ odoo.define('website_sale_payment_terms.payment_terms', function (require) {
console.log('Payment Terms V10.3'); console.log('Payment Terms V10.3');
return this._super.apply(this, arguments).then(function () { return this._super.apply(this, arguments).then(function () {
var available_term = $('input[name="payment_term_id"]').length; var available_term = $('input[name="payment_term_id"]').length;
var $payButton = $('#o_payment_form_pay');
if (available_term > 0) { if (available_term > 0) {
console.log('Payment term detected'); var $payButton = $('#o_payment_form_pay');
$payButton.prop('disabled', true); $payButton.prop('disabled', true);
var disabledReasons = $payButton.data('disabled_reasons') || {}; var disabledReasons = $payButton.data('disabled_reasons') || {};
disabledReasons.payment_terms_selection = true; if ($('input[name="payment_term_id"][checked]')) {
disabledReasons.payment_terms_selection = false;
} else {
disabledReasons.payment_terms_selection = true;
}
$payButton.data('disabled_reasons', disabledReasons); $payButton.data('disabled_reasons', disabledReasons);
} else { $payButton.prop('disabled', _.contains($payButton.data('disabled_reasons'), true));
console.log('no payment term detected');
} }
}); });
}, },
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/*
* Calculate amount Due Now
*
* @public
* @param: {number} t Total
* @param: {number} d Deposit percentage
* @param: {number} f Deposit flat amount
*/
// calculateDeposit: function (t, d, f) {
// var amount = t * d / 100 + f;
// if (amount > 0) {
// amount = amount.toFixed(2);
// amount = amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// return amount;
// } else {
// amount = 0.00;
// return amount;
// }
// },
/*
* All input clicks update due amount
*
* @public
*/
// updateAmountDue: function () {
// var amount_total = $('#order_total span.oe_currency_value').html().replace(',', '');
// amount_total = parseFloat(amount_total);
// var $checked = $('input[name="payment_term_id"]:checked');
// var $deposit_percentage = $checked.attr('data-deposit-percentage');
// var $deposit_flat = parseFloat($checked.attr('data-deposit-flat'));
// var $due_amount = this.calculateDeposit(amount_total, $deposit_percentage, $deposit_flat);
// $('#order_due_today span.oe_currency_value').html($due_amount);
// },
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Private // Private
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@@ -115,11 +78,9 @@ odoo.define('website_sale_payment_terms.payment_terms', function (require) {
if(result.amount_due_today == 0.0) { if(result.amount_due_today == 0.0) {
$('#payment_method').hide(); $('#payment_method').hide();
$('#non_payment_method').show(); $('#non_payment_method').show();
$('#order_due_today').hide();
} else { } else {
$('#payment_method').show(); $('#payment_method').show();
$('#non_payment_method').hide(); $('#non_payment_method').hide();
$('#order_due_today').show();
} }
// Open success modal with message // Open success modal with message

View File

@@ -3,9 +3,8 @@
<!-- Payment terms list items for /shop/payment --> <!-- Payment terms list items for /shop/payment -->
<template id="payment_term_items"> <template id="payment_term_items">
<p t-esc="order.sudo().payment_term_id"/>
<p t-esc="website_sale_order.sudo().payment_term_id"/>
<t t-set="partner_term" t-value="order.partner_id.property_payment_term_id"/> <t t-set="partner_term" t-value="order.partner_id.property_payment_term_id"/>
<t t-set="selected_term" t-value="order.payment_term_id or partner_term"/>
<!-- Show current partners payment terms --> <!-- Show current partners payment terms -->
<t t-if="partner_term and partner_term not in website_terms"> <t t-if="partner_term and partner_term not in website_terms">
<li class="list-group-item"> <li class="list-group-item">
@@ -14,7 +13,7 @@
t-att-data-deposit-flat="partner_term.deposit_flat or '0'" t-att-data-deposit-flat="partner_term.deposit_flat or '0'"
name="payment_term_id" name="payment_term_id"
t-att-id="'payment_term_%i' % partner_term.id" t-att-id="'payment_term_%i' % partner_term.id"
t-att-checked="term == order.payment_term_id" t-att-checked="term == selected_term"
type="radio"/> type="radio"/>
<label t-att-for="'payment_term_%i' % partner_term.id" <label t-att-for="'payment_term_%i' % partner_term.id"
t-field="partner_term.name" t-field="partner_term.name"
@@ -27,7 +26,7 @@
t-att-data-deposit-percentage="term.deposit_percentage or '0'" t-att-data-deposit-percentage="term.deposit_percentage or '0'"
t-att-data-deposit-flat="term.deposit_flat or '0'" t-att-data-deposit-flat="term.deposit_flat or '0'"
t-att-id="'payment_term_%i' % term.id" t-att-id="'payment_term_%i' % term.id"
t-att-checked="term == order.payment_term_id" t-att-checked="term == selected_term"
type="radio" type="radio"
name="payment_term_id"/> name="payment_term_id"/>
<label t-att-for="'payment_term_%i' % term.id" <label t-att-for="'payment_term_%i' % term.id"
@@ -53,12 +52,23 @@
</div> </div>
</t> </t>
</xpath> </xpath>
<xpath expr="//div[@id='payment_method']" position="attributes">
<attribute name="t-att-style">'display: block;' if website_sale_order.amount_due_today else 'display: none;'</attribute>
</xpath>
<xpath expr="//div[@id='payment_method']" position="after"> <xpath expr="//div[@id='payment_method']" position="after">
<!-- Bypass Validation for users with 0 deposit payment terms --> <!-- Bypass Validation for users with 0 deposit payment terms -->
<div class="mt-3" style="display:none;" id="non_payment_method"> <div class="mt-3" t-att-style="'display: none;' if website_sale_order.amount_due_today else 'display: block;'" id="non_payment_method">
<a href="/shop/confirm_without_payment" class="float-right btn btn-primary"> <div class="float-left mt-2">
<span>Confirm Order <span class="fa fa-chevron-right"/></span> <a role="button" href="/shop/cart" class="btn btn-secondary">
</a> <i class="fa fa-chevron-left"/>
Return to Cart
</a>
</div>
<div class="float-right mt-2" >
<a href="/shop/confirm_without_payment" class="float-right btn btn-primary">
<span>Confirm Order <span class="fa fa-chevron-right"/></span>
</a>
</div>
</div> </div>
</xpath> </xpath>
</template> </template>
@@ -122,7 +132,7 @@
<!-- Add empty div to calculate amount due today in payment_terms.js --> <!-- Add empty div to calculate amount due today in payment_terms.js -->
<template id="amount_due_today" inherit_id="website_sale.total"> <template id="amount_due_today" inherit_id="website_sale.total">
<xpath expr="//tr[@id='order_total']" position="after"> <xpath expr="//tr[@id='order_total']" position="after">
<tr id="order_due_today" t-att-class="'' if website_sale_order.amount_due_today else 'd-none'"> <tr id="order_due_today">
<td class="text-right text-info"> <td class="text-right text-info">
<strong>Due Now:</strong> <strong>Due Now:</strong>
</td> </td>