|
| 1 | +# Copyright 2023 ACSONE SA/NV |
| 2 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
| 3 | +from odoo import Command |
| 4 | +from odoo.tests.common import TransactionCase |
| 5 | + |
| 6 | + |
| 7 | +class TestStockPickingDeliveryPackage(TransactionCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + super().setUpClass() |
| 11 | + cls.warehouse = cls.env.ref("stock.warehouse0") |
| 12 | + cls.stock_move_obj = cls.env["stock.move"] |
| 13 | + cls.warehouse.delivery_steps = "pick_ship" |
| 14 | + cls.pick_type = cls.warehouse.pick_type_id |
| 15 | + |
| 16 | + cls.location_out = cls.env.ref("stock.stock_location_output") |
| 17 | + cls.location_customers = cls.env.ref("stock.stock_location_customers") |
| 18 | + |
| 19 | + cls.delivery_product = cls.env["product.product"].create( |
| 20 | + { |
| 21 | + "name": "Delivery Test", |
| 22 | + "type": "service", |
| 23 | + } |
| 24 | + ) |
| 25 | + cls.carrier = cls.env["delivery.carrier"].create( |
| 26 | + { |
| 27 | + "name": "Delivery Test", |
| 28 | + "product_id": cls.delivery_product.id, |
| 29 | + } |
| 30 | + ) |
| 31 | + |
| 32 | + cls.route = cls.env["stock.route"].search( |
| 33 | + [ |
| 34 | + ("rule_ids.location_dest_id", "=", cls.location_customers.id), |
| 35 | + ("rule_ids.location_src_id", "=", cls.location_out.id), |
| 36 | + ], |
| 37 | + limit=1, |
| 38 | + ) |
| 39 | + cls.rule_out = cls.route.rule_ids.filtered( |
| 40 | + lambda r: r.location_dest_id == cls.location_customers |
| 41 | + ) |
| 42 | + |
| 43 | + cls.pick_type.launch_delivery_package_wizard = True |
| 44 | + cls.package_type = cls.env["stock.package.type"].create( |
| 45 | + {"name": "Package Type A"} |
| 46 | + ) |
| 47 | + |
| 48 | + cls.product = cls.env["product.product"].create( |
| 49 | + { |
| 50 | + "name": "Product Test", |
| 51 | + "type": "product", |
| 52 | + "route_ids": [Command.link(cls.route.id)], |
| 53 | + } |
| 54 | + ) |
| 55 | + cls._create_qty() |
| 56 | + cls.group = cls.env["procurement.group"].create({"name": "Test"}) |
| 57 | + cls.env["procurement.group"].run( |
| 58 | + [ |
| 59 | + cls.group.Procurement( |
| 60 | + cls.product, |
| 61 | + 2.0, |
| 62 | + cls.product.uom_id, |
| 63 | + cls.location_customers, |
| 64 | + cls.product.name, |
| 65 | + "test", |
| 66 | + cls.warehouse.company_id, |
| 67 | + {}, |
| 68 | + ) |
| 69 | + ] |
| 70 | + ) |
| 71 | + cls.move_pick = cls.stock_move_obj.search( |
| 72 | + [ |
| 73 | + ("product_id", "=", cls.product.id), |
| 74 | + ("location_dest_id", "=", cls.location_out.id), |
| 75 | + ] |
| 76 | + ) |
| 77 | + cls.move_out = cls.stock_move_obj.search( |
| 78 | + [ |
| 79 | + ("product_id", "=", cls.product.id), |
| 80 | + ("location_dest_id", "=", cls.location_customers.id), |
| 81 | + ] |
| 82 | + ) |
| 83 | + cls.move_out.picking_id.carrier_id = cls.carrier |
| 84 | + |
| 85 | + @classmethod |
| 86 | + def _create_qty(cls): |
| 87 | + cls.env["stock.quant"].with_context(inventory_mode=True).create( |
| 88 | + { |
| 89 | + "product_id": cls.product.id, |
| 90 | + "inventory_quantity": 10.0, |
| 91 | + "location_id": cls.env.ref("stock.stock_location_stock").id, |
| 92 | + } |
| 93 | + )._apply_inventory() |
| 94 | + |
| 95 | + def test_picking_delivery(self): |
| 96 | + result = self.move_pick.picking_id.action_put_in_pack() |
| 97 | + self.assertEqual(result.get("res_model"), "choose.delivery.package") |
0 commit comments