diff --git a/stock_analysis_forecast/README.rst b/stock_analysis_forecast/README.rst new file mode 100644 index 0000000..fc597d2 --- /dev/null +++ b/stock_analysis_forecast/README.rst @@ -0,0 +1,56 @@ +.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 + +======================= +Stock Analysis Forecast +======================= + +Backport (with adjustments) of the report_stock_forecast analysis view of Odoo 9. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/151/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Odoo SA +* Alex Comba + +**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.** + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/stock_analysis_forecast/__init__.py b/stock_analysis_forecast/__init__.py new file mode 100644 index 0000000..2ed881c --- /dev/null +++ b/stock_analysis_forecast/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Odoo SA +# Copyright 2016 Alex Comba - Agile Business Group +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_analysis_forecast/__openerp__.py b/stock_analysis_forecast/__openerp__.py new file mode 100644 index 0000000..c8060c3 --- /dev/null +++ b/stock_analysis_forecast/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Odoo SA +# Copyright 2016 Alex Comba - Agile Business Group +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + 'name': 'Stock Analysis Forecast', + 'summary': """ + Analysis wiew for stock forecast""", + 'version': '8.0.1.0.0', + 'category': 'Inventory, Logistic, Storage', + 'license': 'LGPL-3', + 'author': 'Agile Business Group, Odoo Community Association (OCA)', + 'website': 'https://www.agilebg.com', + 'depends': [ + 'product', + 'stock', + ], + 'data': [ + 'views/report_stock_forecast.xml', + ], +} diff --git a/stock_analysis_forecast/models/__init__.py b/stock_analysis_forecast/models/__init__.py new file mode 100644 index 0000000..c798bb1 --- /dev/null +++ b/stock_analysis_forecast/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Odoo SA +# Copyright 2016 Alex Comba - Agile Business Group +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import report_stock_forecast diff --git a/stock_analysis_forecast/models/report_stock_forecast.py b/stock_analysis_forecast/models/report_stock_forecast.py new file mode 100644 index 0000000..e80339a --- /dev/null +++ b/stock_analysis_forecast/models/report_stock_forecast.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Odoo SA +# Copyright 2016 Alex Comba - Agile Business Group +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import fields, models, tools + + +class ReportStockForecast(models.Model): + + _name = 'report.stock.forecast' + _description = 'Report Stock Forecast' + _auto = False + + date = fields.Date( + string='Date') + product_id = fields.Many2one( + 'product.product', string='Product', readonly=True) + quantity = fields.Float(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, + product_id as product_id, + date as date, + sum(product_qty) AS quantity + FROM + (SELECT + MIN(id) as id, + MAIN.product_id as product_id, + SUB.date as date, + CASE WHEN MAIN.date = SUB.date + THEN sum(MAIN.product_qty) ELSE 0 END as product_qty + FROM + (SELECT + MIN(sq.id) as id, + sq.product_id, + date_trunc( + 'week', + to_date(to_char(CURRENT_DATE, 'YYYY/MM/DD'), + 'YYYY/MM/DD')) as date, + SUM(sq.qty) AS product_qty + FROM + stock_quant as sq + LEFT JOIN + product_product ON product_product.id = sq.product_id + LEFT JOIN + stock_location location_id ON sq.location_id = location_id.id + WHERE + location_id.usage = 'internal' + GROUP BY date, sq.product_id + UNION ALL + SELECT + MIN(-sm.id) as id, + sm.product_id, + CASE WHEN sm.date_expected > CURRENT_DATE + THEN date_trunc( + 'week', + to_date(to_char(sm.date_expected, 'YYYY/MM/DD'), + 'YYYY/MM/DD')) + ELSE date_trunc( + 'week', + to_date( + to_char(CURRENT_DATE, 'YYYY/MM/DD'), 'YYYY/MM/DD')) END + AS date, + SUM(sm.product_qty) AS product_qty + FROM + stock_move as sm + LEFT JOIN + product_product ON product_product.id = sm.product_id + LEFT JOIN + stock_location dest_location + ON sm.location_dest_id = dest_location.id + LEFT JOIN + stock_location source_location + ON sm.location_id = source_location.id + WHERE + sm.state IN ('confirmed','assigned','waiting') and + source_location.usage != 'internal' and + dest_location.usage = 'internal' + GROUP BY sm.date_expected,sm.product_id + UNION ALL + SELECT + MIN(-sm.id) as id, + sm.product_id, + CASE WHEN sm.date_expected > CURRENT_DATE + THEN date_trunc( + 'week', + to_date(to_char(sm.date_expected, 'YYYY/MM/DD'), + 'YYYY/MM/DD')) + ELSE date_trunc( + 'week', + to_date(to_char(CURRENT_DATE, 'YYYY/MM/DD'), + 'YYYY/MM/DD')) END + AS date, + SUM(-(sm.product_qty)) AS product_qty + FROM + stock_move as sm + LEFT JOIN + product_product ON product_product.id = sm.product_id + LEFT JOIN + stock_location source_location + ON sm.location_id = source_location.id + LEFT JOIN + stock_location dest_location + ON sm.location_dest_id = dest_location.id + WHERE + sm.state IN ('confirmed','assigned','waiting') and + source_location.usage = 'internal' and + dest_location.usage != 'internal' + GROUP BY sm.date_expected,sm.product_id) + as MAIN + LEFT JOIN + (SELECT DISTINCT date + FROM + ( + SELECT date_trunc('week', CURRENT_DATE) AS DATE + UNION ALL + SELECT date_trunc( + 'week', + to_date(to_char(sm.date_expected, 'YYYY/MM/DD'), + 'YYYY/MM/DD')) AS date + FROM stock_move sm + LEFT JOIN + stock_location source_location + ON sm.location_id = source_location.id + LEFT JOIN + stock_location dest_location + ON sm.location_dest_id = dest_location.id + WHERE + sm.state IN ('confirmed','assigned','waiting') and + sm.date_expected > CURRENT_DATE and + ((dest_location.usage = 'internal' + AND source_location.usage != 'internal') + 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 + ) AS FINAL + GROUP BY product_id,date)""") diff --git a/stock_analysis_forecast/static/description/icon.png b/stock_analysis_forecast/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/stock_analysis_forecast/static/description/icon.png differ diff --git a/stock_analysis_forecast/views/report_stock_forecast.xml b/stock_analysis_forecast/views/report_stock_forecast.xml new file mode 100644 index 0000000..4bedf91 --- /dev/null +++ b/stock_analysis_forecast/views/report_stock_forecast.xml @@ -0,0 +1,47 @@ + + + + + + + + Stock.forecast.pivot + report.stock.forecast + + + + + + + + + + view.stock.level.forecast.filter + report.stock.forecast + + + + + + + + + + + + + Stock Level Forecast + report.stock.forecast + form + graph + + {'search_default_pivot_by':1} + + + + + + +