From 4854c59a8381d7f441cef8747f366f1111c9c3a9 Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Tue, 14 Jan 2020 13:47:57 +0100 Subject: [PATCH] [MIG] stock_move_location: Migration to 13.0 --- stock_move_location/__init__.py | 1 + stock_move_location/__manifest__.py | 5 +- stock_move_location/data/stock_quant_view.xml | 3 +- stock_move_location/init_hook.py | 10 +++ stock_move_location/readme/CONTRIBUTORS.rst | 6 +- stock_move_location/tests/test_common.py | 68 ++++++++++++------- .../tests/test_move_location.py | 8 --- .../wizard/stock_move_location.py | 16 ++--- .../wizard/stock_move_location.xml | 0 .../wizard/stock_move_location_line.py | 10 +-- 10 files changed, 69 insertions(+), 58 deletions(-) mode change 100755 => 100644 stock_move_location/data/stock_quant_view.xml create mode 100644 stock_move_location/init_hook.py mode change 100755 => 100644 stock_move_location/wizard/stock_move_location.xml diff --git a/stock_move_location/__init__.py b/stock_move_location/__init__.py index 91ba63a47..d1dcf0d2a 100644 --- a/stock_move_location/__init__.py +++ b/stock_move_location/__init__.py @@ -4,3 +4,4 @@ from . import wizard from . import models +from .init_hook import enable_multi_locations diff --git a/stock_move_location/__manifest__.py b/stock_move_location/__manifest__.py index a2c60d32d..9feb57a27 100644 --- a/stock_move_location/__manifest__.py +++ b/stock_move_location/__manifest__.py @@ -4,8 +4,8 @@ { "name": "Move Stock Location", - "version": "12.0.1.2.0", - "author": "Julius Network Solutions, " "Odoo Community Association (OCA)", + "version": "13.0.1.0.0", + "author": "Julius Network Solutions, Odoo Community Association (OCA)", "summary": "This module allows to move all stock " "in a stock location to an other one.", "website": "https://github.com/OCA/stock-logistics-warehouse", @@ -17,4 +17,5 @@ "views/stock_picking_type_views.xml", "wizard/stock_move_location.xml", ], + "post_init_hook": "enable_multi_locations", } diff --git a/stock_move_location/data/stock_quant_view.xml b/stock_move_location/data/stock_quant_view.xml old mode 100755 new mode 100644 index d55d803b1..a8e6f1baf --- a/stock_move_location/data/stock_quant_view.xml +++ b/stock_move_location/data/stock_quant_view.xml @@ -5,11 +5,10 @@ diff --git a/stock_move_location/init_hook.py b/stock_move_location/init_hook.py new file mode 100644 index 000000000..0402025ba --- /dev/null +++ b/stock_move_location/init_hook.py @@ -0,0 +1,10 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import SUPERUSER_ID, api + + +def enable_multi_locations(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + ResConfig = env["res.config.settings"] + default_values = ResConfig.default_get(list(ResConfig.fields_get())) + default_values.update({"group_stock_multi_locations": True}) + ResConfig.create(default_values).execute() diff --git a/stock_move_location/readme/CONTRIBUTORS.rst b/stock_move_location/readme/CONTRIBUTORS.rst index 0e307c893..bb0536766 100644 --- a/stock_move_location/readme/CONTRIBUTORS.rst +++ b/stock_move_location/readme/CONTRIBUTORS.rst @@ -1,6 +1,6 @@ * Mathieu Vatel * Mykhailo Panarin * Sergio Teruel -* Joan Sisquella -* Jordi Ballester Alomar -* Lois Rilo +* Joan Sisquella +* Jordi Ballester Alomar +* Lois Rilo diff --git a/stock_move_location/tests/test_common.py b/stock_move_location/tests/test_common.py index bdb67f3d7..21da35c5f 100644 --- a/stock_move_location/tests/test_common.py +++ b/stock_move_location/tests/test_common.py @@ -14,56 +14,63 @@ class TestsCommon(common.SavepointCase): product_obj = cls.env["product.product"] cls.wizard_obj = cls.env["wiz.stock.move.location"] cls.quant_obj = cls.env["stock.quant"] - - # Enable multi-locations: - wizard = cls.env["res.config.settings"].create( - {"group_stock_multi_locations": True} - ) - wizard.execute() + cls.company = cls.env.ref("base.main_company") cls.internal_loc_1 = cls.location_obj.create( - {"name": "INT_1", "usage": "internal", "active": True} + { + "name": "INT_1", + "usage": "internal", + "active": True, + "company_id": cls.company.id, + } ) cls.internal_loc_2 = cls.location_obj.create( - {"name": "INT_2", "usage": "internal", "active": True} + { + "name": "INT_2", + "usage": "internal", + "active": True, + "company_id": cls.company.id, + } ) cls.uom_unit = cls.env.ref("uom.product_uom_unit") cls.product_no_lots = product_obj.create( - { - "name": "Pineapple", - "type": "product", - "tracking": "none", - "category_id": cls.env.ref("product.product_category_all").id, - } + {"name": "Pineapple", "type": "product", "tracking": "none"} ) cls.product_lots = product_obj.create( - { - "name": "Pineapple", - "type": "product", - "tracking": "lot", - "category_id": cls.env.ref("product.product_category_all").id, - } + {"name": "Apple", "type": "product", "tracking": "lot"} ) cls.lot1 = cls.env["stock.production.lot"].create( - {"product_id": cls.product_lots.id} + { + "name": "lot1", + "product_id": cls.product_lots.id, + "company_id": cls.company.id, + } ) cls.lot2 = cls.env["stock.production.lot"].create( - {"product_id": cls.product_lots.id} + { + "name": "lot2", + "product_id": cls.product_lots.id, + "company_id": cls.company.id, + } ) cls.lot3 = cls.env["stock.production.lot"].create( - {"product_id": cls.product_lots.id} + { + "name": "lot3", + "product_id": cls.product_lots.id, + "company_id": cls.company.id, + } ) def setup_product_amounts(self): self.set_product_amount(self.product_no_lots, self.internal_loc_1, 123) self.set_product_amount( - self.product_lots, self.internal_loc_1, 1, lot_id=self.lot1 + self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot1 ) self.set_product_amount( - self.product_lots, self.internal_loc_1, 1, lot_id=self.lot2 + self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot2 ) self.set_product_amount( - self.product_lots, self.internal_loc_1, 1, lot_id=self.lot3 + self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot3 ) def set_product_amount(self, product, location, amount, lot_id=None): @@ -78,3 +85,12 @@ class TestsCommon(common.SavepointCase): ), amount, ) + + def _create_wizard(self, origin_location, destination_location): + move_location_wizard = self.env["wiz.stock.move.location"] + return move_location_wizard.create( + { + "origin_location_id": origin_location.id, + "destination_location_id": destination_location.id, + } + ) diff --git a/stock_move_location/tests/test_move_location.py b/stock_move_location/tests/test_move_location.py index 120166ad8..2b6250848 100644 --- a/stock_move_location/tests/test_move_location.py +++ b/stock_move_location/tests/test_move_location.py @@ -12,14 +12,6 @@ class TestMoveLocation(TestsCommon): super().setUp() self.setup_product_amounts() - def _create_wizard(self, origin_location, destination_location): - return self.wizard_obj.create( - { - "origin_location_id": origin_location.id, - "destination_location_id": destination_location.id, - } - ) - def test_move_location_wizard(self): """Test a simple move.""" wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) diff --git a/stock_move_location/wizard/stock_move_location.py b/stock_move_location/wizard/stock_move_location.py index 8dac23ce7..a8f691cd8 100644 --- a/stock_move_location/wizard/stock_move_location.py +++ b/stock_move_location/wizard/stock_move_location.py @@ -11,7 +11,6 @@ class StockMoveLocationWizard(models.TransientModel): _name = "wiz.stock.move.location" _description = "Wizard move location" - @api.multi def _get_default_picking_type_id(self): company_id = self.env.context.get("company_id") or self.env.user.company_id.id return ( @@ -63,6 +62,9 @@ class StockMoveLocationWizard(models.TransientModel): rec.origin_location_disable = self.env.context.get( "origin_location_disable", False ) + rec.destination_location_disable = self.env.context.get( + "destination_location_disable", False + ) if not rec.edit_locations: rec.origin_location_disable = True rec.destination_location_disable = True @@ -120,7 +122,6 @@ class StockMoveLocationWizard(models.TransientModel): } ) - @api.multi def group_lines(self): lines_grouped = {} for line in self.stock_move_location_line_ids: @@ -130,7 +131,6 @@ class StockMoveLocationWizard(models.TransientModel): lines_grouped[line.product_id.id] |= line return lines_grouped - @api.multi def _create_moves(self, picking): self.ensure_one() groups = self.group_lines() @@ -158,7 +158,6 @@ class StockMoveLocationWizard(models.TransientModel): "location_move": True, } - @api.multi def _create_move(self, picking, lines): self.ensure_one() move = self.env["stock.move"].create(self._get_move_values(picking, lines)) @@ -167,7 +166,6 @@ class StockMoveLocationWizard(models.TransientModel): line.create_move_lines(picking, move) return move - @api.multi def action_move_location(self): self.ensure_one() picking = self._create_picking() @@ -189,18 +187,16 @@ class StockMoveLocationWizard(models.TransientModel): return action def _get_group_quants(self): - location_id = self.origin_location_id.id - company = self.env["res.company"]._company_default_get("stock.inventory") + location_id = self.origin_location_id # Using sql as search_group doesn't support aggregation functions # leading to overhead in queries to DB query = """ SELECT product_id, lot_id, SUM(quantity) FROM stock_quant WHERE location_id = %s - AND company_id = %s GROUP BY product_id, lot_id """ - self.env.cr.execute(query, (location_id, company.id)) + self.env.cr.execute(query, (location_id.id,)) return self.env.cr.dictfetchall() def _get_stock_move_location_lines_values(self): @@ -210,7 +206,7 @@ class StockMoveLocationWizard(models.TransientModel): product = product_obj.browse(group.get("product_id")).exists() # Apply the putaway strategy location_dest_id = ( - self.destination_location_id.get_putaway_strategy(product).id + self.destination_location_id._get_putaway_strategy(product).id or self.destination_location_id.id ) product_data.append( diff --git a/stock_move_location/wizard/stock_move_location.xml b/stock_move_location/wizard/stock_move_location.xml old mode 100755 new mode 100644 diff --git a/stock_move_location/wizard/stock_move_location_line.py b/stock_move_location/wizard/stock_move_location_line.py index 643dededf..514b54eb6 100644 --- a/stock_move_location/wizard/stock_move_location_line.py +++ b/stock_move_location/wizard/stock_move_location_line.py @@ -6,8 +6,6 @@ from odoo import _, api, fields, models from odoo.exceptions import ValidationError from odoo.tools import float_compare -from odoo.addons import decimal_precision as dp - class StockMoveLocationWizardLine(models.TransientModel): _name = "wiz.stock.move.location.line" @@ -31,11 +29,10 @@ class StockMoveLocationWizardLine(models.TransientModel): domain="[('product_id','=',product_id)]", ) move_quantity = fields.Float( - string="Quantity to move", digits=dp.get_precision("Product Unit of Measure") + string="Quantity to move", digits="Product Unit of Measure" ) max_quantity = fields.Float( - string="Maximum available quantity", - digits=dp.get_precision("Product Unit of Measure"), + string="Maximum available quantity", digits="Product Unit of Measure" ) custom = fields.Boolean(string="Custom line", default=True) @@ -78,11 +75,10 @@ class StockMoveLocationWizardLine(models.TransientModel): self.env["stock.move.line"].create(values) return True - @api.multi def _get_move_line_values(self, picking, move): self.ensure_one() location_dest_id = ( - self.destination_location_id.get_putaway_strategy(self.product_id).id + self.destination_location_id._get_putaway_strategy(self.product_id).id or self.destination_location_id.id ) qty_todo, qty_done = self._get_available_quantity()