[FIX] website_sale: stop using field before its creation

Since using new api for the website_sale module with commit 788c1334e2,
the website_sale module cannot be installed after the sale_stock module
is installed. The problem has not been detected on the runbot as, by
chance, the website_sale module seems to be installed before.

The problem here is that on installation, the _default_website_sequence
method is called to add a default value for the added website_sequence
field. In this method, a search() is done, ordered by this field values
then a read() is performed. The problem is that the read does not use
the given order value and use always the default one, which uses the
website_published field which happens to not be created at that time.

However the creation order of a model fields is difficult to determine
which is why when sale_stock is not installed, the bug does not appear,
the website_published being created, by chance, before calling the
_default_website_sequence method in that case.

To fix the problem, refactore the method by using a SQL query so that
the website_published field is not used. This also makes the method
easier to understand and more efficient.

Thanks to @rco-odoo
This commit is contained in:
qsm-odoo
2016-07-18 12:24:52 +02:00
parent fa9782d24d
commit b22082ac8e
+2 -1
View File
@@ -94,7 +94,8 @@ class ProductTemplate(models.Model):
help="Those categories are used to group similar products for e-commerce.")
def _default_website_sequence(self):
min_sequence = self.sudo().search([], order='website_sequence', limit=1).website_sequence
self._cr.execute("SELECT MIN(website_sequence) FROM %s" % self._table)
min_sequence = self._cr.fetchone()[0]
return min_sequence and min_sequence - 1 or 10
def set_sequence_top(self):