[IMP] stock, mrp: report forecast cell clickable

closes odoo/odoo#30464
This commit is contained in:
Arnold Moyaux
2019-02-12 12:12:14 +00:00
parent d3f14f6a1d
commit 9f5de8b116
4 changed files with 81 additions and 13 deletions
+1
View File
@@ -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
@@ -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"
+41 -12
View File
@@ -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):
+13 -1
View File
@@ -5,7 +5,7 @@
<field name="name">Stock.forecast.pivot</field>
<field name="model">report.stock.forecast</field>
<field name="arch" type="xml">
<pivot string="Stock Level forecast" disable_linking="True">
<pivot string="Stock Level forecast">
<field name="product_id" type="row"/>
<field name="date" type="col"/>
<field name="quantity" type="measure"/>
@@ -14,6 +14,18 @@
</field>
</record>
<record id="view_stock_level_forecast_tree" model="ir.ui.view">
<field name="name">Stock.forecast.tree</field>
<field name="model">report.stock.forecast</field>
<field name="arch" type="xml">
<tree string="Stock Inventory Lines">
<field name="reference"/>
<field name="date"/>
<field name="quantity"/>
</tree>
</field>
</record>
<record id="view_stock_level_forecast_filter" model="ir.ui.view">
<field name="name">view.stock.level.forecast.filter</field>
<field name="model">report.stock.forecast</field>