From a8150ee2c3c680d0e784d66ffea2d1151db8c6b8 Mon Sep 17 00:00:00 2001 From: hveficent Date: Fri, 20 Dec 2019 16:56:14 +0100 Subject: [PATCH] [MIG] stock_quantity_history_location: Migration to 13.0 --- .../__manifest__.py | 6 ++-- .../test_stock_quantity_history_location.py | 33 +++++++------------ .../wizards/stock_quantity_history.py | 17 +++------- .../wizards/stock_quantity_history.xml | 2 +- 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/stock_quantity_history_location/__manifest__.py b/stock_quantity_history_location/__manifest__.py index 1b8c765..012495c 100644 --- a/stock_quantity_history_location/__manifest__.py +++ b/stock_quantity_history_location/__manifest__.py @@ -1,13 +1,13 @@ -# Copyright 2019 Eficent Business and IT Consulting Services, S.L. +# Copyright 2019 ForgeFlow S.L. # Copyright 2019 Aleph Objects, Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Stock Quantity History Location", "summary": "Provides stock quantity by location on past date", - "version": "12.0.1.0.1", + "version": "13.0.1.0.1", "license": "AGPL-3", - "author": "Eficent," "Odoo Community Association (OCA)", + "author": "ForgeFlow," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-reporting", "depends": ["stock"], "data": ["wizards/stock_quantity_history.xml"], diff --git a/stock_quantity_history_location/tests/test_stock_quantity_history_location.py b/stock_quantity_history_location/tests/test_stock_quantity_history_location.py index 2d70039..83d86b4 100644 --- a/stock_quantity_history_location/tests/test_stock_quantity_history_location.py +++ b/stock_quantity_history_location/tests/test_stock_quantity_history_location.py @@ -1,4 +1,4 @@ -# Copyright 2019 Eficent Business and IT Consulting Services, S.L. +# Copyright 2019 ForgeFlow S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests.common import SavepointCase @@ -49,11 +49,10 @@ class TestStockQuantityHistoryLocation(SavepointCase): { "location_id": self.test_stock_loc.id, "include_child_locations": True, - "compute_at_date": 1, - "date": "2019-08-12", + "inventory_datetime": "2019-08-12 00:00:00", } ) - action = wizard.with_context(company_owned=True).open_table() + action = wizard.with_context(company_owned=True).open_at_date() self.assertEquals( self.product.with_context(action["context"]).qty_available, 100.0 ) @@ -66,24 +65,14 @@ class TestStockQuantityHistoryLocation(SavepointCase): def test_wizard_current(self): wizard = self.env["stock.quantity.history"].create( - { - "location_id": self.test_stock_loc.id, - "include_child_locations": False, - "compute_at_date": 0, - } - ) - action = wizard.with_context().open_table() - self.assertEquals( - action["domain"], [("location_id", "=", self.test_stock_loc.id)] + {"location_id": self.test_stock_loc.id, "include_child_locations": False} ) + action = wizard.with_context().open_at_date() + self.assertEquals(action["context"]["compute_child"], False) + self.assertEquals(action["context"]["location"], self.test_stock_loc.id) wizard = self.env["stock.quantity.history"].create( - { - "location_id": self.test_stock_loc.id, - "include_child_locations": True, - "compute_at_date": 0, - } - ) - action = wizard.with_context().open_table() - self.assertEquals( - action["domain"], [("location_id", "child_of", self.test_stock_loc.id)] + {"location_id": self.test_stock_loc.id, "include_child_locations": True} ) + action = wizard.with_context().open_at_date() + self.assertEquals(action["context"]["compute_child"], True) + self.assertEquals(action["context"]["location"], self.test_stock_loc.id) diff --git a/stock_quantity_history_location/wizards/stock_quantity_history.py b/stock_quantity_history_location/wizards/stock_quantity_history.py index 5b9dd80..3ea6436 100644 --- a/stock_quantity_history_location/wizards/stock_quantity_history.py +++ b/stock_quantity_history_location/wizards/stock_quantity_history.py @@ -1,4 +1,4 @@ -# Copyright 2019 Eficent Business and IT Consulting Services, S.L. +# Copyright 2019 ForgeFlow S.L. # Copyright 2019 Aleph Objects, Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import ast @@ -14,22 +14,13 @@ class StockQuantityHistory(models.TransientModel): ) include_child_locations = fields.Boolean("Include child locations", default=True) - def open_table(self): - action = super(StockQuantityHistory, self).open_table() + def open_at_date(self): + action = super(StockQuantityHistory, self).open_at_date() ctx = action["context"] if isinstance(ctx, str): ctx = ast.literal_eval(ctx) # If we are opening the current quants, filter by domain - if ( - self.location_id - and not self.compute_at_date - and not self.env.context.get("valuation") - ): - if self.include_child_locations: - action["domain"] = [("location_id", "child_of", self.location_id.id)] - else: - action["domain"] = [("location_id", "=", self.location_id.id)] - elif self.location_id: + if self.location_id: ctx["location"] = self.location_id.id ctx["compute_child"] = self.include_child_locations if ctx.get("company_owned", False): diff --git a/stock_quantity_history_location/wizards/stock_quantity_history.xml b/stock_quantity_history_location/wizards/stock_quantity_history.xml index 97329f9..12aa036 100644 --- a/stock_quantity_history_location/wizards/stock_quantity_history.xml +++ b/stock_quantity_history_location/wizards/stock_quantity_history.xml @@ -5,7 +5,7 @@ stock.quantity.history - +