javascript Odoo版本14:活动POS会话读取订单和付款行

i5desfxk  于 2023-06-28  发布在  Java
关注(0)|答案(1)|浏览(117)

我正在尝试读取Odoo 14中POS会话中的现金支付总额:
有人能给我指个正确的方向吗:我有以下代码:

get totalCash() {
        // Get order list
            const orders = this.env.pos.get_order_list();
            let totalCash = 0;

        console.log("Order list: ", orders);

        // Iterate over each order
        for (const order of orders) {
            console.log("Order: ", order);

            // Iterate over each payment line of the order
            for (const paymentLine of order.paymentlines.models) {
                console.log("Payment line: ", paymentLine);

                // Check if the payment method is cash
                if (paymentLine.cashregister.journal.type === 'cash') {
                    console.log("Cash register type: ", paymentLine.cashregister.journal.type);
                    console.log("Amount before: ", totalCash);
                    totalCash += paymentLine.amount;
                    console.log("Amount after: ", totalCash);
                }
            }
        }

        return totalCash.toFixed(2);

        }

在控制台中,我的输出如下:对象{ cid:“c49”,属性:{...},_changing:false,_previousAttributes:{...},已更改:{},_pending:false,锁定:假,正:{...},selected_orderline:undefined,selected_paymentline:undefined,...}
所以看起来我找到了对象,但我没有使用正确的名称的付款行。有人知道怎么修吗?
多谢了。

nom7f22z

nom7f22z1#

您可以添加额外的console.log来调查对象内容/结构(订单、paymentLine...),以找到正确的属性名称。更妙的是:使用Web浏览器的JavaScript控制台,在代码中手动添加断点(使用以下命令:调试器)...在浏览器中:通过右键单击网页并选择“检查”或按Ctrl+Shift+I(或Mac上的Cmd+Option+I)打开开发人员工具。

get totalCash() 
    {
    debugger; // Set a breakpoint, to investigate in your Browser
    const orders = this.env.pos.get_order_list();
    let totalCash = 0;

    console.log("Order list: ", orders);

    for (const order of orders) {
        console.log("Order: ", order);

        for (const paymentLine of order.paymentlines.models) {
            console.log("Payment line: ", paymentLine);

            // Check if the payment method is cash
            if (paymentLine.cashregister.journal.type === 'cash') {
                console.log("Cash register type: ", paymentLine.cashregister.journal.type);
                console.log("Amount before: ", totalCash);
                totalCash += paymentLine.amount;
                console.log("Amount after: ", totalCash);
            }
        }
    }

    return totalCash.toFixed(2);
    }

相关问题