acysos / odoo-addons

Addons modules for Odoo
GNU Affero General Public License v3.0
33 stars 63 forks source link

Testing the realestate/featured throws sample larger than population #10

Closed xabispacebiker closed 6 years ago

xabispacebiker commented 6 years ago

Creating the website menu link realestate/featured throws the following error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/odoo/addons/website/models/ir_http.py", line 273, in _handle_exception
    response = super(Http, cls)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_http.py", line 169, in _handle_exception
    return request._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 768, in _handle_exception
    return super(HttpRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_http.py", line 195, in _dispatch
    result = request.dispatch()
  File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 827, in dispatch
    r = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 333, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 101, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 326, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 935, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 506, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/odoo/addons/website_real_estate/controllers/main.py", line 311, in featuredtops
    prueba = random.sample(topss, 6)
  File "/usr/lib/python2.7/random.py", line 323, in sample
    raise ValueError("sample larger than population")
ValueError: sample larger than population

The offending code below:

        top_ids_object = top_obj.search(domain, limit=NPages, offset=pager['offset'])
        tops_ids = set([v[0].id for v in top_ids_object])

        topss = top_obj.browse(tops_ids)

        prueba = random.sample(topss, 6)
        print prueba 

        values = {
            'top' : prueba,
            'companies' : company,
            'pager' : pager,
            'tops' : topss
            }

        return request.render("website_real_estate.featured_tops", values)
acysos commented 6 years ago

This is because there isn't any top marked as featured. We go to put a control that avoid this error is there is not featured top.

Thank you for the advise

acysos commented 6 years ago

Solved