Debian Codegraph @

addons/sale/static/src/interactions/portal_prepayment.js

raw symbols SCIP
1 import { registry } from "@web/core/registry";
2 import { Interaction } from "@web/public/interaction";
3
4 export class PortalPrepayment extends Interaction {
5 static selector = ".o_portal_sale_sidebar";
6 dynamicSelectors = {
7 ...this.dynamicSelectors,
8 _amountPrepaymentButton: () => this.amountPrepaymentButton,
9 _amountTotalButton: () => this.amountTotalButton,
10 };
11 dynamicContent = {
12 _amountPrepaymentButton: {
13 't-on-click': () => this.reloadAmount(true),
14 't-att-class': () => ({ 'active': this.isDownPayment }),
15 },
16 _amountTotalButton: {
17 't-on-click': () => this.reloadAmount(false),
18 't-att-class': () => ({ 'active': !this.isDownPayment }),
19 },
20 'span[id="o_sale_portal_use_amount_prepayment"]': {
21 't-att-class': () => ({ 'd-none': !this.isDownPayment }),
22 },
23 'span[id="o_sale_portal_use_amount_total"]': {
24 't-att-class': () => ({ 'd-none': this.isDownPayment }),
25 },
26 };
27
28 setup() {
29 this.amountPrepaymentButton = document.querySelector(
30 'button[name="o_sale_portal_amount_prepayment_button"]'
31 );
32 this.amountTotalButton = document.querySelector(
33 'button[name="o_sale_portal_amount_total_button"]'
34 );
35 const params = new URLSearchParams(window.location.search);
36 if (params.has('amount_selection')) {
37 this.isDownPayment = params.get('amount_selection') === 'down_payment'
38 } else if (params.has('payment_amount')) {
39 const paymentAmount = params.get('payment_amount');
40 this.isDownPayment = Number(paymentAmount) < Number(this.el.dataset.orderAmountTotal);
41 } else {
42 this.isDownPayment = true;
43 }
44 this.showPaymentModal = params.has('payment_amount') || params.has('amount_selection');
45 }
46
47 start() {
48 // When updating the amount re-open the modal.
49 if (this.showPaymentModal) {
50 document.querySelector("#o_sale_portal_paynow")?.click();
51 }
52 }
53
54 reloadAmount(isDownPayment) {
55 const searchParams = new URLSearchParams(window.location.search);
56 searchParams.set('amount_selection', isDownPayment ? 'down_payment' : 'full_amount');
57 window.location.search = searchParams.toString();
58 }
59 }
60
61 registry
62 .category("public.interactions")
63 .add("sale.portal_prepayment", PortalPrepayment);