From d1b7665dbd14d573e94f3c6a41cd98d846bc9f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 7 Jul 2020 23:56:10 +0200 Subject: [PATCH] Add model, record and records attribute on Wizard issue9421 review309861012 --- forecast.py | 19 +++++++------------ tests/test_stock_forecast.py | 3 ++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/forecast.py b/forecast.py index 0198eae0b3..c8bab764ee 100644 --- a/forecast.py +++ b/forecast.py @@ -563,25 +563,21 @@ class ForecastComplete(Wizard): """ Forecast dates shifted by one year. """ - Forecast = Pool().get('stock.forecast') - forecast = Forecast(Transaction().context['active_id']) - - res = {} + default = {} for field in ("to_date", "from_date"): - res[field] = getattr(forecast, field) - relativedelta(years=1) - return res + default[field] = ( + getattr(self.record, field) - relativedelta(years=1)) + return default def _get_product_quantity(self): pool = Pool() - Forecast = pool.get('stock.forecast') Product = pool.get('product.product') - forecast = Forecast(Transaction().context['active_id']) with Transaction().set_context( - stock_destinations=[forecast.destination.id], + stock_destinations=[self.record.destination.id], stock_date_start=self.ask.from_date, stock_date_end=self.ask.to_date): - return Product.products_by_location([forecast.warehouse.id], + return Product.products_by_location([self.record.warehouse.id], with_childs=True) def default_choose(self, fields): @@ -600,11 +596,10 @@ class ForecastComplete(Wizard): def transition_complete(self): pool = Pool() - Forecast = pool.get('stock.forecast') ForecastLine = pool.get('stock.forecast.line') Product = pool.get('product.product') - forecast = Forecast(Transaction().context['active_id']) + forecast = self.record prod2line = {} forecast_lines = ForecastLine.search([ ('forecast', '=', forecast.id), diff --git a/tests/test_stock_forecast.py b/tests/test_stock_forecast.py index 75dddedd18..8d89146c22 100644 --- a/tests/test_stock_forecast.py +++ b/tests/test_stock_forecast.py @@ -303,7 +303,8 @@ class StockForecastTestCase(ModuleTestCase): 'company': company.id, }]) - with Transaction().set_context(active_id=forecast.id): + with Transaction().set_context( + active_model=Forecast.__name__, active_id=forecast.id): session_id, _, _ = ForecastComplete.create() forecast_complete = ForecastComplete(session_id) forecast_complete.ask.from_date = (