[FIX] stock_average_daily_sale: Use a new cursor to avoid closed one

This commit is contained in:
Denis Roussel
2023-10-11 12:25:07 +02:00
committed by twalter-c2c
parent 8ecd2cd37e
commit 171fd862a4
2 changed files with 12 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ import logging
from psycopg2.errors import ObjectNotInPrerequisiteState
from psycopg2.extensions import AsIs
from odoo import _, api, fields, models
from odoo import _, api, fields, models, registry
from odoo.addons.stock_storage_type_putaway_abc.models.stock_location import (
ABC_SELECTION,
@@ -101,8 +101,9 @@ class StockAverageDailySale(models.Model):
@api.model
def _check_view(self):
try:
with self.env.cr.savepoint():
self.env.cr.execute("SELECT COUNT(1) FROM %s", (AsIs(self._table),))
cr = registry(self._cr.dbname).cursor()
new_self = self.with_env(self.env(cr=cr)) # TDE FIXME
new_self.env.cr.execute("SELECT COUNT(1) FROM %s", (AsIs(self._table),))
return True
except ObjectNotInPrerequisiteState:
_logger.warning(
@@ -111,6 +112,8 @@ class StockAverageDailySale(models.Model):
return False
except Exception as e:
raise e
finally:
new_self.env.cr.close()
# pylint: disable=redefined-outer-name
@api.model

View File

@@ -218,3 +218,9 @@ class TestAverageSale(CommonAverageSaleTest, TransactionCase):
str("The materialized view has not been populated. Launch the cron."),
str(logger.output),
)
# Check if we can still query database
product = self.env["product.product"].search([("id", "=", self.product_1.id)])
self.assertEqual(
product,
self.product_1,
)