# Copyright 2026 Criptomart # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import Command from odoo.tests import TransactionCase from odoo.tests import tagged @tagged("-at_install", "post_install") class TestCollectedPicked(TransactionCase): """Collecting a line protects its quantity from the reservation engine.""" @classmethod def setUpClass(cls): super().setUpClass() cls.stock_location = cls.env.ref("stock.stock_location_stock") cls.customer_location = cls.env.ref("stock.stock_location_customers") cls.picking_type = cls.env.ref("stock.picking_type_out") cls.product = cls.env["product.product"].create( { "name": "Collected Apples", "is_storable": True, "uom_id": cls.env.ref("uom.product_uom_kgm").id, "uom_po_id": cls.env.ref("uom.product_uom_kgm").id, } ) cls.env["stock.quant"]._update_available_quantity( cls.product, cls.stock_location, 50.0 ) def _create_picking(self, demand): picking = self.env["stock.picking"].create( { "picking_type_id": self.picking_type.id, "location_id": self.stock_location.id, "location_dest_id": self.customer_location.id, "move_ids": [ Command.create( { "name": self.product.name, "product_id": self.product.id, "product_uom": self.product.uom_id.id, "product_uom_qty": demand, "location_id": self.stock_location.id, "location_dest_id": self.customer_location.id, } ) ], } ) picking.action_confirm() picking.action_assign() return picking def test_collecting_a_line_marks_it_picked(self): picking = self._create_picking(2.0) line = picking.move_ids.move_line_ids line.is_collected = True self.assertTrue(line.picked) self.assertTrue(picking.move_ids.picked) def test_collecting_a_line_keeps_its_demand(self): """Only a hand-typed quantity lowers the demand, collecting does not.""" picking = self._create_picking(2.0) move = picking.move_ids move.move_line_ids.write({"quantity": 1.5, "picked": True}) move.move_line_ids.is_collected = True self.assertEqual(move.product_uom_qty, 1.5) self.assertTrue(move.picked)