[FIX] website_sale: right number of products in the page
authorDenis Ledoux <dle@odoo.com>
Thu, 23 Oct 2014 12:12:39 +0000 (14:12 +0200)
committerDenis Ledoux <dle@odoo.com>
Thu, 23 Oct 2014 12:14:50 +0000 (14:14 +0200)
The goal is to fill the page with at least 20 products and to fill all grid lines
Thus, the page should be filled with products until there are 20 products and all lines of the grid are full.

addons/website_sale/controllers/main.py

index 060370b..df3ab9b 100644 (file)
@@ -37,14 +37,18 @@ class table_compute(object):
         for p in products:
             x = min(max(p.website_size_x, 1), PPR)
             y = min(max(p.website_size_y, 1), PPR)
-            if index>PPG:
+            if index>=PPG:
                 x = y = 1
 
             pos = minpos
             while not self._check_place(pos%PPR, pos/PPR, x, y):
                 pos += 1
-
-            if index>PPG and (pos/PPR)>maxy:
+            # if 21st products (index 20) and the last line is full (PPR products in it), break
+            # (pos + 1.0) / PPR is the line where the product would be inserted
+            # maxy is the number of existing lines
+            # + 1.0 is because pos begins at 0, thus pos 20 is actually the 21st block
+            # and to force python to not round the division operation
+            if index >= PPG and ((pos + 1.0) / PPR) > maxy:
                 break
 
             if x==1 and y==1:   # simple heuristic for CPU optimization