diff --git a/stock_analysis_forecast/models/report_stock_forecast.py b/stock_analysis_forecast/models/report_stock_forecast.py index 6d19757..884b52c 100644 --- a/stock_analysis_forecast/models/report_stock_forecast.py +++ b/stock_analysis_forecast/models/report_stock_forecast.py @@ -21,21 +21,25 @@ class ReportStockForecast(models.Model): outgoing_quantity = fields.Float(readonly=True) location_id = fields.Many2one( 'stock.location', string='Location', readonly=True) + categ_id = fields.Many2one( + 'product.category', string='Category', readonly=True) def init(self, cr): tools.drop_view_if_exists(cr, 'report_stock_forecast') cr.execute("""CREATE OR REPLACE VIEW report_stock_forecast AS (SELECT - MIN(id) AS id, + MIN(FINAL.id) AS id, product_id AS product_id, date AS date, sum(product_qty) AS quantity, sum(in_quantity) AS incoming_quantity, sum(out_quantity) AS outgoing_quantity, - location_id + location_id, + categ.id AS categ_id FROM (SELECT MIN(id) AS id, MAIN.product_id AS product_id, + MAIN.product_tmpl_id as product_tmpl_id, MAIN.location_id AS location_id, MAIN.date AS date, sum(MAIN.product_qty) AS product_qty, @@ -45,6 +49,7 @@ class ReportStockForecast(models.Model): (SELECT MIN(sq.id) AS id, sq.product_id, + product_product.product_tmpl_id, date_trunc( 'day', to_date(to_char(CURRENT_DATE, 'YYYY/MM/DD'), @@ -61,11 +66,12 @@ class ReportStockForecast(models.Model): stock_location location_id ON sq.location_id = location_id.id WHERE location_id.usage = 'internal' - GROUP BY date, sq.product_id, sq.location_id + GROUP BY date, sq.product_id, sq.location_id, product_product.product_tmpl_id UNION ALL SELECT MIN(-sm.id) AS id, sm.product_id, + product_product.product_tmpl_id, date_trunc( 'day', to_date(to_char(sm.date_expected, 'YYYY/MM/DD'), @@ -89,11 +95,12 @@ class ReportStockForecast(models.Model): sm.state IN ('confirmed','assigned','waiting') AND source_location.usage != 'internal' AND dest_location.usage = 'internal' - GROUP BY sm.date_expected, sm.product_id, dest_location.id + GROUP BY sm.date_expected, sm.product_id, dest_location.id, product_product.product_tmpl_id UNION ALL SELECT MIN(-sm.id) AS id, sm.product_id, + product_product.product_tmpl_id, date_trunc( 'day', to_date(to_char(sm.date_expected, 'YYYY/MM/DD'), @@ -117,8 +124,10 @@ class ReportStockForecast(models.Model): sm.state IN ('confirmed','assigned','waiting') AND source_location.usage = 'internal' AND dest_location.usage != 'internal' - GROUP BY sm.date_expected, sm.product_id, source_location.id) + GROUP BY sm.date_expected, sm.product_id, source_location.id, product_product.product_tmpl_id) AS MAIN - GROUP BY MAIN.product_id, MAIN.date, MAIN.date, MAIN.location_id + GROUP BY MAIN.product_id, MAIN.date, MAIN.location_id, MAIN.product_tmpl_id ) AS FINAL - GROUP BY product_id, date, location_id)""") + JOIN product_template tmpl ON FINAL.product_tmpl_id = tmpl.id + JOIN product_category categ ON tmpl.categ_id = categ.id + GROUP BY product_id, date, location_id, categ.id)""") diff --git a/stock_analysis_forecast/views/report_stock_forecast.xml b/stock_analysis_forecast/views/report_stock_forecast.xml index c82c129..163e478 100644 --- a/stock_analysis_forecast/views/report_stock_forecast.xml +++ b/stock_analysis_forecast/views/report_stock_forecast.xml @@ -26,6 +26,8 @@ + +