Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
260 Tampilan

const filtered_lines = this.pos.get_order().lines

            // Step 1: Get all product IDs from refundLines

            const refundProductIds = new Set();

            const refundOrder = this.pos.add_new_order();

            for (const refundLine of refundLines) {

                // refundLine format: [0, 0, { product_id: ... }]

                const productId = refundLine[2].product_id;

                refundProductIds.add(productId);

            }


            // Step 2: Filter and update the lines

            const updatedLines = [];

            for (const line of filtered_lines) {

                const productId = line.product_id?.id || (line.product && line.product.id);

                if (productId && refundProductIds.has(productId)) {

                    // Find the refund quantity for this product

                    const refundEntry = refundLines.find(r => r[2].product_id === productId);

                    const refundQty = refundEntry ? refundEntry[2].qty : 0;

                    // Create a copy of the line with ONLY qty updated

                    updatedLines.push({

                        ...line,                 // Copy all existing fields

                        qty: refundQty           // Override qty with refund value

                    });

                    // this.pos.addLineToCurrentOrder({

                    //     ...line,                 // Copy all existing fields

                    //     qty: refundQty           // Override qty with refund value

                    // })

                }

            }



updatedLines.forEach(updatedLine => {

    this.pos.addLineToCurrentOrder(updatedLine);

});

Hello! I am trying to add lines to odoo pos order lines in pos_screen but this only adding first selected products somehow. 
I am filtering selected orders from order.lines and copying all data from it

Avatar
Buang
Jawaban Terbai

Hii,
Try this code 
const refundProductIds = new Set();

const refundQtyMap = new Map();  // map product_id → qty


// 1. Build refund product ID map

for (const refundLine of refundLines) {

    const productId = refundLine[2].product_id;

    refundProductIds.add(productId);

    refundQtyMap.set(productId, refundLine[2].qty);

}


// 2. Create a new order

const refundOrder = this.pos.add_new_order();


// 3. Loop through existing lines and match

const orderLines = this.pos.get_order().get_orderlines();


for (const line of orderLines) {

    const product = line.get_product();

    const productId = product?.id;


    if (refundProductIds.has(productId)) {

        const qty = refundQtyMap.get(productId);


        // Add a new line using pos.add_product()

        refundOrder.add_product(product, {

            quantity: qty,

            price: line.get_unit_price(),

            discount: line.get_discount(),

            extras: {

                // Add any custom props here if needed

                ref_line_id: line.id, // e.g. store original line reference

            },

        });

    }

}

i hope it is usefull

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Jun 25
463
3
Apr 25
978
1
Agu 24
1754
3
Mei 24
10912
1
Sep 23
3332