@@ -1345,135 +1345,6 @@ def test_rounding_half_up_in_progress_02(self):
13451345 "Quantity in progress should be the rounded down after confirmation" ,
13461346 )
13471347
1348- def test_route_id_propagation_on_creation (self ):
1349- order_vals = {
1350- "company_id" : self .main_company .id ,
1351- "warehouse_id" : self .warehouse .id ,
1352- "location_id" : self .warehouse .lot_stock_id .id ,
1353- "expected_date" : fields .Datetime .now (),
1354- "route_id" : self .route .id ,
1355- "stock_request_ids" : [
1356- Command .create (
1357- {
1358- "product_id" : self .product .id ,
1359- "product_uom_id" : self .product .uom_id .id ,
1360- "product_uom_qty" : 5.0 ,
1361- },
1362- ),
1363- Command .create (
1364- {
1365- "product_id" : self .product .id ,
1366- "product_uom_id" : self .product .uom_id .id ,
1367- "product_uom_qty" : 10.0 ,
1368- },
1369- ),
1370- ],
1371- }
1372- order = self .request_order .create (order_vals )
1373- self .assertEqual (len (order .stock_request_ids ), 2 )
1374- order .write ({"route_id" : self .route_3 })
1375- for request in order .stock_request_ids :
1376- self .assertEqual (
1377- request .route_id .id ,
1378- order .route_id .id ,
1379- "The route_id from stock.request.order has not "
1380- "been set in the associated stock.requests." ,
1381- )
1382-
1383- def test_compute_route_id_consistency_1 (self ):
1384- order_vals = {
1385- "company_id" : self .main_company .id ,
1386- "warehouse_id" : self .warehouse .id ,
1387- "location_id" : self .warehouse .lot_stock_id .id ,
1388- "expected_date" : fields .Datetime .now (),
1389- "stock_request_ids" : [
1390- Command .create (
1391- {
1392- "product_id" : self .product .id ,
1393- "product_uom_id" : self .product .uom_id .id ,
1394- "product_uom_qty" : 5.0 ,
1395- "route_id" : self .route .id ,
1396- },
1397- ),
1398- Command .create (
1399- {
1400- "product_id" : self .product .id ,
1401- "product_uom_id" : self .product .uom_id .id ,
1402- "product_uom_qty" : 10.0 ,
1403- "route_id" : self .route_3 .id ,
1404- },
1405- ),
1406- ],
1407- }
1408- order = self .request_order .create (order_vals )
1409- order ._compute_route_id ()
1410- self .assertFalse (
1411- order .route_id ,
1412- "Route ID should be False due to inconsistent routes in stock requests." ,
1413- )
1414-
1415- def test_compute_route_id_consistency_2 (self ):
1416- order_vals = {
1417- "company_id" : self .main_company .id ,
1418- "warehouse_id" : self .warehouse .id ,
1419- "location_id" : self .warehouse .lot_stock_id .id ,
1420- "expected_date" : fields .Datetime .now (),
1421- "stock_request_ids" : [
1422- Command .create (
1423- {
1424- "product_id" : self .product .id ,
1425- "product_uom_id" : self .product .uom_id .id ,
1426- "product_uom_qty" : 5.0 ,
1427- "route_id" : self .route .id ,
1428- },
1429- ),
1430- Command .create (
1431- {
1432- "product_id" : self .product .id ,
1433- "product_uom_id" : self .product .uom_id .id ,
1434- "product_uom_qty" : 10.0 ,
1435- "route_id" : self .route .id ,
1436- },
1437- ),
1438- ],
1439- }
1440- order = self .request_order .create (order_vals )
1441- order ._compute_route_id ()
1442- self .assertEqual (order .route_id , self .route )
1443-
1444- def test_inverse_route_id_propagation (self ):
1445- order_vals = {
1446- "company_id" : self .main_company .id ,
1447- "warehouse_id" : self .warehouse .id ,
1448- "location_id" : self .warehouse .lot_stock_id .id ,
1449- "expected_date" : fields .Datetime .now (),
1450- "stock_request_ids" : [
1451- Command .create (
1452- {
1453- "product_id" : self .product .id ,
1454- "product_uom_id" : self .product .uom_id .id ,
1455- "product_uom_qty" : 5.0 ,
1456- },
1457- ),
1458- Command .create (
1459- {
1460- "product_id" : self .product .id ,
1461- "product_uom_id" : self .product .uom_id .id ,
1462- "product_uom_qty" : 10.0 ,
1463- },
1464- ),
1465- ],
1466- }
1467- order = self .request_order .create (order_vals )
1468- order .route_id = self .route .id
1469- order ._inverse_route_id ()
1470- for request in order .stock_request_ids :
1471- self .assertEqual (
1472- request .route_id .id ,
1473- self .route .id ,
1474- "Route ID should propagate to all stock requests." ,
1475- )
1476-
14771348 def test_onchange_route_id_propagation (self ):
14781349 order_vals = {
14791350 "company_id" : self .main_company .id ,
@@ -1641,3 +1512,69 @@ def test_two_pickings_related(self):
16411512 order = self .request_order .with_user (self .stock_request_user ).create (vals )
16421513 order .with_user (self .stock_request_manager ).action_confirm ()
16431514 self .assertEqual (len (order .mapped ("picking_ids" )), 2 )
1515+
1516+ def test_route_consistency (self ):
1517+ vals = {
1518+ "company_id" : self .main_company .id ,
1519+ "warehouse_id" : self .warehouse .id ,
1520+ "location_id" : self .warehouse .lot_stock_id .id ,
1521+ "route_id" : self .route .id ,
1522+ "expected_date" : fields .Datetime .now (),
1523+ }
1524+ order = self .request_order .with_user (self .stock_request_user ).create (vals )
1525+ self .assertEqual (
1526+ order .route_id , self .route , "Order should have the initial route set"
1527+ )
1528+ self .product_test .route_ids = [Command .set (self .route .ids )]
1529+ line_vals = {
1530+ "product_id" : self .product_test .id ,
1531+ "product_uom_id" : self .product_test .uom_id .id ,
1532+ "product_uom_qty" : 5.0 ,
1533+ "order_id" : order .id ,
1534+ }
1535+ line = self .env ["stock.request" ].new (line_vals )
1536+ line .onchange_product_id ()
1537+ self .assertEqual (
1538+ line .route_id , self .route , "Line should auto-fill route from Order"
1539+ )
1540+ line_vals ["route_id" ] = line .route_id .id
1541+ line1 = self .stock_request .with_user (self .stock_request_user ).create (line_vals )
1542+ self .assertEqual (line1 .route_id , self .route )
1543+ self .assertEqual (
1544+ order .route_id ,
1545+ self .route ,
1546+ "Order route should be preserved after adding line" ,
1547+ )
1548+ line2 = self .stock_request .with_user (self .stock_request_user ).create (
1549+ {
1550+ "order_id" : order .id ,
1551+ "product_id" : self .product_test .id ,
1552+ "product_uom_id" : self .product_test .uom_id .id ,
1553+ "product_uom_qty" : 1.0 ,
1554+ }
1555+ )
1556+ self .assertEqual (
1557+ order .route_id ,
1558+ self .route ,
1559+ "Order route should be preserved when adding line" ,
1560+ )
1561+ # Test clearing route on line clears order route
1562+ line1 .route_id = False
1563+ line1 .onchange_route_id ()
1564+ self .assertFalse (
1565+ order .route_id , "Order route should be cleared when line route is cleared"
1566+ )
1567+ # Test setting route on order propagates to lines
1568+ order .route_id = self .route
1569+ order ._onchange_route_id ()
1570+ self .assertEqual (
1571+ line1 .route_id , self .route , "Line 1 should have route propagated"
1572+ )
1573+ self .assertEqual (
1574+ line2 .route_id , self .route , "Line 2 should have route propagated"
1575+ )
1576+ # Test clearing route on order clears all lines
1577+ order .route_id = False
1578+ order ._onchange_route_id ()
1579+ self .assertFalse (line1 .route_id , "Line 1 route should be cleared" )
1580+ self .assertFalse (line2 .route_id , "Line 2 route should be cleared" )
0 commit comments