From b22082ac8e64db704bc28466bc6b6bdd702ad373 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 15 Jul 2016 17:22:24 +0200 Subject: [PATCH] [FIX] website_sale: stop using field before its creation Since using new api for the website_sale module with commit 788c1334e2cbe26fa26d4c6d4974dc413dbff608, 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 --- addons/website_sale/models/product.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index 8941071eaac..f429b0930d1 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -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):