[ADD] stock_forecast_report: Backport from 14.0

This commit is contained in:
david
2021-03-05 18:35:03 +01:00
parent 3884c12234
commit 9bef553152
16 changed files with 942 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
=====================
Stock Forecast Report
=====================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_forecast_report
:alt: OCA/stock-logistics-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-reporting-12-0/stock-logistics-reporting-12-0-stock_forecast_report
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/151/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module backports the stock forecast report from v14.
.. image:: https://raw.githubusercontent.com/OCA/stock-logistics-reporting/12.0/stock_forecast_report/static/description/screenshot_stock_forecast.png
**Table of contents**
.. contents::
:local:
Usage
=====
To use this module, you need to:
#. Go to *Inventory > Reports > Forecasted Inventory*
Known issues / Roadmap
======================
* This is a backport from the 14.0 Odoo core forecast report.
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 <https://github.com/OCA/stock-logistics-reporting/issues/new?body=module:%20stock_forecast_report%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Tecnativa
Contributors
~~~~~~~~~~~~
* `Tecnativa <https://www.tecnativa.com>`_:
* David Vidal
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
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.
This module is part of the `OCA/stock-logistics-reporting <https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_forecast_report>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -0,0 +1 @@
from . import reports

View File

@@ -0,0 +1,19 @@
# Copyright 2021 Odoo S.A.
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Forecast Report",
"summary": "Backport of core 14.0 Forecast Report",
"version": "12.0.1.0.0",
"category": "Inventory",
"website": "https://github.com/OCA/stock-logistics-reporting",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["stock"],
"data": [
"reports/report_stock_quantity.xml",
"security/ir.model.access.csv",
],
}

View File

@@ -0,0 +1,3 @@
* `Tecnativa <https://www.tecnativa.com>`_:
* David Vidal

View File

@@ -0,0 +1,3 @@
This module backports the stock forecast report from v14.
.. image:: static/description/screenshot_stock_forecast.png

View File

@@ -0,0 +1 @@
This won't be needed on 14.0+.

View File

@@ -0,0 +1,3 @@
To use this module, you need to:
#. Go to *Inventory > Reports > Forecasted Inventory*

View File

@@ -0,0 +1 @@
from . import report_stock_quantity

View File

@@ -0,0 +1,175 @@
# Copyright 2021 Odoo S.A.
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models, tools
class ReportStockQuantity(models.Model):
_name = "report.stock.quantity"
_auto = False
_description = "Stock Quantity Report"
date = fields.Date(string="Date", readonly=True)
product_tmpl_id = fields.Many2one(
comodel_name="product.template",
related="product_id.product_tmpl_id",
readonly=True,
)
product_id = fields.Many2one(
comodel_name="product.product",
string="Product",
readonly=True,
)
state = fields.Selection(
selection=[
("forecast", "Forecasted Stock"),
("in", "Forecasted Receipts"),
("out", "Forecasted Deliveries"),
],
string="State",
readonly=True,
)
product_qty = fields.Float(string="Quantity", readonly=True)
move_ids = fields.One2many(comodel_name="stock.move", readonly=True)
company_id = fields.Many2one("res.company", readonly=True)
warehouse_id = fields.Many2one("stock.warehouse", readonly=True)
def init(self):
tools.drop_view_if_exists(self._cr, "report_stock_quantity")
query = """
CREATE or REPLACE VIEW report_stock_quantity AS (
WITH forecast_qty AS (
SELECT
m.id,
m.product_id,
CASE
WHEN (whs.id IS NOT NULL AND whd.id IS NULL)
OR ls.usage = 'transit' THEN 'out'
WHEN (whs.id IS NULL AND whd.id IS NOT NULL)
OR ld.usage = 'transit' THEN 'in'
END AS state,
m.date_expected::date AS date,
CASE
WHEN (whs.id IS NOT NULL AND whd.id IS NULL)
OR ls.usage = 'transit' THEN -product_qty
WHEN (whs.id IS NULL AND whd.id IS NOT NULL)
OR ld.usage = 'transit' THEN product_qty
END AS product_qty,
m.company_id,
CASE
WHEN (whs.id IS NOT NULL AND whd.id IS NULL)
OR ls.usage = 'transit' THEN whs.id
WHEN (whs.id IS NULL AND whd.id IS NOT NULL)
OR ld.usage = 'transit' THEN whd.id
END AS warehouse_id
FROM
stock_move m
LEFT JOIN stock_location ls ON (ls.id=m.location_id)
LEFT JOIN stock_location ld ON (ld.id=m.location_dest_id)
LEFT JOIN stock_warehouse whs
ON ls.parent_path like concat('%/', whs.view_location_id, '/%')
LEFT JOIN stock_warehouse whd
ON ld.parent_path like concat('%/', whd.view_location_id, '/%')
LEFT JOIN product_product pp ON pp.id=m.product_id
LEFT JOIN product_template pt ON pt.id=pp.product_tmpl_id
WHERE
pt.type = 'product' AND
product_qty != 0 AND
(whs.id IS NOT NULL OR whd.id IS NOT NULL) AND
(whs.id IS NULL OR whd.id IS NULL OR whs.id != whd.id) AND
m.state NOT IN ('cancel', 'draft', 'done')
UNION ALL
SELECT
-q.id as id,
q.product_id,
'forecast' as state,
date.*::date,
q.quantity as product_qty,
q.company_id,
wh.id as warehouse_id
FROM
GENERATE_SERIES(
(now() at time zone 'utc')::date - interval '3month',
(now() at time zone 'utc')::date + interval '3 month',
'1 day'::interval
) date,
stock_quant q
LEFT JOIN stock_location l ON (l.id=q.location_id)
LEFT JOIN stock_warehouse wh ON l.parent_path like concat(
'%/', wh.view_location_id, '/%')
WHERE
(l.usage = 'internal' AND wh.id IS NOT NULL) OR
l.usage = 'transit'
UNION ALL
SELECT
m.id,
m.product_id,
'forecast' as state,
GENERATE_SERIES(
CASE
WHEN m.state = 'done' THEN (
now() at time zone 'utc'
)::date - interval '3month'
ELSE m.date_expected::date
END,
CASE
WHEN m.state != 'done' THEN (
now() at time zone 'utc'
)::date + interval '3 month'
ELSE m.date_expected::date - interval '1 day'
END, '1 day'::interval)::date date,
CASE
WHEN (
(whs.id IS NOT NULL AND whd.id IS NULL) OR ls.usage = 'transit'
) AND m.state = 'done' THEN product_qty
WHEN (
(whs.id IS NULL AND whd.id IS NOT NULL) OR ld.usage = 'transit'
) AND m.state = 'done' THEN -product_qty
WHEN (
whs.id IS NOT NULL AND whd.id IS NULL
) OR ls.usage = 'transit' THEN -product_qty
WHEN (
whs.id IS NULL AND whd.id IS NOT NULL
) OR ld.usage = 'transit' THEN product_qty
END AS product_qty,
m.company_id,
CASE
WHEN (
whs.id IS NOT NULL AND whd.id IS NULL
) OR ls.usage = 'transit' THEN whs.id
WHEN (
whs.id IS NULL AND whd.id IS NOT NULL
) OR ld.usage = 'transit' THEN whd.id
END AS warehouse_id
FROM
stock_move m
LEFT JOIN stock_location ls on (ls.id=m.location_id)
LEFT JOIN stock_location ld on (ld.id=m.location_dest_id)
LEFT JOIN stock_warehouse whs ON ls.parent_path like concat(
'%/', whs.view_location_id, '/%'
)
LEFT JOIN stock_warehouse whd ON ld.parent_path like concat(
'%/', whd.view_location_id, '/%'
)
LEFT JOIN product_product pp on pp.id=m.product_id
LEFT JOIN product_template pt on pt.id=pp.product_tmpl_id
WHERE
pt.type = 'product' AND
product_qty != 0 AND
(whs.id IS NOT NULL OR whd.id IS NOT NULL) AND
(whs.id IS NULL or whd.id IS NULL OR whs.id != whd.id) AND
m.state NOT IN ('cancel', 'draft')
) -- /forecast_qty
SELECT
MIN(id) as id,
product_id,
state,
date,
sum(product_qty) as product_qty,
company_id,
warehouse_id
FROM forecast_qty
GROUP BY product_id, state, date, company_id, warehouse_id
);
"""
self.env.cr.execute(query)

View File

@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="stock_report_view_graph" model="ir.ui.view">
<field name="name">stock_report_view_graph</field>
<field name="model">report.stock.quantity</field>
<field name="arch" type="xml">
<graph string="report_stock_quantity_graph" type="line">
<field name="product_id" type="col"/>
<field name="date" interval="day" type="row"/>
<field name="product_qty" type="measure"/>
</graph>
</field>
</record>
<record id="stock_report_view_pivot" model="ir.ui.view">
<field name="name">stock_report_view_pivot</field>
<field name="model">report.stock.quantity</field>
<field name="arch" type="xml">
<pivot string="report_stock_quantity_pivot" disable_linking="1">
<field name="product_id" type="col"/>
<field name="date" interval="day" type="row"/>
<field name="product_qty" type="measure"/>
</pivot>
</field>
</record>
<record id="stock_report_view_search" model="ir.ui.view">
<field name="name">report.stock.quantity.search</field>
<field name="model">report.stock.quantity</field>
<field name="arch" type="xml">
<search string="Report Quantity">
<field name="product_id"/>
<field name="state"/>
<field name="product_tmpl_id"/>
<field name="warehouse_id"/>
<group expand="0" string="State">
<filter string="Forecasted Stock" name="filter_forecast" domain="[('state', '=', 'forecast')]"/>
<filter string="Forecasted Receipts" name="filter_in" domain="[('state', '=', 'in'), ('date', '&gt;', context_today().strftime('%Y-%m-%d'))]"/>
<filter string="Forecasted Deliveries" name="filter_out" domain="[('state', '=', 'out'), ('date', '&gt;', context_today().strftime('%Y-%m-%d'))]"/>
<separator/>
<filter string="Date" name="filter_date" date="date"/>
<filter string="Forecasted this Week" name="filter_forecasted_next_days" domain="[('date', '&gt;=', context_today().strftime('%Y-%m-%d')), ('date','&lt;=', (context_today() + datetime.timedelta(days=5)).strftime('%%Y-%%m-%%d'))]" />
</group>
<group expand="0" string="Group By">
<filter string="Date" name="groupby_date" domain="[]" context="{'group_by':'date:day'}"/>
</group>
</search>
</field>
</record>
<record id="stock.action_stock_level_forecast_report_template" model="ir.actions.act_window">
<field name="res_model">report.stock.quantity</field>
<field name="search_view_id" ref="stock_forecast_report.stock_report_view_search"/>
<field name="context">{
'search_default_product_tmpl_id': active_id,
'search_default_filter_forecast': 1,
'graph_groupbys': ['date:day', 'product_id'],
'graph_intervalMapping': {},
'graph_mode': 'line',
'group_by': ['date:day', 'product_id'],
'graph_measure': 'product_qty',
'pivot_row_groupby': ['product_id'],
'pivot_column_groupby': ['date:day'],
'pivot_measures': ['product_qty']
}</field>
<field name="view_id" ref="stock_forecast_report.stock_report_view_graph"/>
</record>
<record id="stock.action_stock_level_forecast_report_product" model="ir.actions.act_window">
<field name="res_model">report.stock.quantity</field>
<field name="search_view_id" ref="stock_forecast_report.stock_report_view_search"/>
<field name="context">{
'search_default_product_id': active_id,
'search_default_filter_forecast': 1,
'graph_groupbys': ['date:day', 'product_id'],
'graph_intervalMapping': {},
'graph_mode': 'line',
'group_by': ['date:day', 'product_id'],
'graph_measure': 'product_qty',
'pivot_row_groupby': ['product_id'],
'pivot_column_groupby': ['date:day'],
'pivot_measures': ['product_qty']
}</field>
<field name="view_id" ref="stock_forecast_report.stock_report_view_graph"/>
</record>
<record id="report_stock_quantity_action" model="ir.actions.act_window">
<field name="name">Forecasted Inventory</field>
<field name="res_model">report.stock.quantity</field>
<field name="view_mode">graph,pivot</field>
<field name="context">{
'search_default_filter_forecasted_next_days': 1,
'graph_groupbys': ['date:day', 'product_id'],
'graph_mode': 'line',
'group_by': ['date:day', 'product_id'],
'graph_measure': 'product_qty',
'pivot_row_groupby': ['product_id'],
'pivot_column_groupby': ['date:day'],
'pivot_measures': ['product_qty']
}</field>
</record>
<menuitem id="menu_forecast_inventory" name="Forecasted Inventory" parent="stock.menu_warehouse_report" sequence="101" action="report_stock_quantity_action"/>
</odoo>

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_report_stock_quantity,access_report_stock_quantity,model_report_stock_quantity,base.group_user,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_report_stock_quantity access_report_stock_quantity model_report_stock_quantity base.group_user 1 0 0 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -0,0 +1,438 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Stock Forecast Report</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="stock-forecast-report">
<h1 class="title">Stock Forecast Report</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_forecast_report"><img alt="OCA/stock-logistics-reporting" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--reporting-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-reporting-12-0/stock-logistics-reporting-12-0-stock_forecast_report"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/151/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module backports the stock forecast report from v14.</p>
<img alt="https://raw.githubusercontent.com/OCA/stock-logistics-reporting/12.0/stock_forecast_report/static/description/screenshot_stock_forecast.png" src="https://raw.githubusercontent.com/OCA/stock-logistics-reporting/12.0/stock_forecast_report/static/description/screenshot_stock_forecast.png" />
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Go to <em>Inventory &gt; Reports &gt; Forecasted Inventory</em></li>
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>This is a backport from the 14.0 Odoo core forecast report.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/issues/new?body=module:%20stock_forecast_report%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>David Vidal</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_forecast_report">OCA/stock-logistics-reporting</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -0,0 +1 @@
from . import test_report_stock_quantity

View File

@@ -0,0 +1,102 @@
# Copyright 2021 Odoo S.A.
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.tests.common import TransactionCase
class TestReportStockQuantity(TransactionCase):
def setUp(self):
super().setUp()
self.product1 = self.env["product.product"].create({
"name": "Mellohi",
"default_code": "C418",
"type": "product",
"categ_id": self.env.ref("product.product_category_all").id,
"tracking": "lot",
"barcode": "scan_me"
})
wh = self.env["stock.warehouse"].create({
"name": "Base Warehouse",
"code": "TESTWH"
})
self.categ_unit = self.env.ref("uom.product_uom_categ_unit")
self.uom_unit = self.env["uom.uom"].search(
[
("category_id", "=", self.categ_unit.id),
("uom_type", "=", "reference")
],
limit=1
)
self.customer_location = self.env.ref("stock.stock_location_customers")
self.supplier_location = self.env.ref("stock.stock_location_suppliers")
# Replenish
self.move1 = self.env["stock.move"].create({
"name": "test_in_1",
"location_id": self.supplier_location.id,
"location_dest_id": wh.lot_stock_id.id,
"product_id": self.product1.id,
"product_uom": self.uom_unit.id,
"product_uom_qty": 100.0,
"state": "done",
"date": fields.Datetime.now(),
"date_expected": fields.Datetime.now(),
})
self.quant1 = self.env["stock.quant"].create({
"product_id": self.product1.id,
"location_id": wh.lot_stock_id.id,
"quantity": 100.0,
})
self.move2 = self.env["stock.move"].create({
"name": "test_out_1",
"location_id": wh.lot_stock_id.id,
"location_dest_id": self.customer_location.id,
"product_id": self.product1.id,
"product_uom": self.uom_unit.id,
"product_uom_qty": 120.0,
"state": "partially_available",
"date": fields.Datetime.add(fields.Datetime.now(), days=3),
"date_expected": fields.Datetime.add(fields.Datetime.now(), days=3),
})
self.move2.date = fields.Datetime.add(fields.Datetime.now(), days=3)
def test_report_stock_quantity(self):
from_date = fields.Date.to_string(
fields.Date.add(fields.Date.today(), days=-1))
to_date = fields.Date.to_string(
fields.Date.add(fields.Date.today(), days=4))
report = self.env["report.stock.quantity"].read_group(
[
("date", ">=", from_date),
("date", "<=", to_date),
("product_id", "=", self.product1.id)
],
["product_qty", "date", "product_id", "state"],
["date:day", "product_id", "state"],
lazy=False
)
forecast_report = (
[x["product_qty"] for x in report if x["state"] == "forecast"]
)
self.assertEqual(forecast_report, [0, 100, 100, 100, -20, -20])
def test_report_stock_quantity_with_product_qty_filter(self):
from_date = fields.Date.to_string(
fields.Date.add(fields.Date.today(), days=-1)
)
to_date = fields.Date.to_string(
fields.Date.add(fields.Date.today(), days=4)
)
report = self.env["report.stock.quantity"].read_group(
[
("product_qty", "<", 0), ("date", ">=", from_date),
("date", "<=", to_date), ("product_id", "=", self.product1.id)
],
["product_qty", "date", "product_id", "state"],
["date:day", "product_id", "state"],
lazy=False
)
forecast_report = (
[x["product_qty"] for x in report if x["state"] == "forecast"]
)
self.assertEqual(forecast_report, [-20, -20])