From 9f5de8b1160c991814e10f22985be8a7467f7b6c Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Mon, 28 Jan 2019 09:03:40 +0000 Subject: [PATCH] [IMP] stock, mrp: report forecast cell clickable closes odoo/odoo#30464 --- addons/mrp/report/__init__.py | 1 + addons/mrp/report/report_stock_forecast.py | 26 +++++++++ addons/stock/report/report_stock_forecast.py | 53 ++++++++++++++----- addons/stock/report/report_stock_forecast.xml | 14 ++++- 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 addons/mrp/report/report_stock_forecast.py diff --git a/addons/mrp/report/__init__.py b/addons/mrp/report/__init__.py index c2e895dd1f6..735590415f6 100644 --- a/addons/mrp/report/__init__.py +++ b/addons/mrp/report/__init__.py @@ -2,4 +2,5 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import mrp_report_bom_structure +from . import report_stock_forecast from . import report_stock_rule diff --git a/addons/mrp/report/report_stock_forecast.py b/addons/mrp/report/report_stock_forecast.py new file mode 100644 index 00000000000..4de5b980891 --- /dev/null +++ b/addons/mrp/report/report_stock_forecast.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +from odoo import api, fields, models + + +class ReportStockForecat(models.Model): + _inherit = 'report.stock.forecast' + + production_id = fields.Many2one('mrp.production', string='Manufacturing Order', readonly=True) + + @api.model + def _select(self): + select_query = super(ReportStockForecat, self)._select() + return select_query + ", mo.id AS production_id" + + @api.model + def _left_join(self): + left_join_query = super(ReportStockForecat, self)._left_join() + return left_join_query + """LEFT JOIN + mrp_production mo ON final.reference=mo.name + """ + + @api.model + def _groupby(self): + groupby_query = super(ReportStockForecat, self)._groupby() + return groupby_query + ",mo.id" diff --git a/addons/stock/report/report_stock_forecast.py b/addons/stock/report/report_stock_forecast.py index 1fbfe364d61..59e788ac4b6 100644 --- a/addons/stock/report/report_stock_forecast.py +++ b/addons/stock/report/report_stock_forecast.py @@ -14,19 +14,15 @@ class ReportStockForecat(models.Model): cumulative_quantity = fields.Float(string='Cumulative Quantity', readonly=True) quantity = fields.Float(readonly=True) company_id = fields.Many2one('res.company', string='Company', readonly=True) + picking_id = fields.Many2one('stock.picking', string='Picking', readonly=True) reference = fields.Char('Reference') @api.model_cr def init(self): tools.drop_view_if_exists(self._cr, 'report_stock_forecast') - self._cr.execute("""CREATE or REPLACE VIEW report_stock_forecast AS (SELECT - row_number() OVER (ORDER BY final.date,final.id) AS id, - product_id as product_id, - date(final.date) as date, - sum(product_qty) AS quantity, - sum(sum(product_qty)) OVER (PARTITION BY final.product_id, final.company_id ORDER BY final.date) AS cumulative_quantity, - reference, - final.company_id + query = """ + CREATE or REPLACE VIEW report_stock_forecast AS (SELECT + %s FROM (SELECT MIN(id) as id, @@ -129,12 +125,45 @@ class ReportStockForecat(models.Model): GROUP BY MAIN.product_id,SUB.date, MAIN.date, MAIN.company_id,MAIN.reference ) AS FINAL - LEFT JOIN - stock_picking sp ON final.reference=sp.name + %s WHERE final.product_qty != 0 OR final.reference = 'Starting Inventory' - GROUP BY - product_id,final.date,final.id,final.company_id,final.reference,sp.priority,sp.date,sp.id)""") + %s + ) + """ % (self._select(), self._left_join(), self._groupby()) + self.env.cr.execute(query) + + @api.model + def _select(self): + return """ + row_number() OVER (ORDER BY final.date,final.id) AS id, + final.product_id as product_id, + date(final.date) as date, + sum(final.product_qty) AS quantity, + sum(sum(final.product_qty)) OVER (PARTITION BY final.product_id, final.company_id ORDER BY final.date) AS cumulative_quantity, + reference, + sp.id as picking_id, + final.company_id + """ + + @api.model + def _left_join(self): + return """LEFT JOIN + stock_picking sp ON final.reference=sp.name + """ + + @api.model + def _groupby(self): + return """GROUP BY + final.product_id, + final.date, + final.id, + final.company_id, + final.reference, + sp.priority, + sp.date, + sp.id + """ @api.model def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): diff --git a/addons/stock/report/report_stock_forecast.xml b/addons/stock/report/report_stock_forecast.xml index e25e00acd50..06af85dc0df 100644 --- a/addons/stock/report/report_stock_forecast.xml +++ b/addons/stock/report/report_stock_forecast.xml @@ -5,7 +5,7 @@ Stock.forecast.pivot report.stock.forecast - + @@ -14,6 +14,18 @@ + + Stock.forecast.tree + report.stock.forecast + + + + + + + + + view.stock.level.forecast.filter report.stock.forecast