mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
Backport of report.stock.forecast from Odoo v9
This commit is contained in:
56
stock_analysis_forecast/README.rst
Normal file
56
stock_analysis_forecast/README.rst
Normal file
@@ -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
|
||||
<https://github.com/OCA/stock-logistics-reporting/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Odoo SA <https://www.odoo.com>
|
||||
* Alex Comba <alex.comba@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.**
|
||||
|
||||
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.
|
||||
6
stock_analysis_forecast/__init__.py
Normal file
6
stock_analysis_forecast/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Odoo SA <https://www.odoo.com>
|
||||
# Copyright 2016 Alex Comba - Agile Business Group
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
22
stock_analysis_forecast/__openerp__.py
Normal file
22
stock_analysis_forecast/__openerp__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Odoo SA <https://www.odoo.com>
|
||||
# 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',
|
||||
],
|
||||
}
|
||||
6
stock_analysis_forecast/models/__init__.py
Normal file
6
stock_analysis_forecast/models/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Odoo SA <https://www.odoo.com>
|
||||
# Copyright 2016 Alex Comba - Agile Business Group
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import report_stock_forecast
|
||||
141
stock_analysis_forecast/models/report_stock_forecast.py
Normal file
141
stock_analysis_forecast/models/report_stock_forecast.py
Normal file
@@ -0,0 +1,141 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Odoo SA <https://www.odoo.com>
|
||||
# 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)""")
|
||||
BIN
stock_analysis_forecast/static/description/icon.png
Normal file
BIN
stock_analysis_forecast/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
47
stock_analysis_forecast/views/report_stock_forecast.xml
Normal file
47
stock_analysis_forecast/views/report_stock_forecast.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2016 Odoo SA <https://www.odoo.com>
|
||||
Copyright 2016 Alex Comba - Agile Business Group
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_stock_level_forecast_pivot" model="ir.ui.view">
|
||||
<field name="name">Stock.forecast.pivot</field>
|
||||
<field name="model">report.stock.forecast</field>
|
||||
<field name="arch" type="xml">
|
||||
<graph string="Stock Level forecast" type="pivot" stacked="True">
|
||||
<field name="product_id" type="row"/>
|
||||
<field name="quantity" type="measure"/>
|
||||
</graph>
|
||||
</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>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Stock Level forecast">
|
||||
<field name="product_id"/>
|
||||
<field name="date"/>
|
||||
<group expand="1" string="Group By">
|
||||
<filter string="Pivot" name="pivot_by" context="{'row_group_by': ['product_id'], 'col_group_by': ['date:week'],'measures': ['quantity']}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_stock_level_forecast_report_product" model="ir.actions.act_window">
|
||||
<field name="name">Stock Level Forecast</field>
|
||||
<field name="res_model">report.stock.forecast</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">graph</field>
|
||||
<field name="search_view_id" ref="view_stock_level_forecast_filter"/>
|
||||
<field name="context">{'search_default_pivot_by':1}</field>
|
||||
<field name="view_id" ref="view_stock_level_forecast_pivot"/>
|
||||
</record>
|
||||
|
||||
<menuitem parent="stock.next_id_61" action="action_stock_level_forecast_report_product" id="menu_report_action_stock_level_forecast_report_product"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user