Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

Custom Cards Payment Module: POS Payment Summary Not Updating with Installments

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
javascriptdevelopmentsalesproject
2 Trả lời
2124 Lượt xem
Ảnh đại diện
Diego Naranjo

Hey there! I'm having a tricky issue with my custom Cards payment module for Odoo 18 POS. I built this module to handle credit card payments with installments, and everything works great except for one annoying detail in the payment screen. The total amount in the payment summary doesn't update automatically when selecting installments. This is my custom implementation that extends the default POS payment screen, using a CardsPaymentHandler class to manage card brands and installment calculations. The weird part is that the amount only updates in two scenarios:

If I remove the payment method and add it again (then it shows the correct total from the order/status)

If I manually type numbers using the POS numeric keypad (then it updates the payment method total in the summary)

All the interest calculations work fine, and I can see the correct amounts in the state, but for some reason, the payment summary display won't refresh with the new total when choosing installments.

Has anyone encountered something similar when extending the POS payment screen or knows what might be missing? Maybe there's a specific method I need to call to force the payment summary update?

I published the main functions that manage the updates of the totals according to the installments.

Thanks in advance!

/**

    * Handles card brand selection change

    * Resets prices and loads available installments

    * @param {Event} ev Change event from select element

    */

async onCardBrandChange(ev) {

    const cardBrand = ev.target.value;

    this._resetPrices();

    if (!cardBrand) {

        this._resetState();

        return;

    }


    try {

        const amount = this.currentOrder.get_total_with_tax();

        const installments = await rpc('/pos_payment_method/get_installments', {

            payment_method_id: CARDS_PAYMENT_METHOD_ID,

            card_brand: cardBrand,

            amount: amount

        });


        if (!installments) {

            throw new Error('There isn´t installments plan.');

        }


        this.state.selectedCardBrand = cardBrand;

        this.state.installmentOptions = this._formatInstallmentOptions(installments);

        this.screen.render();

    } catch (error) {

        this._resetState();

        this.showError('Error loading installments');

    }

}


/**

    * Handles installment selection change

    * Updates order amounts and payment line with interest

    * @param {Event} ev Change event from select element

    */

onInstallmentChange(ev) {

    const installments = ev.target.value;

    const option = this.state.installmentOptions.find(

        opt => opt.installments.toString() === installments

    );


    if (!option) return;


    try {

        // Update state with selected installment data

        Object.assign(this.state, {

            selectedInstallments: option.installments,

            installmentAmount: parseFloat(option.amount),

            totalWithInterest: parseFloat(option.total),

            interestRate: parseFloat(option.rate)

        });

        if (typeof option.coefficient === 'number' && !isNaN(option.coefficient)) {

            this._updateOrderLinesWithInterest(option.coefficient);

            const totalWithInterest = parseFloat(this.state.totalWithInterest);

            if (!isNaN(totalWithInterest) && this.selectedPaymentLine) {

                this.selectedPaymentLine.amount = totalWithInterest;

                this.selectedPaymentLine.set_payment_status("done");

                if (this.screen.numberBuffer) {

                    this.screen.numberBuffer.set(totalWithInterest.toString());

                }

            }

        }

        this._updatePaymentSummary();

        this.screen.render();

    } catch (error) {

        this.showError('Error processing installment change');

    }

}


/**

    * Updates order lines with interest coefficient

    * Recalculates totals and updates UI

    * @param {number} coefficient Interest multiplier

    */

_updateOrderLinesWithInterest(coefficient) {

    const order = this.currentOrder;

    if (!order) return;


    const coef = parseFloat(coefficient);

    if (isNaN(coef)) return;


    order.get_orderlines().forEach(line => {

        try {

            if (!line.original_price) {

                line.original_price = line.get_unit_price();

            }

            line.set_unit_price(line.original_price * coef);

        } catch (error) {

            console.error('Error processing line:', error);

        }

    });


    order.recomputeOrderData();

    this.state.totalWithInterest = order.amount_total;

    this._forcePaymentSummaryUpdate();

}


/**

    * Forces payment summary update in UI

    * Updates totals, remaining amount and payment lines

    */

_forcePaymentSummaryUpdate() {

    if (!this.currentOrder) return;


    try {

        Object.assign(this.screen.state, {

            totalAmount: this.currentOrder.amount_total,

            remainingAmount: this.currentOrder.get_due(),

            paymentLines: [...this.currentOrder.payment_ids]

        });

        if (this.screen.numberBuffer) {

            this.screen.numberBuffer.set(this.state.totalWithInterest.toString());

        }

        this.screen.render();

    } catch (error) {

        this.showError('Error updating payment summary');

    }

}


/**

    * Updates payment summary with new totals

    * Handles payment line amount updates

    */

_updatePaymentSummary() {

    if (!this.currentOrder || !this.selectedPaymentLine) return;

    const paid = this.currentOrder.get_total_paid();

    const remaining = Math.max(this.state.totalWithInterest - paid, 0);

    Object.assign(this.screen.state, {

        totalAmount: this.state.totalWithInterest,

        remainingAmount: remaining,

        paymentLines: [...this.currentOrder.payment_ids]

    });

    this.selectedPaymentLine.set_amount(this.state.totalWithInterest);

    this.currentOrder.set_total_with_tax(this.state.totalWithInterest);

    this.screen.payment_interface.update_payment_summary({

        total: this.state.totalWithInterest,

        total_paid: paid,

        remaining: remaining

    });

    this.screen.render();

}


/**

    * Updates payment line amount

    * Handles amount validation and UI updates

    * @param {number|false} amount New amount or false to get from buffer

    */

updatePaymentLine(amount = false) {

    this.updateReferences();

    if (amount === false) {

        amount = this.screen.numberBuffer.getFloat();

    }

    if (amount === null) {

        this._resetPrices();

        this.screen.deletePaymentLine(this.screen.selectedPaymentLine.uuid);

        return;

    }

    const maxAmount = this.state.totalWithInterest || this.currentOrder.get_total_with_tax();

    if (amount > maxAmount) {

        amount = maxAmount;

        this.screen.numberBuffer.set(maxAmount.toString());

        this._showMaxAmountError();

    }

    this.screen.selectedPaymentLine.set_amount(amount);

    this.screen.render();

}


/**

    * Resets prices to original values

    * Clears interest calculations

    */

_resetPrices() {

    const order = this.currentOrder;

    if (!order) return;

    order.get_orderlines().forEach(line => {

        try {

            if (line.original_price) {

                line.set_unit_price(line.original_price);

                line.setLinePrice();

            }

        } catch (error) {

            console.error('Error resetting price:', error);

        }

    });

    order.recomputeOrderData();

}

0
Ảnh đại diện
Huỷ bỏ
Diego Naranjo
Tác giả

Hi there!, after 4 months i managed to make an absolutely FREE module for use with credit cards through the Fiserv gateway service (at the moment it only works for Argentina but it could be improved for other countries).

It is published on github, you can find it as fiserv_gateway.

The ideal is that we can all improve it as a community so that it works in the countries that see it useful.
It still has several points to improve, but it is a good starting point for all those who need a form of payment online and at the POS with debit/credit cards.
Any queries can locate my contact details on my github profile.
Kind regards

Ảnh đại diện
Diego Naranjo
Tác giả Câu trả lời hay nhất

Hello Tiago,

I thank you for your kindness, but I have already tried all the options provided by the available AI and I have not been able to make progress.

Kind regards.

0
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Tiago de Freitas Gomes
Câu trả lời hay nhất

The analysis of your code indicates that the main functions to update the payment summary are in place, but there might be issues related to the DOM rendering cycle or state synchronization in the Odoo POS. Here are the potential causes and solutions for the issue of the payment summary not refreshing when selecting installments:


Potential Causes

  1. DOM Rendering Cycle Issue
    • The DOM might not be updating correctly after the installment calculations. This happens when state changes are not propagated to the user interface components.
  2. Update Methods Not Called Properly
    • Although _updatePaymentSummary is being called, it might require a more explicit method to ensure the POS updates the payment component.
  3. numberBuffer Synchronization
    • The numeric buffer synchronization with the new totals might not be functioning correctly, requiring a more explicit approach to reflect the updated amounts.

Fixes and Improvements

1. Force Screen Refresh

Add an explicit command to force the payment component to re-render after updates:

_updatePaymentSummary() {
    if (!this.currentOrder || !this.selectedPaymentLine) return;

    const paid = this.currentOrder.get_total_paid();
    const remaining = Math.max(this.state.totalWithInterest - paid, 0);

    Object.assign(this.screen.state, {
        totalAmount: this.state.totalWithInterest,
        remainingAmount: remaining,
        paymentLines: [...this.currentOrder.payment_ids],
    });

    this.selectedPaymentLine.set_amount(this.state.totalWithInterest);
    this.currentOrder.set_total_with_tax(this.state.totalWithInterest);

    // Explicitly update the payment interface
    if (this.screen.payment_interface) {
        this.screen.payment_interface.update_payment_summary({
            total: this.state.totalWithInterest,
            total_paid: paid,
            remaining: remaining,
        });
    }

    // Force a screen re-render
    this.screen.render(true);
}

2. Update numberBuffer

Ensure the numberBuffer is synchronized with the recalculated totals:

if (this.screen.numberBuffer) {
    this.screen.numberBuffer.reset();
    this.screen.numberBuffer.set(this.state.totalWithInterest.toString());
}

3. Explicitly Recalculate and Update Totals

After updating the installments, ensure the order data is fully recalculated:

this.currentOrder.recomputeOrderData();
this.state.totalWithInterest = this.currentOrder.amount_total;
this._forcePaymentSummaryUpdate();

4. Force Global State Updates

If the state changes are not propagating correctly, add a mechanism to trigger a global update:

this.env.pos.trigger('update-screen');

Final Checks

Ensure that:

  1. POS Dependencies: There are no broken dependencies or modifications in your POS module that might prevent updates.
  2. Order and Lines: Update methods like recomputeOrderData are being called at the right time.
  3. Custom Events: If needed, create custom events to trigger component updates.

Enable Detailed Logging

If the issue persists, enable detailed logging to pinpoint where the state changes are not propagating correctly. For example:

console.log('Current State:', this.state);
console.log('Order Total:', this.currentOrder.amount_total);
console.log('Payment Lines:', this.currentOrder.payment_ids);

This will help isolate the problem. Tell me if it helped you.... 

by chatGPT





Another answer (outra resposta):


Analisando o código fornecido, posso identificar o problema e sugerir uma correção. O principal motivo pelo qual o sumário de pagamento não está atualizando automaticamente é devido à forma como as atualizações de estado estão sendo manipuladas.


(By analyzing the code provided, I can identify the problem and suggest a fix. The main reason the payment summary is not updating automatically is due to the way state updates are being handled.)


class CardsPaymentHandler {
    async onCardBrandChange(ev) {
        const cardBrand = ev.target.value;
        this._resetPrices();
       
        if (!cardBrand) {
            this._resetState();
            return;
        }

        try {
            const amount = this.currentOrder.get_total_with_tax();
            const installments = await rpc('/pos_payment_method/get_installments', {
                payment_method_id: CARDS_PAYMENT_METHOD_ID,
                card_brand: cardBrand,
                amount: amount
            });

            if (!installments) {
                throw new Error('Não há plano de parcelamento disponível.');
            }

            this.state.selectedCardBrand = cardBrand;
            this.state.installmentOptions = this._formatInstallmentOptions(installments);
            this._triggerUpdate();  // Nova função para garantir atualização
        } catch (error) {
            this._resetState();
            this.showError('Erro ao carregar parcelas');
        }
    }

    onInstallmentChange(ev) {
        const installments = ev.target.value;
        const option = this.state.installmentOptions.find(
            opt => opt.installments.toString() === installments
        );

        if (!option) return;

        try {
            Object.assign(this.state, {
                selectedInstallments: option.installments,
                installmentAmount: parseFloat(option.amount),
                totalWithInterest: parseFloat(option.total),
                interestRate: parseFloat(option.rate)
            });

            if (typeof option.coefficient === 'number' && !isNaN(option.coefficient)) {
                this._updateOrderLinesWithInterest(option.coefficient);
                this._updatePaymentLine(this.state.totalWithInterest);  // Atualiza linha de pagamento
            }
           
            this._triggerUpdate();  // Força atualização completa
        } catch (error) {
            this.showError('Erro ao processar alteração de parcelas');
        }
    }

    _updatePaymentLine(amount) {
        if (this.selectedPaymentLine) {
            this.selectedPaymentLine.amount = amount;
            this.selectedPaymentLine.set_payment_status("done");
        }
    }

    _triggerUpdate() {
        // Nova função para garantir atualização completa
        this._updatePaymentSummary();
        this.screen.render();
       
        // Força atualização do componente pai
        if (this.screen.props.update) {
            this.screen.props.update();
        }
       
        // Atualiza o buffer numérico se necessário
        if (this.screen.numberBuffer) {
            this.screen.numberBuffer.set(this.state.totalWithInterest.toString());
        }
    }

    _updatePaymentSummary() {
        if (!this.currentOrder) return;

        const totalWithInterest = this.state.totalWithInterest || this.currentOrder.get_total_with_tax();
        const paid = this.currentOrder.get_total_paid();
        const remaining = Math.max(totalWithInterest - paid, 0);

        // Atualiza o estado do pedido
        this.currentOrder.set_total_with_tax(totalWithInterest);

        // Atualiza o estado da tela
        Object.assign(this.screen.state, {
            totalAmount: totalWithInterest,
            remainingAmount: remaining,
            paymentLines: [...this.currentOrder.payment_ids]
        });

        // Atualiza a interface de pagamento
        this.screen.payment_interface.update_payment_summary({
            total: totalWithInterest,
            total_paid: paid,
            remaining: remaining
        });
    }
}

export default CardsPaymentHandler;


As principais correções e melhorias implementadas são:


Criação do método _triggerUpdate() para centralizar todas as atualizações necessárias

Melhor gerenciamento do estado e atualizações da interface

Atualização consistente da linha de pagamento

Tratamento mais robusto dos valores com juros

Garantia de que o sumário de pagamento seja sempre atualizado


Principais mudanças:


Centralização das atualizações em um único método _triggerUpdate()

Melhor tratamento das atualizações do numberBuffer

Adição de verificações de segurança para evitar erros

Garantia de que o componente pai seja notificado das mudanças

Atualização consistente do estado do pedido e da interface


Para implementar esta correção, você precisará:


Substituir seu código atual pelo novo

Certificar-se de que a classe está sendo corretamente exportada

Verificar se todas as dependências estão disponíveis

Testar especialmente os cenários de alteração de parcelas


(The main corrections and improvements implemented are:


Creation of the _triggerUpdate() method to centralize all necessary updates

Better state management and interface updates

Consistent payline update

More robust treatment of interest-bearing amounts

Ensuring that the payment summary is always updated


Main changes:


Centralization of updates in a single _triggerUpdate() method

Better handling of numberBuffer updates

Adding security checks to prevent errors

Ensuring that the parent component is notified of changes

Consistent order and interface state update


To implement this fix, you will need:


Replace your current code with the new one

Make sure the class is being exported correctly

Check if all dependencies are available

Specially test installment change scenarios.)

By Claude.ai

0
Ảnh đại diện
Huỷ bỏ
Tiago de Freitas Gomes

EI Diego!

Estou buscando uma solução para oferecer parcelamentos no meu site.
Estou no Brasil e aqui não existe a possibilidade de um e-commerce não oferecer parcelamento. Descobri esta semana que o Odoo tem essa limitação e fiquei bem desapontado.

Tenho resolvido muitos problemas dentro do Odoo com o auxílio das iAs, mas como não estou programando, não consigo checar se essas soluções funcionariam.

Seguirei acompanhando o seu post.

Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Bài viết liên quan Trả lời Lượt xem Hoạt động
OWL Component Not Rendering in Custom Layout (Odoo 18) — Likely XML Template Issue
javascript development project debug
Ảnh đại diện
Ảnh đại diện
1
thg 7 25
3389
How can I use my only web url domain using odoo?
javascript development
Ảnh đại diện
Ảnh đại diện
1
thg 9 25
1199
Service worker `fetch` fails in `install` event when trying to cache assets
webclient javascript development sales chrome
Ảnh đại diện
Ảnh đại diện
2
thg 9 25
929
Automatically create a task and timesheet lines from a confirmed quotation in Odoo 17? Đã xử lý
sales project
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
2
thg 10 25
2478
How to Load Related Many2Many Data (pos.ticket.type) into the Frontend?
javascript development
Ảnh đại diện
0
thg 6 25
1613
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now