[stock_analysis_forecast] Add location_is as col to the pivot table

This commit is contained in:
Alex Comba
2016-09-29 10:31:45 +02:00
parent c534db5ffc
commit acaff72070
5 changed files with 35 additions and 15 deletions

View File

@@ -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 <https://www.odoo.com>
* Alex Comba <alex.comba@agilebg.com>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
**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.**

View File

@@ -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',

View File

@@ -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)""")

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

View File

@@ -12,6 +12,7 @@
<field name="arch" type="xml">
<graph string="Stock Level forecast" type="pivot" stacked="True">
<field name="product_id" type="row"/>
<field name="location_id" type="col"/>
<field name="quantity" type="measure"/>
<field name="incoming_quantity" type="measure"/>
<field name="outgoing_quantity" type="measure"/>
@@ -29,7 +30,7 @@
<group expand="1" string="Group By">
<filter string="Pivot" name="pivot_by"
context="{'row_group_by': ['product_id'],
'col_group_by': ['date:week'],
'col_group_by': ['date:week', 'location_id'],
'measures': ['quantity', 'incoming_quantity', 'outgoing_quantity']}"/>
</group>
</search>