| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -14,19 +14,43 @@ patch(Orderline.prototype,  { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//      Checking the orderline quantity and onhand lot quantity
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        super.set_quantity(quantity, keep_price); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        var lines = await this.get_lot_lines() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        var pos_config_id = this.pos.config.id | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if(lines.length){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            var product_id = this.get_product().id | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            var lot_name = lines[0].lot_name | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            var lot_name = lines.map(line => line.lot_name).pop(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            const result = await this.pos.orm.call( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "stock.lot", "get_available_lots_qty_pos", [product_id, lot_name], {} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                "stock.lot", "get_available_lots_qty_pos", [product_id, lot_name, pos_config_id], {} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (result != 0 && lines.length == 1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (quantity > result) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                this.quantity = result | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    this.quantity = result; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    await this.env.services.popup.add(CustomButtonPopup, { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        title: _t("Exception"), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        body: _t("Product quantity Exceeding the allowed lot quantity") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } else if (result == 0) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                const order = this.pos.get_order(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                const selectedLine = order.get_selected_orderline(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                selectedLine.stock = result; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (quantity === 1 && lines.length >= 1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    order._unlinkOrderline(selectedLine); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                else if (quantity >=1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    const Length = selectedLine.pack_lot_lines.length | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    const LastLine = selectedLine.pack_lot_lines[Length - 1] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    selectedLine.pack_lot_lines.remove(LastLine) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    selectedLine.set_quantity(quantity - 1, keep_price) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                this.env.services.popup.add(ErrorPopup, { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        title: _t("No Stock Available"), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        body: _t( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            "The requested lot:" + lot_name + "is currently out of stock." | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        ), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    }); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                browser.location.reload() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					}); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |