Skip to Content
Menu
This question has been flagged
4 Replies
3275 Rodiniai

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


Portretas
Atmesti
Best Answer

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

Portretas
Atmesti
Autorius

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

Portretas
Atmesti
Autorius 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 

 


Portretas
Atmesti

thank you sir

Autorius

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);
}
Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
lapkr. 24
1054
0
spal. 22
5056
0
rugs. 22
38
1
kov. 15
6703
2
saus. 25
915