Skip to Content
Menu
This question has been flagged
4 Replies
3277 Zobrazenia

I want to add a product line in POS but I face some errors

this my code

                const productId = 293;
                const sel_product = await this.rpc({
                    model: "product.product",
                    method: "read",
                    args: [[productId]],
                });

                console.log("sel_product :", sel_product[0]);
                const newItem = {
                    id: productId,
                    product: sel_product[0],
                    qty: 1,
                    price: -300,
                };

                var Orderline = models.Orderline;
                var line = new Orderline({}, {
                      pos: this.env.pos,
                      order: this.env.pos.get_order(),
                      product: newItem.product});

                line.set_quantity(newItem.qty);
                this.env.pos.get_order().add_product(line);

and I face some error

error fetching promotions: TypeError: this.product.get_unit is not a function at Orderline.get_unit at Orderline.set_quantity

can any one help me on this


Avatar
Zrušiť
Best Answer

Thank you very much, I searched a lot for the solution and I found it here

Avatar
Zrušiť
Autor

you are welcome

Best Answer

Hi,

In the Odoo 16 Point of Sale module, you can pass an object to specify options such as price, discount, and quantity when adding a product to the order. This eliminates the need for calling the set_quantity() function separately. Here's an example code snippet:

const productId = 293;
var order = this.env.pos.get_order();
var product = this.env.pos.db.get_product_by_id(product_id);
var options = {
   discount: 0,
   merge: false,
   price: -300,
   quantity: 1,
   tax_ids: []
};

if (product){
    order.add_product(product, options);
}


Hope it helps

Avatar
Zrušiť
Autor Best Answer

I found a solution, 
may pe it will help 

this code 

 

var product = this.env.pos.db.get_product_by_id(productId);
var order = this.env.pos.get_order();
if (product) {
order.add_product(product);
} else {
console.error("Error Not there");
}


put the problem if the productId belongs to one of the products in the order It's coming and if the productId does not belong to it's giving me undefined

can any one help me 

 


Avatar
Zrušiť

thank you sir

Autor

you are welcome

Best Answer

As an addition to the answers above, if the product is not loaded in the POS yet, we can load it first using this code

var product = this.env.pos.db.get_product_by_id(line.product_id);                    if (!product) {                        
// If product is not loaded in POS, load it
await this.env.pos._addProducts([line.product_id]);
// Assume that the result is unique.
product = this.env.pos.db.get_product_by_id(line.product_id);
}
Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
1
nov 24
1054
0
okt 22
5056
0
sep 22
38
1
mar 15
6705
2
jan 25
915