Se rendre au contenu
Menu
Cette question a été signalée
4 Réponses
3276 Vues

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
Ignorer
Meilleure réponse

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

Avatar
Ignorer
Auteur

you are welcome

Meilleure réponse

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
Ignorer
Auteur Meilleure réponse

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
Ignorer

thank you sir

Auteur

you are welcome

Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
1
nov. 24
1054
0
oct. 22
5056
0
sept. 22
38
1
mars 15
6705
2
janv. 25
915