Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
3294 Vistas

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
Descartar
Mejor respuesta

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

Avatar
Descartar
Autor

you are welcome

Mejor respuesta

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
Descartar
Autor Mejor respuesta

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
Descartar

thank you sir

Autor

you are welcome

Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 24
1071
0
oct 22
5061
0
sept 22
38
1
mar 15
6713
2
ene 25
918