22# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
33
44from odoo .tests import Form
5+
56from odoo .addons .stock_product_variant_mto .tests .common import TestMTOVariantCommon
67
78
89class TestMtoAsMtsVariant (TestMTOVariantCommon ):
9-
1010 @classmethod
1111 def setUpClass (cls ):
1212 super ().setUpClass ()
@@ -25,6 +25,7 @@ def setUpClass(cls):
2525 ]
2626 )
2727 cls .warehouse = cls .env .ref ("stock.warehouse0" )
28+ cls .warehouse .mto_as_mts = True
2829
2930 @classmethod
3031 def setUpClassProduct (cls ):
@@ -49,21 +50,41 @@ def _get_orderpoint_for_products(self, products, archived=False):
4950 orderpoint = self .env ["stock.warehouse.orderpoint" ]
5051 if archived :
5152 orderpoint = orderpoint .with_context (active_test = False )
52- return orderpoint .search (
53- [("product_id" , "in" , products .ids )]
54- )
53+ return orderpoint .search ([("product_id" , "in" , products .ids )])
54+
55+ def test_mto_as_mts_orderpoint_warehouse_archive (self ):
56+ black_pen = self .black_pen
57+ order = self ._create_sale_order (black_pen )
58+ order .action_confirm ()
59+ orderpoint = self ._get_orderpoint_for_products (black_pen )
60+ self .assertTrue (orderpoint )
61+ self .warehouse .mto_as_mts = False
62+ orderpoint = self ._get_orderpoint_for_products (black_pen )
63+ self .assertFalse (orderpoint )
64+
65+ def test_mto_as_mts_orderpoint_product_archive (self ):
66+ black_pen = self .black_pen
67+ order = self ._create_sale_order (black_pen )
68+ order .action_confirm ()
69+ orderpoint = self ._get_orderpoint_for_products (black_pen )
70+ self .assertTrue (orderpoint )
71+ self .toggle_is_mto (black_pen )
72+ orderpoint = self ._get_orderpoint_for_products (black_pen )
73+ self .assertFalse (orderpoint )
5574
5675 def test_mto_as_mts_orderpoint (self ):
57- template_pen = self .template_pen
5876 black_pen = self .black_pen
5977 blue_pen = self .blue_pen
6078 red_pen = self .red_pen
6179 green_pen = self .green_pen
6280 order = self ._create_sale_order (black_pen )
6381 orderpoint = self ._get_orderpoint_for_products (black_pen )
6482 self .assertFalse (orderpoint )
83+ self .assertIn (self .mto_route , black_pen .route_ids )
84+ self .assertTrue (black_pen .is_mto )
6585 order .action_confirm ()
6686 orderpoint = self ._get_orderpoint_for_products (black_pen )
87+ self .assertTrue (orderpoint )
6788 self .assertEqual (
6889 orderpoint .location_id ,
6990 self .warehouse ._get_locations_for_mto_orderpoints (),
@@ -82,17 +103,24 @@ def test_mto_as_mts_orderpoint(self):
82103 self .assertFalse (self ._get_orderpoint_for_products (black_pen ))
83104 self .assertTrue (self ._get_orderpoint_for_products (black_pen , archived = True ))
84105 other_pens = red_pen | green_pen | blue_pen
85- self .assertEqual (
86- len (self ._get_orderpoint_for_products (other_pens )), 3
87- )
106+ self .assertEqual (len (self ._get_orderpoint_for_products (other_pens )), 3 )
88107
89108 def test_mtp_as_mts_orderpoint_product_no_mto (self ):
109+ self .assertIn (self .buy_route , self .template_pen .route_ids )
90110 template_pen = self .template_pen
91111 black_pen = self .black_pen
92112 variants_pen = self .variants_pen
113+ self .assertIn (self .buy_route , black_pen .route_ids )
93114 # set everything to not mto
94- template_pen .route_ids = False
115+ template_pen .write ({"route_ids" : [(3 , self .mto_route .id , 0 )]})
116+ self .assertIn (self .buy_route , black_pen .route_ids )
117+ self .assertNotIn (self .mto_route , black_pen .route_ids )
118+ self .toggle_is_mto (variants_pen )
119+ self .assertIn (self .mto_route , black_pen .route_ids )
120+ self .assertIn (self .buy_route , black_pen .route_ids )
95121 self .toggle_is_mto (variants_pen )
122+ self .assertNotIn (self .mto_route , black_pen .route_ids )
123+ self .assertIn (self .buy_route , black_pen .route_ids )
96124 # then check that no orderpoint is created
97125 order = self ._create_sale_order (black_pen )
98126 orderpoint = self .env ["stock.warehouse.orderpoint" ].search (
0 commit comments