diff --git a/stock_account_quantity_history_location/README.rst b/stock_account_quantity_history_location/README.rst
index 48c51d0..6dc2c29 100644
--- a/stock_account_quantity_history_location/README.rst
+++ b/stock_account_quantity_history_location/README.rst
@@ -14,13 +14,13 @@ Stock Account Quantity History Location
: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_account_quantity_history_location
+ :target: https://github.com/OCA/stock-logistics-reporting/tree/13.0/stock_account_quantity_history_location
: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_account_quantity_history_location
+ :target: https://translation.odoo-community.org/projects/stock-logistics-reporting-13-0/stock-logistics-reporting-13-0-stock_account_quantity_history_location
: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
+ :target: https://runbot.odoo-community.org/runbot/151/13.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -41,7 +41,7 @@ Bug Tracker
Bugs are tracked on `GitHub 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 `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -66,6 +66,6 @@ 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 `_ project on GitHub.
+This module is part of the `OCA/stock-logistics-reporting `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/stock_account_quantity_history_location/__manifest__.py b/stock_account_quantity_history_location/__manifest__.py
index 6637473..f207572 100644
--- a/stock_account_quantity_history_location/__manifest__.py
+++ b/stock_account_quantity_history_location/__manifest__.py
@@ -1,5 +1,6 @@
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# Copyright 2019 Aleph Objects, Inc.
+# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
@@ -7,11 +8,11 @@
"summary": """
Glue module between Stock Account and Stock Quantity History Location
modules""",
- "version": "12.0.1.1.0",
+ "version": "13.0.1.0.0",
"license": "AGPL-3",
- "author": "Eficent," "Odoo Community Association (OCA)",
+ "author": "Eficent, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-reporting",
- "depends": ["stock_account", "stock_quantity_history_location",],
- "data": ["wizards/stock_quantity_history.xml",],
+ "depends": ["stock_account", "stock_quantity_history_location"],
+ "data": ["wizards/stock_quantity_history.xml"],
"auto_install": True,
}
diff --git a/stock_account_quantity_history_location/i18n/stock_account_quantity_history_location.pot b/stock_account_quantity_history_location/i18n/stock_account_quantity_history_location.pot
index 26eb1b9..e83603c 100644
--- a/stock_account_quantity_history_location/i18n/stock_account_quantity_history_location.pot
+++ b/stock_account_quantity_history_location/i18n/stock_account_quantity_history_location.pot
@@ -1,12 +1,12 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
-# * stock_account_quantity_history_location
+# * stock_account_quantity_history_location
#
msgid ""
msgstr ""
-"Project-Id-Version: Odoo Server 12.0\n"
+"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
-"Last-Translator: <>\n"
+"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -17,4 +17,3 @@ msgstr ""
#: model:ir.model,name:stock_account_quantity_history_location.model_stock_quantity_history
msgid "Stock Quantity History"
msgstr ""
-
diff --git a/stock_account_quantity_history_location/readme/CONSTRIBUTORS.rst b/stock_account_quantity_history_location/readme/CONSTRIBUTORS.rst
index 6860aff..36bb64b 100644
--- a/stock_account_quantity_history_location/readme/CONSTRIBUTORS.rst
+++ b/stock_account_quantity_history_location/readme/CONSTRIBUTORS.rst
@@ -1 +1,5 @@
* Jordi Ballester Alomar
+
+* `Tecnativa `_:
+
+ * Víctor Martínez
diff --git a/stock_account_quantity_history_location/static/description/index.html b/stock_account_quantity_history_location/static/description/index.html
index 88bd988..13ce383 100644
--- a/stock_account_quantity_history_location/static/description/index.html
+++ b/stock_account_quantity_history_location/static/description/index.html
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

Glue module between Stock Account and Stock Quantity History Location modules.
Display a warning on the Stock Inventory report that accounting valuation is
not calculated when you specify a location.
@@ -387,7 +387,7 @@ not calculated when you specify a location.
Bugs are tracked on GitHub 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.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -405,7 +405,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
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 project on GitHub.
+
This module is part of the OCA/stock-logistics-reporting project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/stock_account_quantity_history_location/tests/test_valuation_location.py b/stock_account_quantity_history_location/tests/test_valuation_location.py
index 34c591c..1d0eb1b 100644
--- a/stock_account_quantity_history_location/tests/test_valuation_location.py
+++ b/stock_account_quantity_history_location/tests/test_valuation_location.py
@@ -1,5 +1,8 @@
# Copyright 2020 Tecnativa - David Vidal
+# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from datetime import datetime
+
from odoo.addons.stock_quantity_history_location.tests import (
test_stock_quantity_history_location,
)
@@ -11,48 +14,87 @@ class TestValuationLocation(
@classmethod
def setUpClass(cls):
super().setUpClass()
- cls.env["product.price.history"].create(
- {"datetime": "2019-08-12", "product_id": cls.product.id, "cost": 35.01,}
+ cls.sqh_model = cls.env["stock.quantity.history"]
+ cls.sqh_model_svl = cls.env["stock.quantity.history"].with_context(
+ active_model="stock.valuation.layer"
)
- cls.env["product.price.history"].create(
- {"datetime": "2020-01-01", "product_id": cls.product.id, "cost": 33.33,}
- )
- cls.product.categ_id.property_cost_method = "standard"
- cls.test_stock_loc2 = cls.env["stock.location"].create(
- {
- "usage": "internal",
- "name": "Test Stock Location 2",
- "company_id": cls.main_company.id,
- }
- )
- # Create a move for the past
- move = cls.env["stock.move"].create(
+
+ def _create_stock_move(self, location_dest_id, qty):
+ move = self.env["stock.move"].create(
{
"name": "Stock move in",
- "location_id": cls.supplier_location.id,
- "location_dest_id": cls.test_stock_loc2.id,
- "product_id": cls.product.id,
- "product_uom": cls.product.uom_id.id,
- "product_uom_qty": 50.0,
+ "location_id": self.supplier_location.id,
+ "location_dest_id": location_dest_id.id,
+ "product_id": self.product.id,
+ "product_uom": self.product.uom_id.id,
+ "product_uom_qty": qty,
}
)
move._action_confirm()
move._action_assign()
move_line = move.move_line_ids[0]
- move_line.qty_done = 50.0
+ move_line.qty_done = qty
move._action_done()
- move.date = "2020-01-01"
+ return move
def test_stock_location_valuation(self):
- wizard = self.env["stock.quantity.history"].create(
+ wizard = self.sqh_model.create(
{
- "location_id": self.test_stock_loc2.id,
+ "location_id": self.test_stock_loc.id,
"include_child_locations": True,
- "compute_at_date": 1,
- "date": "2020-01-01",
+ "inventory_datetime": datetime.today(),
}
)
- action = wizard.with_context(company_owned=True, valuation=True).open_table()
- self.assertAlmostEqual(
- self.product.with_context(action["context"]).stock_value, 1666.5
+ action = wizard.with_context(company_owned=True).open_at_date()
+ qty_svl_prev = self.product.with_context(action["context"]).quantity_svl
+ move = self._create_stock_move(location_dest_id=self.test_stock_loc, qty=60)
+ wizard["inventory_datetime"] = move.stock_valuation_layer_ids.create_date
+ action = wizard.with_context(company_owned=True).open_at_date()
+ product = self.product.with_context(action["context"])
+ self.assertEqual(product.quantity_svl - qty_svl_prev, 60)
+
+ def test_stock_location_valuation_without_location_id(self):
+ wizard = self.sqh_model.create(
+ {"include_child_locations": True, "inventory_datetime": datetime.today()}
)
+ action = wizard.with_context(company_owned=True, valuation=True).open_at_date()
+ qty_svl_prev = self.product.with_context(action["context"]).quantity_svl
+ self._create_stock_move(location_dest_id=self.test_stock_loc, qty=50)
+ move = self._create_stock_move(
+ location_dest_id=self.child_test_stock_loc, qty=10
+ )
+ wizard["inventory_datetime"] = move.stock_valuation_layer_ids.create_date
+ action = wizard.with_context(company_owned=True).open_at_date()
+ product = self.product.with_context(action["context"])
+ self.assertEqual(product.quantity_svl - qty_svl_prev, 60)
+
+ def test_stock_location_valuation_with_svl(self):
+ wizard = self.sqh_model_svl.create(
+ {
+ "location_id": self.test_stock_loc.id,
+ "include_child_locations": True,
+ "inventory_datetime": datetime.today(),
+ }
+ )
+ action = wizard.with_context(company_owned=True).open_at_date()
+ records_prev = self.env[action["res_model"]].search(action["domain"])
+ move = self._create_stock_move(location_dest_id=self.test_stock_loc, qty=100)
+ wizard["inventory_datetime"] = move.stock_valuation_layer_ids.create_date
+ action = wizard.with_context(company_owned=True).open_at_date()
+ records = self.env[action["res_model"]].search(action["domain"]) - records_prev
+ self.assertEqual(sum(records.mapped("quantity")), 100)
+
+ def test_stock_location_valuation_with_svl_without_location_id(self):
+ wizard = self.sqh_model_svl.create(
+ {"include_child_locations": True, "inventory_datetime": datetime.today()}
+ )
+ action = wizard.with_context(company_owned=True).open_at_date()
+ records_prev = self.env[action["res_model"]].search(action["domain"])
+ self._create_stock_move(location_dest_id=self.test_stock_loc, qty=100)
+ move = self._create_stock_move(
+ location_dest_id=self.child_test_stock_loc, qty=100
+ )
+ wizard["inventory_datetime"] = move.stock_valuation_layer_ids.create_date
+ action = wizard.with_context(company_owned=True).open_at_date()
+ records = self.env[action["res_model"]].search(action["domain"]) - records_prev
+ self.assertEqual(sum(records.mapped("quantity")), 200)
diff --git a/stock_account_quantity_history_location/wizards/stock_quantity_history.py b/stock_account_quantity_history_location/wizards/stock_quantity_history.py
index 690ee21..8d8220b 100644
--- a/stock_account_quantity_history_location/wizards/stock_quantity_history.py
+++ b/stock_account_quantity_history_location/wizards/stock_quantity_history.py
@@ -1,26 +1,18 @@
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# Copyright 2019 Aleph Objects, Inc.
+# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import ast
from odoo import models
+from odoo.osv import expression
class StockQuantityHistory(models.TransientModel):
_inherit = "stock.quantity.history"
- def open_table(self):
- """Stock valuation goes by a different path than stock report, so
- we ensure the correct context as well"""
- action = super().open_table()
- if not self.env.context.get("valuation"):
- return action
- # Show 0 quantities on Inventory Valuation to display Account Valuation
- # anomalies, such as, non 0 stock_value on cost_method FIFO
- if not self.location_id:
- domain = ast.literal_eval(action["domain"])
- domain.pop(domain.index(("qty_available", "!=", 0)))
- action["domain"] = domain
+ def open_at_date(self):
+ action = super().open_at_date()
ctx = action["context"]
if isinstance(ctx, str):
ctx = ast.literal_eval(ctx)
@@ -36,4 +28,22 @@ class StockQuantityHistory(models.TransientModel):
self.location_id.complete_name,
)
action["context"] = ctx
+ if self.env.context.get("active_model") == "stock.valuation.layer":
+ action["domain"] = expression.AND(
+ [
+ action["domain"],
+ [("stock_move_id.location_dest_id", "=", self.location_id.id)],
+ ]
+ )
+ else:
+ # Show 0 quantities on Inventory Valuation to display Account Valuation
+ # anomalies, such as, non 0 stock_value on cost_method FIFO
+ if self.env.context.get("active_model") == "stock.valuation.layer":
+ action["domain"] = expression.AND(
+ [action["domain"], [("quantity", "!=", 0)]]
+ )
+ else:
+ action["domain"] = expression.AND(
+ [action["domain"], [("qty_available", "!=", 0)]]
+ )
return action
diff --git a/stock_account_quantity_history_location/wizards/stock_quantity_history.xml b/stock_account_quantity_history_location/wizards/stock_quantity_history.xml
index 9f64613..255ad9f 100644
--- a/stock_account_quantity_history_location/wizards/stock_quantity_history.xml
+++ b/stock_account_quantity_history_location/wizards/stock_quantity_history.xml
@@ -3,13 +3,16 @@
Valuation Report
stock.quantity.history
-
+
+
-
-
+