Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
3314 Zobrazení

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šit
Nejlepší odpověď

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

Avatar
Zrušit
Autor

you are welcome

Nejlepší odpověď

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šit
Autor Nejlepší odpověď

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šit

thank you sir

Autor

you are welcome

Nejlepší odpověď

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šit
Related Posts Odpovědi Zobrazení Aktivita
1
lis 24
1083
0
říj 22
5062
0
zář 22
38
1
bře 15
6718
2
led 25
924