diff --git a/stock_quantity_history_location/__manifest__.py b/stock_quantity_history_location/__manifest__.py index e69e0c4..1b8c765 100644 --- a/stock_quantity_history_location/__manifest__.py +++ b/stock_quantity_history_location/__manifest__.py @@ -3,18 +3,12 @@ # 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', - 'license': 'AGPL-3', - 'author': 'Eficent,' - 'Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/stock-logistics-reporting', - 'depends': [ - 'stock', - ], - 'data': [ - 'wizards/stock_quantity_history.xml', - ], - + "name": "Stock Quantity History Location", + "summary": "Provides stock quantity by location on past date", + "version": "12.0.1.0.1", + "license": "AGPL-3", + "author": "Eficent," "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 3f1b762..2d70039 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 @@ -5,33 +5,38 @@ from odoo.tests.common import SavepointCase class TestStockQuantityHistoryLocation(SavepointCase): - @classmethod def setUpClass(cls): super(TestStockQuantityHistoryLocation, cls).setUpClass() - 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 - }) + 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 = 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] @@ -40,34 +45,45 @@ class TestStockQuantityHistoryLocation(SavepointCase): move.date = "2019-08-11" 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", - }) + 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) + 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": False, - "compute_at_date": 0, - }) + 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, - }) + 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['domain'], - [('location_id', 'child_of', - 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 5849e68..5b9dd80 100644 --- a/stock_quantity_history_location/wizards/stock_quantity_history.py +++ b/stock_quantity_history_location/wizards/stock_quantity_history.py @@ -2,38 +2,40 @@ # Copyright 2019 Aleph Objects, Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import ast + from odoo import fields, models class StockQuantityHistory(models.TransientModel): - _inherit = 'stock.quantity.history' + _inherit = "stock.quantity.history" location_id = fields.Many2one( - 'stock.location', domain=[('usage', 'in', ['internal', 'transit'])], + "stock.location", domain=[("usage", "in", ["internal", "transit"])] ) - include_child_locations = fields.Boolean('Include child locations', - default=True, - ) + include_child_locations = fields.Boolean("Include child locations", default=True) def open_table(self): action = super(StockQuantityHistory, self).open_table() - ctx = action['context'] + 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.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)] + action["domain"] = [("location_id", "child_of", self.location_id.id)] else: - action['domain'] = [('location_id', '=', self.location_id.id)] + 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): - ctx.pop('company_owned') - action['name'] = '%s (%s)' % (action['name'], - self.location_id.complete_name) - action['context'] = ctx + ctx["location"] = self.location_id.id + ctx["compute_child"] = self.include_child_locations + if ctx.get("company_owned", False): + ctx.pop("company_owned") + action["name"] = "{} ({})".format( + action["name"], self.location_id.complete_name + ) + action["context"] = ctx return action diff --git a/stock_quantity_history_location/wizards/stock_quantity_history.xml b/stock_quantity_history_location/wizards/stock_quantity_history.xml index 864d474..97329f9 100644 --- a/stock_quantity_history_location/wizards/stock_quantity_history.xml +++ b/stock_quantity_history_location/wizards/stock_quantity_history.xml @@ -13,4 +13,3 @@ -