22# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
33import logging
44
5+ from odoo .exceptions import ValidationError
6+
57from .common import TestMTOVariantCommon
68
79onchange_logger = "odoo.tests.form.onchange"
@@ -32,9 +34,8 @@ def test_variants_mto(self):
3234 self .add_route (pen_template , self .mto_route )
3335 self .assertVariantsMTO (pens )
3436 # Disable mto route for black_pen
35- self .toggle_is_mto (black_pen )
36- self .assertVariantsNotMTO (black_pen )
37- self .assertVariantsMTO (blue_pen | green_pen | red_pen )
37+ with self .assertRaises (ValidationError ):
38+ self .toggle_is_mto (black_pen )
3839 # Disable mto route on the template, reset is_mto on variants
3940 with self .assertLogs (onchange_logger , level = "WARNING" ):
4041 self .remove_route (pen_template , self .mto_route )
@@ -49,20 +50,18 @@ def test_template_routes_updated(self):
4950 green_pen = self .green_pen
5051 black_pen = self .black_pen
5152 self .assertVariantsNotMTO (pens )
52- # If template is set to MTO, all variants are updated
53- with self .assertLogs (onchange_logger , level = "WARNING" ):
54- self .add_route (pen_template , self .mto_route )
55- self .assertVariantsMTO (pens )
56- # Now toggle a few variants to is_mto == False
57- self .toggle_is_mto (black_pen | blue_pen )
58- self .assertVariantsMTO (green_pen | red_pen )
59- self .assertVariantsNotMTO (black_pen | blue_pen )
53+ # Now toggle a variant to is_mto
54+ self .toggle_is_mto (black_pen )
55+ self .assertVariantsMTO (black_pen )
56+ self .assertVariantsNotMTO (green_pen | red_pen | blue_pen )
6057 # Now modifying template.route_ids to trigger variant's _compute_is_mto
6158 random_route = self .mto_route .create ({"name" : "loutourout de la vit" })
6259 self .add_route (pen_template , random_route )
63- # Template is still MTO, but variants is_mto shouldn't have changed
64- self .assertVariantsMTO (green_pen | red_pen )
65- self .assertVariantsNotMTO (black_pen | blue_pen )
60+ self .assertVariantsMTO (black_pen )
61+ self .assertVariantsNotMTO (green_pen | red_pen | blue_pen )
62+ self .remove_route (pen_template , random_route )
63+ self .assertVariantsMTO (black_pen )
64+ self .assertVariantsNotMTO (green_pen | red_pen | blue_pen )
6665
6766 def test_template_warnings (self ):
6867 # instanciate variables
@@ -85,19 +84,13 @@ def test_template_warnings(self):
8584 self .assertIn ("Activating MTO route will reset" , log_catcher .output [0 ])
8685 self .assertVariantsMTO (pens )
8786
88- # Disable mto route for black pen
89- self .toggle_is_mto (black_pen )
90- self .assertVariantsNotMTO (black_pen )
91- self .assertVariantsMTO (blue_pen | green_pen | red_pen )
92-
9387 # Enable unrelated route does not raise warning nor reset
9488 random_route = self .mto_route .create ({"name" : "loutourout de la vit" })
9589 with self .assertLogs (onchange_logger ) as log_catcher :
9690 self .add_route (pen_template , random_route )
9791 _logger .info ("No warning raised" )
9892 self .assertNotIn ("WARNING" , log_catcher .output [0 ])
99- self .assertVariantsNotMTO (black_pen )
100- self .assertVariantsMTO (blue_pen | green_pen | red_pen )
93+ self .assertVariantsMTO (pens )
10194
10295 # Disable mto route on the template,
10396 # raise warning as is_mto is reset on variants
0 commit comments