mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[FIX] stock_average_daily_sale: Use a new cursor to avoid closed one
This commit is contained in:
committed by
twalter-c2c
parent
8ecd2cd37e
commit
171fd862a4
@@ -6,7 +6,7 @@ import logging
|
|||||||
from psycopg2.errors import ObjectNotInPrerequisiteState
|
from psycopg2.errors import ObjectNotInPrerequisiteState
|
||||||
from psycopg2.extensions import AsIs
|
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 (
|
from odoo.addons.stock_storage_type_putaway_abc.models.stock_location import (
|
||||||
ABC_SELECTION,
|
ABC_SELECTION,
|
||||||
@@ -101,8 +101,9 @@ class StockAverageDailySale(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def _check_view(self):
|
def _check_view(self):
|
||||||
try:
|
try:
|
||||||
with self.env.cr.savepoint():
|
cr = registry(self._cr.dbname).cursor()
|
||||||
self.env.cr.execute("SELECT COUNT(1) FROM %s", (AsIs(self._table),))
|
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
|
return True
|
||||||
except ObjectNotInPrerequisiteState:
|
except ObjectNotInPrerequisiteState:
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
@@ -111,6 +112,8 @@ class StockAverageDailySale(models.Model):
|
|||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
finally:
|
||||||
|
new_self.env.cr.close()
|
||||||
|
|
||||||
# pylint: disable=redefined-outer-name
|
# pylint: disable=redefined-outer-name
|
||||||
@api.model
|
@api.model
|
||||||
|
|||||||
@@ -218,3 +218,9 @@ class TestAverageSale(CommonAverageSaleTest, TransactionCase):
|
|||||||
str("The materialized view has not been populated. Launch the cron."),
|
str("The materialized view has not been populated. Launch the cron."),
|
||||||
str(logger.output),
|
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,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user