diff --git a/addons/stock_account/data/stock_account_data.xml b/addons/stock_account/data/stock_account_data.xml
index d5f55811def..107fcd6acc1 100644
--- a/addons/stock_account/data/stock_account_data.xml
+++ b/addons/stock_account/data/stock_account_data.xml
@@ -26,17 +26,6 @@
manual_periodic
selection
-
- Stock Valuation Report
- ir.actions.server
- code
-
-
-
-env['stock.move']._run_fifo_vacuum()
-action = env.ref('stock_account.product_valuation_action').read()[0]
-
-
diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py
index 4ac2ef61128..df642de4337 100644
--- a/addons/stock_account/models/product.py
+++ b/addons/stock_account/models/product.py
@@ -240,6 +240,34 @@ class ProductProduct(models.Model):
value, quantity, aml_ids = fifo_automated_values.get((product.id, valuation_account_id)) or (0, 0, [])
product.stock_fifo_real_time_aml_ids = self.env['account.move.line'].browse(aml_ids)
+ def action_valuation_at_date_details(self):
+ """ Returns an action with either a list view of all the valued stock moves of `self` if the
+ valuation is set as manual or a list view of all the account move lines if the valuation is
+ set as automated.
+ """
+ self.ensure_one()
+ to_date = self.env.context.get('to_date')
+ action = {
+ 'name': _('Valuation at date'),
+ 'type': 'ir.actions.act_window',
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'context': self.env.context,
+ }
+ if self.valuation == 'real_time':
+ action['res_model'] = 'account.move.line'
+ action['domain'] = [('id', 'in', self.with_context(to_date=to_date).stock_fifo_real_time_aml_ids.ids)]
+ tree_view_ref = self.env.ref('stock_account.view_stock_account_aml')
+ form_view_ref = self.env.ref('account.view_move_line_form')
+ action['views'] = [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')]
+ else:
+ action['res_model'] = 'stock.move'
+ action['domain'] = [('id', 'in', self.with_context(to_date=to_date).stock_fifo_manual_move_ids.ids)]
+ tree_view_ref = self.env.ref('stock_account.view_move_tree_valuation_at_date')
+ form_view_ref = self.env.ref('stock.view_move_form')
+ action['views'] = [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')]
+ return action
+
@api.multi
def action_open_product_moves(self):
self.ensure_one()
diff --git a/addons/stock_account/views/product_views.xml b/addons/stock_account/views/product_views.xml
index 5491d63a6bd..32f8db22645 100644
--- a/addons/stock_account/views/product_views.xml
+++ b/addons/stock_account/views/product_views.xml
@@ -86,27 +86,14 @@
-
-
- product.valuation.tree
- product.product
-
-
-
-
-
-
-
-
-
-
+
Product Valuation
ir.actions.act_window
product.product
tree,form
form
-
+
[('type', '=', 'product'), ('qty_available', '!=', 0)]
{}
diff --git a/addons/stock_account/views/stock_account_views.xml b/addons/stock_account/views/stock_account_views.xml
index 92eb6970705..656d6ea7364 100644
--- a/addons/stock_account/views/stock_account_views.xml
+++ b/addons/stock_account/views/stock_account_views.xml
@@ -49,6 +49,82 @@
-
+
+
+ Valuation Report
+ stock.quantity.history
+
+
+
+
+
+ product.stock.tree.2
+ product.product
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Valuation Report
+ stock.quantity.history
+ form
+ form
+
+ new
+ {'default_compute_at_date': 0, 'valuation': True}
+
+
+
+
+
+ stock.account.aml
+ account.move.line
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ stock.move.tree.valuation.at.date
+ stock.move
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/stock_account/wizard/__init__.py b/addons/stock_account/wizard/__init__.py
index 3fbd834da9f..01b730d1fe4 100644
--- a/addons/stock_account/wizard/__init__.py
+++ b/addons/stock_account/wizard/__init__.py
@@ -2,4 +2,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import stock_change_standard_price
+from . import stock_quantity_history
diff --git a/addons/stock_account/wizard/stock_quantity_history.py b/addons/stock_account/wizard/stock_quantity_history.py
new file mode 100644
index 00000000000..6b244d13ac2
--- /dev/null
+++ b/addons/stock_account/wizard/stock_quantity_history.py
@@ -0,0 +1,32 @@
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models, _
+
+
+class StockQuantityHistory(models.TransientModel):
+ _inherit = 'stock.quantity.history'
+
+ def open_table(self):
+ if not self.env.context.get('valuation'):
+ return super(StockQuantityHistory, self).open_table()
+
+ self.env['stock.move']._run_fifo_vacuum()
+
+ if self.compute_at_date:
+ tree_view_id = self.env.ref('stock_account.view_stock_product_tree2').id
+ form_view_id = self.env.ref('stock.product_form_view_procurement_button').id
+ # We pass `to_date` in the context so that `qty_available` will be computed across
+ # moves until date.
+ action = {
+ 'type': 'ir.actions.act_window',
+ 'views': [(tree_view_id, 'tree'), (form_view_id, 'form')],
+ 'view_mode': 'tree,form',
+ 'name': _('Products'),
+ 'res_model': 'product.product',
+ 'domain': "[('type', '=', 'product'), ('qty_available', '!=', 0)]",
+ 'context': dict(self.env.context, to_date=self.date),
+ }
+ return action
+ else:
+ return self.env.ref('stock_account.product_valuation_action').read()[0]
+