0

I am trying to add lines to Odoo pos order lines in pos_screen, but this only adds the first selected products somehow.

I am filtering selected orders from order.lines and copying all data from it. Is there any way to set order in Odoo pos without changing this.pos using only created pos.order id.

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);
});

1 Answer 1

0

addLineToCurrentOrder is an async function, that means you have to await for it to finish

https://github.com/odoo/odoo/blob/18.0/addons/point_of_sale/static/src/app/store/pos_store.js#L652

and a usage example
https://github.com/odoo/odoo/blob/022fcbcf40a28afa56010f6130c26bb0503d5467/addons/pos_discount/static/src/overrides/components/control_buttons/control_buttons.js#L60

Also, have a look at the ...line desctructuring; are all the values in there needed on the new line?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.