|
| 1 | +from odoo.tests import TransactionCase |
| 2 | + |
| 3 | +from odoo.addons.openupgrade_framework import openupgrade_test |
| 4 | + |
| 5 | + |
| 6 | +@openupgrade_test |
| 7 | +class TestStockMigration(TransactionCase): |
| 8 | + def test_picking_type_required_fields(self): |
| 9 | + """Test that newly required fields are set""" |
| 10 | + # TODO: this fails with demo data |
| 11 | + for picking_type in self.env["stock.picking.type"].search([]): |
| 12 | + self.assertTrue(picking_type.default_location_src_id) |
| 13 | + self.assertTrue(picking_type.default_location_dest_id) |
| 14 | + |
| 15 | + def test_pull_moves(self): |
| 16 | + """ |
| 17 | + Test that pull moves have been migrated correctly and new moves yield the |
| 18 | + same result |
| 19 | + """ |
| 20 | + product = self.env.ref("openupgrade_test_stock.pull_product") |
| 21 | + stock_location = self.env.ref("stock.stock_location_stock") |
| 22 | + intermediate_location = self.env.ref( |
| 23 | + "openupgrade_test_stock.intermediate_pull_location" |
| 24 | + ) |
| 25 | + customer_location = self.env.ref("stock.stock_location_customers") |
| 26 | + |
| 27 | + moves = self.env["stock.move"].search([("product_id", "=", product.id)]) |
| 28 | + from_stock = moves.filtered(lambda x: x.location_id == stock_location) |
| 29 | + from_intermediate = moves.filtered( |
| 30 | + lambda x: x.location_id == intermediate_location |
| 31 | + ) |
| 32 | + |
| 33 | + self.assertEqual(from_stock.location_dest_id, intermediate_location) |
| 34 | + self.assertEqual(from_stock.location_final_id, intermediate_location) |
| 35 | + |
| 36 | + self.assertEqual(from_intermediate.location_dest_id, customer_location) |
| 37 | + self.assertEqual(from_intermediate.location_final_id, customer_location) |
| 38 | + |
| 39 | + # TODO: this should be done by migration |
| 40 | + self.env["stock.rule"].search( |
| 41 | + [ |
| 42 | + "|", |
| 43 | + ("location_src_id", "=", intermediate_location.id), |
| 44 | + ("location_dest_id", "=", intermediate_location.id), |
| 45 | + ] |
| 46 | + ).location_dest_from_rule = True |
| 47 | + |
| 48 | + procurement_group = self.env["procurement.group"].create( |
| 49 | + { |
| 50 | + "name": "2 step procurement v18", |
| 51 | + } |
| 52 | + ) |
| 53 | + self.env["procurement.group"].run( |
| 54 | + [ |
| 55 | + self.env["procurement.group"].Procurement( |
| 56 | + product_id=product, |
| 57 | + product_qty=42, |
| 58 | + product_uom=product.uom_id, |
| 59 | + location_id=self.env.ref("stock.stock_location_customers"), |
| 60 | + name="2 step procurement", |
| 61 | + origin="/", |
| 62 | + company_id=self.env.company, |
| 63 | + values={"group_id": procurement_group}, |
| 64 | + ), |
| 65 | + ] |
| 66 | + ) |
| 67 | + |
| 68 | + new_moves = ( |
| 69 | + self.env["stock.move"].search([("product_id", "=", product.id)]) - moves |
| 70 | + ) |
| 71 | + from_stock = new_moves.filtered(lambda x: x.location_id == stock_location) |
| 72 | + from_intermediate = new_moves.filtered( |
| 73 | + lambda x: x.location_id == intermediate_location |
| 74 | + ) |
| 75 | + |
| 76 | + self.assertEqual(from_stock.location_dest_id, intermediate_location) |
| 77 | + self.assertEqual(from_stock.location_final_id, intermediate_location) |
| 78 | + |
| 79 | + self.assertEqual(from_intermediate.location_dest_id, customer_location) |
| 80 | + self.assertEqual(from_intermediate.location_final_id, customer_location) |
| 81 | + |
| 82 | + def test_push_moves(self): |
| 83 | + """ |
| 84 | + Test that push moves have been migrated correctly and new moves yield the |
| 85 | + same result |
| 86 | + """ |
| 87 | + product = self.env.ref("openupgrade_test_stock.push_product") |
| 88 | + stock_location = self.env.ref("stock.stock_location_stock") |
| 89 | + intermediate_location = self.env.ref( |
| 90 | + "openupgrade_test_stock.intermediate_push_location" |
| 91 | + ) |
| 92 | + customer_location = self.env.ref("stock.stock_location_customers") |
| 93 | + |
| 94 | + moves = self.env["stock.move"].search([("product_id", "=", product.id)]) |
| 95 | + |
| 96 | + from_stock = moves.filtered(lambda x: x.location_id == stock_location) |
| 97 | + from_intermediate = moves.filtered( |
| 98 | + lambda x: x.location_id == intermediate_location |
| 99 | + ) |
| 100 | + |
| 101 | + self.assertEqual(from_stock.location_dest_id, intermediate_location) |
| 102 | + # TODO: this fails because we don't set this from move_dest_ids/route_ids |
| 103 | + self.assertEqual(from_stock.location_final_id, customer_location) |
| 104 | + |
| 105 | + self.assertEqual(from_intermediate.location_dest_id, customer_location) |
| 106 | + self.assertEqual(from_intermediate.location_final_id, customer_location) |
| 107 | + |
| 108 | + in_move = self.env["stock.move"].create( |
| 109 | + { |
| 110 | + "name": "in", |
| 111 | + "location_id": self.env.ref("stock.stock_location_suppliers").id, |
| 112 | + "location_dest_id": stock_location.id, |
| 113 | + "location_final_id": customer_location.id, |
| 114 | + "route_ids": [(6, 0, moves.route_ids.ids)], |
| 115 | + "product_id": product.id, |
| 116 | + "quantity": 42, |
| 117 | + "product_uom_qty": 42, |
| 118 | + "picked": True, |
| 119 | + } |
| 120 | + ) |
| 121 | + in_move._action_done() |
| 122 | + in_move.move_dest_ids.picked = True |
| 123 | + in_move.move_dest_ids._action_done() |
| 124 | + |
| 125 | + new_moves = ( |
| 126 | + self.env["stock.move"].search([("product_id", "=", product.id)]) - moves |
| 127 | + ) |
| 128 | + |
| 129 | + from_stock = new_moves.filtered(lambda x: x.location_id == stock_location) |
| 130 | + from_intermediate = new_moves.filtered( |
| 131 | + lambda x: x.location_id == intermediate_location |
| 132 | + ) |
| 133 | + |
| 134 | + self.assertEqual(from_stock.location_dest_id, intermediate_location) |
| 135 | + self.assertEqual(from_stock.location_final_id, customer_location) |
| 136 | + |
| 137 | + self.assertEqual(from_intermediate.location_dest_id, customer_location) |
| 138 | + self.assertEqual(from_intermediate.location_final_id, customer_location) |
0 commit comments