diff --git a/stock_analysis_forecast/README.rst b/stock_analysis_forecast/README.rst index fc597d2..2b1b826 100644 --- a/stock_analysis_forecast/README.rst +++ b/stock_analysis_forecast/README.rst @@ -6,7 +6,17 @@ Stock Analysis Forecast ======================= -Backport (with adjustments) of the report_stock_forecast analysis view of Odoo 9. +Backport (with improvements) of the report_stock_forecast analysis view of Odoo 9. + +By default, it adds a pivot table grouped by date where lines are products and columns are locations. +Each column is further divided into Quantity, Incoming quantity and Outgoing quantity. +Quantity column doesn't take into account incoming and outgoing quantities. + +See example: + +.. figure:: static/description/forecast.png + :width: 600 px + :alt: Sample forecast report Usage ===== @@ -36,6 +46,7 @@ Contributors * Odoo SA * Alex Comba +* Lorenzo Battistini **This module is a backport from Odoo SA and as such, it is not included in the OCA CLA. That means we do not have a copy of the copyright on it like all other OCA modules.** diff --git a/stock_analysis_forecast/__openerp__.py b/stock_analysis_forecast/__openerp__.py index c8060c3..fd8e8fe 100644 --- a/stock_analysis_forecast/__openerp__.py +++ b/stock_analysis_forecast/__openerp__.py @@ -5,12 +5,13 @@ { 'name': 'Stock Analysis Forecast', - 'summary': """ - Analysis wiew for stock forecast""", + 'summary': "Analysis wiew for stock forecast", 'version': '8.0.1.0.0', - 'category': 'Inventory, Logistic, Storage', + 'category': 'Warehouse Management', 'license': 'LGPL-3', - 'author': 'Agile Business Group, Odoo Community Association (OCA)', + 'author': 'Odoo S.A,' + 'Agile Business Group,' + 'Odoo Community Association (OCA)', 'website': 'https://www.agilebg.com', 'depends': [ 'product', diff --git a/stock_analysis_forecast/models/report_stock_forecast.py b/stock_analysis_forecast/models/report_stock_forecast.py index 054959f..5312d2a 100644 --- a/stock_analysis_forecast/models/report_stock_forecast.py +++ b/stock_analysis_forecast/models/report_stock_forecast.py @@ -19,6 +19,8 @@ class ReportStockForecast(models.Model): quantity = fields.Float(readonly=True) incoming_quantity = fields.Float(readonly=True) outgoing_quantity = fields.Float(readonly=True) + location_id = fields.Many2one( + 'stock.location', string='Location', readonly=True) def init(self, cr): tools.drop_view_if_exists(cr, 'report_stock_forecast') @@ -28,11 +30,13 @@ class ReportStockForecast(models.Model): date as date, sum(product_qty) AS quantity, sum(in_quantity) AS incoming_quantity, - sum(out_quantity) AS outgoing_quantity + sum(out_quantity) AS outgoing_quantity, + location_id FROM (SELECT MIN(id) as id, MAIN.product_id as product_id, + MAIN.location_id as location_id, SUB.date as date, CASE WHEN MAIN.date = SUB.date THEN sum(MAIN.product_qty) ELSE 0 END as product_qty, @@ -50,7 +54,8 @@ class ReportStockForecast(models.Model): 'YYYY/MM/DD')) as date, SUM(sq.qty) AS product_qty, 0 AS in_quantity, - 0 AS out_quantity + 0 AS out_quantity, + sq.location_id FROM stock_quant as sq LEFT JOIN @@ -59,7 +64,7 @@ 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 + GROUP BY date, sq.product_id, sq.location_id UNION ALL SELECT MIN(-sm.id) as id, @@ -76,7 +81,8 @@ class ReportStockForecast(models.Model): AS date, 0 AS product_qty, SUM(sm.product_qty) AS in_quantity, - 0 AS out_quantity + 0 AS out_quantity, + dest_location.id as location_id FROM stock_move as sm LEFT JOIN @@ -91,7 +97,7 @@ 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 + GROUP BY sm.date_expected, sm.product_id, dest_location.id UNION ALL SELECT MIN(-sm.id) as id, @@ -108,7 +114,8 @@ class ReportStockForecast(models.Model): AS date, 0 AS product_qty, 0 AS in_quantity, - SUM(sm.product_qty) AS out_quantity + SUM(sm.product_qty) AS out_quantity, + source_location.id as location_id FROM stock_move as sm LEFT JOIN @@ -123,7 +130,7 @@ 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) + GROUP BY sm.date_expected, sm.product_id, source_location.id) as MAIN LEFT JOIN (SELECT DISTINCT date @@ -150,6 +157,6 @@ class ReportStockForecast(models.Model): or (source_location.usage = 'internal' AND dest_location.usage != 'internal'))) AS DATE_SEARCH) SUB ON (SUB.date IS NOT NULL) - GROUP BY MAIN.product_id,SUB.date, MAIN.date + GROUP BY MAIN.product_id,SUB.date, MAIN.date, MAIN.location_id ) AS FINAL - GROUP BY product_id,date)""") + GROUP BY product_id,date, location_id)""") diff --git a/stock_analysis_forecast/static/description/forecast.png b/stock_analysis_forecast/static/description/forecast.png new file mode 100644 index 0000000..abb8e26 Binary files /dev/null and b/stock_analysis_forecast/static/description/forecast.png differ diff --git a/stock_analysis_forecast/views/report_stock_forecast.xml b/stock_analysis_forecast/views/report_stock_forecast.xml index affb033..dd80841 100644 --- a/stock_analysis_forecast/views/report_stock_forecast.xml +++ b/stock_analysis_forecast/views/report_stock_forecast.xml @@ -12,6 +12,7 @@ + @@ -29,7 +30,7 @@