From c88517b6f15a104de955a7cf16058ee1403aca08 Mon Sep 17 00:00:00 2001 From: hveficent Date: Tue, 9 Jul 2019 12:15:06 +0200 Subject: [PATCH 1/4] [IMP] Backport improvements from 12.0 migration --- .../static/description/index.html | 6 +- .../test_stock_quantity_history_location.py | 56 ++++++++++++++++--- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/stock_quantity_history_location/static/description/index.html b/stock_quantity_history_location/static/description/index.html index 3590484..87088e3 100644 --- a/stock_quantity_history_location/static/description/index.html +++ b/stock_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. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/stock-logistics-reporting Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/stock-logistics-reporting Translate me on Weblate Try me on Runbot

This module allows to run an Inventory report or Inventory Valuation report by location, for a past date or for current date.

Table of contents

@@ -404,7 +404,7 @@ report by location, for a past date or for current date.

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.

@@ -422,7 +422,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_quantity_history_location/tests/test_stock_quantity_history_location.py b/stock_quantity_history_location/tests/test_stock_quantity_history_location.py index 59cedea..0bf7d2c 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 @@ -9,14 +9,56 @@ class TestStockQuantityHistoryLocation(SavepointCase): @classmethod def setUpClass(cls): super(TestStockQuantityHistoryLocation, cls).setUpClass() - cls.stock_loc = cls.env.ref('stock.stock_location_stock') + cls.supplier_location = cls.env.ref('stock.stock_location_suppliers') + cls.main_company = cls.env.ref('base.main_company') + cls.product = cls.env.ref('product.product_product_3') + cls.test_stock_loc = cls.env['stock.location'].create({ + 'usage': 'internal', + 'name': 'Test Stock Location', + 'company_id': cls.main_company.id + }) + cls.child_test_stock_loc = cls.env['stock.location'].create({ + 'usage': 'internal', + 'name': 'Child Test Stock Location', + 'location_id': cls.test_stock_loc.id, + 'company_id': cls.main_company.id + }) + # Create a move for the past + move = cls.env['stock.move'].create({ + 'name': 'Stock move in', + 'location_id': cls.supplier_location.id, + 'location_dest_id': cls.child_test_stock_loc.id, + 'product_id': cls.product.id, + 'product_uom': cls.product.uom_id.id, + 'product_uom_qty': 100.0, + }) + move._action_confirm() + move._action_assign() + move_line = move.move_line_ids[0] + move_line.qty_done = 100.0 + move._action_done() + move.date = "2019-08-11" - def test_wizard(self): - self.wizard = self.env['stock.quantity.history'].create({ - "location_id": self.stock_loc.id, + def test_wizard_past_date(self): + wizard = self.env['stock.quantity.history'].create({ + "location_id": self.test_stock_loc.id, + "include_child_locations": True, + "compute_at_date": 1, + "date": "2019-08-12", + }) + action = wizard.with_context(company_owned=True).open_table() + self.assertEquals( + self.product.with_context(action['context']).qty_available, 100.0) + self.assertEquals(self.product.with_context( + location=self.child_test_stock_loc.id, + to_date="2019-08-10").qty_available, 0.0) + + def test_wizard_current(self): + wizard = self.env['stock.quantity.history'].create({ + "location_id": self.test_stock_loc.id, "include_child_locations": True, "compute_at_date": 0, - "company_owned": True }) - wizard = self.wizard.open_table() - self.assertEquals(wizard['context']['location'], self.stock_loc.id) + action = wizard.with_context().open_table() + self.assertEquals(action['context']['location'], + self.test_stock_loc.id) From caeac059fd3a853894825774c0bd1d26bb572c5b Mon Sep 17 00:00:00 2001 From: hveficent Date: Fri, 30 Aug 2019 11:48:39 +0200 Subject: [PATCH 2/4] [FIX] stock_quantity_history_location: stock.quant action fixup! --- .../tests/test_stock_quantity_history_location.py | 13 +++++++++++-- .../wizards/stock_quantity_history.py | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) 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 0bf7d2c..3f1b762 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 @@ -54,11 +54,20 @@ class TestStockQuantityHistoryLocation(SavepointCase): to_date="2019-08-10").qty_available, 0.0) 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)]) 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['context']['location'], - self.test_stock_loc.id) + self.assertEquals(action['domain'], + [('location_id', 'child_of', + 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 689ee4f..5849e68 100644 --- a/stock_quantity_history_location/wizards/stock_quantity_history.py +++ b/stock_quantity_history_location/wizards/stock_quantity_history.py @@ -20,8 +20,15 @@ class StockQuantityHistory(models.TransientModel): ctx = action['context'] if isinstance(ctx, str): ctx = ast.literal_eval(ctx) - action['domain'] = [('type', '=', 'product')] - if self.location_id: + # 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: ctx['location'] = self.location_id.id ctx['compute_child'] = self.include_child_locations if ctx.get('company_owned', False): From ee355eb5b79ba6205e4fcd315420c339daa5cdcd Mon Sep 17 00:00:00 2001 From: hveficent Date: Tue, 16 Jul 2019 12:43:00 +0200 Subject: [PATCH 3/4] [IMP] Backport stock_account_quantity_history_location 12.0 improvements --- .../__init__.py | 1 + .../wizards/__init__.py | 2 ++ .../wizards/stock_quantity_history.py | 19 +++++++++++++++++++ .../wizards/stock_quantity_history.xml | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 stock_account_quantity_history_location/wizards/__init__.py create mode 100644 stock_account_quantity_history_location/wizards/stock_quantity_history.py diff --git a/stock_account_quantity_history_location/__init__.py b/stock_account_quantity_history_location/__init__.py index e69de29..326c3db 100644 --- a/stock_account_quantity_history_location/__init__.py +++ b/stock_account_quantity_history_location/__init__.py @@ -0,0 +1 @@ +from . import wizards \ No newline at end of file diff --git a/stock_account_quantity_history_location/wizards/__init__.py b/stock_account_quantity_history_location/wizards/__init__.py new file mode 100644 index 0000000..500ceb8 --- /dev/null +++ b/stock_account_quantity_history_location/wizards/__init__.py @@ -0,0 +1,2 @@ +from . import stock_quantity_history + diff --git a/stock_account_quantity_history_location/wizards/stock_quantity_history.py b/stock_account_quantity_history_location/wizards/stock_quantity_history.py new file mode 100644 index 0000000..aa1ac6f --- /dev/null +++ b/stock_account_quantity_history_location/wizards/stock_quantity_history.py @@ -0,0 +1,19 @@ +# Copyright 2019 Eficent Business and IT Consulting Services, S.L. +# Copyright 2019 Aleph Objects, Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import ast +from odoo import models + + +class StockQuantityHistory(models.TransientModel): + _inherit = 'stock.quantity.history' + + def open_table(self): + action = super(StockQuantityHistory, self).open_table() + # 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('valuation') and not self.location_id: + domain = ast.literal_eval(action['domain']) + domain.pop(domain.index(('qty_available', '!=', 0))) + action['domain'] = domain + 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 fc09cdf..4ce6489 100644 --- a/stock_account_quantity_history_location/wizards/stock_quantity_history.xml +++ b/stock_account_quantity_history_location/wizards/stock_quantity_history.xml @@ -9,7 +9,7 @@ -