|
| 1 | +# Copyright 2023 Camptocamp SA |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) |
| 3 | + |
| 4 | +from odoo.addons.shopfloor.tests.common import CommonCase |
| 5 | + |
| 6 | + |
| 7 | +class TestActionsStock(CommonCase): |
| 8 | + @classmethod |
| 9 | + def setUpClassVars(cls): |
| 10 | + super().setUpClassVars() |
| 11 | + cls.wh = cls.env.ref("stock.warehouse0") |
| 12 | + cls.location_customers = cls.env.ref("stock.stock_location_customers") |
| 13 | + cls.picking_type = cls.wh.out_type_id |
| 14 | + cls.picking_type.sudo().write( |
| 15 | + {"default_location_dest_id": cls.location_customers.id} |
| 16 | + ) |
| 17 | + cls.picking_type_in = cls.picking_type.return_picking_type_id |
| 18 | + cls.picking_type_in.sudo().write( |
| 19 | + {"default_location_src_id": cls.location_customers.id} |
| 20 | + ) |
| 21 | + |
| 22 | + @classmethod |
| 23 | + def setUpClass(cls): |
| 24 | + super().setUpClass() |
| 25 | + with cls.work_on_actions(cls) as work: |
| 26 | + cls.stock = work.component(usage="stock") |
| 27 | + cls.picking = cls._create_picking( |
| 28 | + lines=[(cls.product_a, 10), (cls.product_b, 10)], confirm=True |
| 29 | + ) |
| 30 | + cls.move0 = cls.picking.move_lines[0] |
| 31 | + cls.move1 = cls.picking.move_lines[1] |
| 32 | + cls._fill_stock_for_moves(cls.move0) |
| 33 | + cls._fill_stock_for_moves(cls.move1) |
| 34 | + cls.picking.action_assign() |
| 35 | + cls.picking._action_done() |
| 36 | + |
| 37 | + def test_create_return_move(self): |
| 38 | + # For incoming returns, moves are set to `to_refund` |
| 39 | + return_picking = self.stock.create_return_picking( |
| 40 | + self.picking, self.picking_type_in, "potato" |
| 41 | + ) |
| 42 | + return_moves = self.stock.create_return_move( |
| 43 | + return_picking, self.picking.move_lines |
| 44 | + ) |
| 45 | + self.assertTrue(all(move.to_refund for move in return_moves)) |
| 46 | + return_picking.action_assign() |
| 47 | + return_picking._action_done() |
| 48 | + |
| 49 | + # However, on outgoing returns, this field is False |
| 50 | + outgoing_return = self.stock.create_return_picking( |
| 51 | + return_picking, self.picking_type, "potato" |
| 52 | + ) |
| 53 | + outgoing_moves = self.stock.create_return_move(outgoing_return, return_moves) |
| 54 | + self.assertTrue(all(not move.to_refund for move in outgoing_moves)) |
0 commit comments