From 29471fa294bd0c1516e079aaa2b69b2bc8f146cf Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Wed, 6 Nov 2019 12:30:57 +0100 Subject: [PATCH] [MIG] stock_move_location to v12 [FIX] improvement move line generation --- stock_move_location/README.rst | 1 + stock_move_location/__manifest__.py | 2 +- stock_move_location/models/stock_move.py | 4 ++-- stock_move_location/readme/CONTRIBUTORS.rst | 1 + stock_move_location/tests/test_common.py | 6 ++--- .../tests/test_move_location.py | 10 ++++---- .../wizard/stock_move_location.py | 23 ++++++++++--------- .../wizard/stock_move_location.xml | 8 ++----- .../wizard/stock_move_location_line.py | 19 ++++----------- 9 files changed, 32 insertions(+), 42 deletions(-) diff --git a/stock_move_location/README.rst b/stock_move_location/README.rst index 8b62edec7..30af0743e 100644 --- a/stock_move_location/README.rst +++ b/stock_move_location/README.rst @@ -89,6 +89,7 @@ Contributors * Mathieu Vatel * Mykhailo Panarin * Sergio Teruel +* Joan Sisquella Maintainers ~~~~~~~~~~~ diff --git a/stock_move_location/__manifest__.py b/stock_move_location/__manifest__.py index c5df55d68..531a97ae9 100644 --- a/stock_move_location/__manifest__.py +++ b/stock_move_location/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Move Stock Location", - "version": "11.0.1.1.0", + "version": "12.0.1.1.0", "author": "Julius Network Solutions, " "Odoo Community Association (OCA)", "summary": "This module allows to move all stock " diff --git a/stock_move_location/models/stock_move.py b/stock_move_location/models/stock_move.py index c8f252f16..437c679a5 100644 --- a/stock_move_location/models/stock_move.py +++ b/stock_move_location/models/stock_move.py @@ -15,5 +15,5 @@ class StockMove(models.Model): @api.depends("location_move") def _compute_show_details_visible(self): super()._compute_show_details_visible() - for move in self: - move.show_details_visible = move.location_move + for move in self.filtered(lambda x: x.location_move): + move.show_details_visible = True diff --git a/stock_move_location/readme/CONTRIBUTORS.rst b/stock_move_location/readme/CONTRIBUTORS.rst index 42ac7b946..b0de51f61 100644 --- a/stock_move_location/readme/CONTRIBUTORS.rst +++ b/stock_move_location/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Mathieu Vatel * Mykhailo Panarin * Sergio Teruel +* Joan Sisquella \ No newline at end of file diff --git a/stock_move_location/tests/test_common.py b/stock_move_location/tests/test_common.py index bb158ce15..04769281c 100644 --- a/stock_move_location/tests/test_common.py +++ b/stock_move_location/tests/test_common.py @@ -26,18 +26,18 @@ class TestsCommon(common.SavepointCase): "usage": "internal", "active": True, }) - cls.uom_unit = cls.env.ref('product.product_uom_unit') + cls.uom_unit = cls.env.ref('uom.product_uom_unit') cls.product_no_lots = product_obj.create({ "name": "Pineapple", "type": "product", "tracking": "none", - 'categ_id': cls.env.ref('product.product_category_all').id, + 'category_id': cls.env.ref('product.product_category_all').id, }) cls.product_lots = product_obj.create({ "name": "Pineapple", "type": "product", "tracking": "lot", - 'categ_id': cls.env.ref('product.product_category_all').id, + 'category_id': cls.env.ref('product.product_category_all').id, }) cls.lot1 = cls.env['stock.production.lot'].create({ 'product_id': cls.product_lots.id, diff --git a/stock_move_location/tests/test_move_location.py b/stock_move_location/tests/test_move_location.py index 07271f0ce..57825106f 100644 --- a/stock_move_location/tests/test_move_location.py +++ b/stock_move_location/tests/test_move_location.py @@ -21,7 +21,7 @@ class TestMoveLocation(TestsCommon): def test_move_location_wizard(self): """Test a simple move.""" wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) - wizard.add_lines() + wizard.onchange_origin_location() wizard.action_move_location() self.check_product_amount( self.product_no_lots, self.internal_loc_1, 0, @@ -51,14 +51,14 @@ class TestMoveLocation(TestsCommon): def test_move_location_wizard_amount(self): """Can't move more than exists.""" wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) - wizard.add_lines() + wizard.onchange_origin_location() with self.assertRaises(ValidationError): wizard.stock_move_location_line_ids[0].move_quantity += 1 def test_move_location_wizard_ignore_reserved(self): """Can't move more than exists.""" wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) - wizard.add_lines() + wizard.onchange_origin_location() # reserve some quants self.quant_obj._update_reserved_quantity( self.product_no_lots, @@ -86,7 +86,7 @@ class TestMoveLocation(TestsCommon): def test_wizard_clear_lines(self): """Test lines getting cleared properly.""" wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) - wizard.add_lines() + wizard.onchange_origin_location() self.assertEqual(len(wizard.stock_move_location_line_ids), 4) wizard._onchange_destination_location_id() self.assertEqual(len(wizard.stock_move_location_line_ids), 4) @@ -99,7 +99,7 @@ class TestMoveLocation(TestsCommon): def test_planned_transfer(self): """Test planned transfer.""" wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2) - wizard.add_lines() + wizard.onchange_origin_location() wizard.with_context({'planned': True}).action_move_location() picking = wizard.picking_id self.assertEqual(picking.state, 'draft') diff --git a/stock_move_location/wizard/stock_move_location.py b/stock_move_location/wizard/stock_move_location.py index 42bd5af32..0bbea79e7 100644 --- a/stock_move_location/wizard/stock_move_location.py +++ b/stock_move_location/wizard/stock_move_location.py @@ -9,6 +9,7 @@ from odoo.fields import first class StockMoveLocationWizard(models.TransientModel): _name = "wiz.stock.move.location" + _description = 'Wizard move location' origin_location_id = fields.Many2one( string='Origin Location', @@ -22,10 +23,9 @@ class StockMoveLocationWizard(models.TransientModel): required=True, domain=lambda self: self._get_locations_domain(), ) - stock_move_location_line_ids = fields.One2many( + stock_move_location_line_ids = fields.Many2many( string="Move Location lines", comodel_name="wiz.stock.move.location.line", - inverse_name="move_location_wizard_id", ) picking_id = fields.Many2one( string="Connected Picking", @@ -175,23 +175,24 @@ class StockMoveLocationWizard(models.TransientModel): # cursor returns None instead of False 'lot_id': group.get("lot_id") or False, 'product_uom_id': product.uom_id.id, - 'move_location_wizard_id': self.id, 'custom': False, }) return product_data - def add_lines(self): - self.ensure_one() - line_model = self.env["wiz.stock.move.location.line"] - if not self.stock_move_location_line_ids: + @api.onchange('origin_location_id') + def onchange_origin_location(self): + lines = [] + if self.origin_location_id: + line_model = self.env["wiz.stock.move.location.line"] for line_val in self._get_stock_move_location_lines_values(): if line_val.get('max_quantity') <= 0: continue line = line_model.create(line_val) - line.onchange_product_id() - return { - "type": "ir.actions.do_nothing", - } + line.max_quantity = line.get_max_quantity() + lines.append(line) + # self.stock_move_location_line_ids = [(4, line.id)] + self.update({'stock_move_location_line_ids': [ + (6, 0, [line.id for line in lines])]}) def clear_lines(self): self._clear_lines() diff --git a/stock_move_location/wizard/stock_move_location.xml b/stock_move_location/wizard/stock_move_location.xml index 32f4399ca..895ccb0db 100755 --- a/stock_move_location/wizard/stock_move_location.xml +++ b/stock_move_location/wizard/stock_move_location.xml @@ -11,15 +11,11 @@ - -