diff --git a/stock_quant_manual_assign/README.rst b/stock_quant_manual_assign/README.rst index 84e03791487b..c5b2b94960ba 100644 --- a/stock_quant_manual_assign/README.rst +++ b/stock_quant_manual_assign/README.rst @@ -160,6 +160,10 @@ Contributors - Tony Gu tony@openerp.cn +* `Quartile `_: + + * Yoshi Tashiro + Maintainers ----------- diff --git a/stock_quant_manual_assign/readme/CONTRIBUTORS.md b/stock_quant_manual_assign/readme/CONTRIBUTORS.md index 02832e33f84e..5d07a72118d2 100644 --- a/stock_quant_manual_assign/readme/CONTRIBUTORS.md +++ b/stock_quant_manual_assign/readme/CONTRIBUTORS.md @@ -15,3 +15,7 @@ * `Shine IT `_: * Tony Gu + +* `Quartile `_: + + * Yoshi Tashiro diff --git a/stock_quant_manual_assign/static/description/index.html b/stock_quant_manual_assign/static/description/index.html index 332f3990ed40..5e11ba9c7ce3 100644 --- a/stock_quant_manual_assign/static/description/index.html +++ b/stock_quant_manual_assign/static/description/index.html @@ -493,6 +493,10 @@

Contributors

  • Tony Gu tony@openerp.cn
  • +
  • Quartile:
      +
    • Yoshi Tashiro
    • +
    +
  • diff --git a/stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py b/stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py index b87b2b85299b..a986fc373b8e 100644 --- a/stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py +++ b/stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py @@ -9,68 +9,33 @@ class TestStockQuantManualAssign(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) - cls.quant_model = cls.env["stock.quant"] - cls.picking_model = cls.env["stock.picking"] - cls.location_model = cls.env["stock.location"] - cls.move_model = cls.env["stock.move"] cls.quant_assign_wizard = cls.env["assign.manual.quants"] - cls.ModelDataObj = cls.env["ir.model.data"] cls.product = cls.env["product.product"].create( {"name": "Product 4 test", "type": "product"} ) cls.location_src = cls.env.ref("stock.stock_location_locations_virtual") cls.location_dst = cls.env.ref("stock.stock_location_customers") - cls.picking_type_out = cls.ModelDataObj._xmlid_to_res_id( + cls.picking_type_out = cls.env["ir.model.data"]._xmlid_to_res_id( "stock.picking_type_out" ) cls.env["stock.picking.type"].browse( cls.picking_type_out ).reservation_method = "manual" - cls.location1 = cls.location_model.create( - { - "name": "Location 1", - "usage": "internal", - "location_id": cls.location_src.id, - } - ) - cls.location2 = cls.location_model.create( - { - "name": "Location 2", - "usage": "internal", - "location_id": cls.location_src.id, - } - ) - cls.location3 = cls.location_model.create( - { - "name": "Location 3", - "usage": "internal", - "location_id": cls.location_src.id, - } - ) + cls.location1 = cls._create_location(cls, "Location 1") + cls.location2 = cls._create_location(cls, "Location 2") + cls.location3 = cls._create_location(cls, "Location 3") cls.picking_type = cls.env.ref("stock.picking_type_out") - cls.quant1 = cls.quant_model.sudo().create( + cls.quant1 = cls._create_quant(cls, cls.product, 100.0, cls.location1) + cls.quant2 = cls._create_quant(cls, cls.product, 100.0, cls.location2) + cls.quant3 = cls._create_quant(cls, cls.product, 100.0, cls.location3) + cls.picking = cls.env["stock.picking"].create( { - "product_id": cls.product.id, - "quantity": 100.0, + "picking_type_id": cls.picking_type.id, "location_id": cls.location1.id, + "location_dest_id": cls.location_dst.id, } ) - cls.quant2 = cls.quant_model.sudo().create( - { - "product_id": cls.product.id, - "quantity": 100.0, - "location_id": cls.location2.id, - } - ) - cls.quant3 = cls.quant_model.sudo().create( - { - "product_id": cls.product.id, - "quantity": 100.0, - "location_id": cls.location3.id, - } - ) - cls.move = cls.move_model.create( + cls.move = cls.env["stock.move"].create( { "name": cls.product.name, "product_id": cls.product.id, @@ -78,15 +43,40 @@ def setUpClass(cls): "product_uom": cls.product.uom_id.id, "location_id": cls.location_src.id, "location_dest_id": cls.location_dst.id, - "picking_type_id": cls.picking_type.id, + "picking_id": cls.picking.id, } ) cls.move._action_confirm() - def test_quant_assign_wizard(self): - wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create( - {} + def _create_location(self, name): + return self.env["stock.location"].create( + {"name": name, "usage": "internal", "location_id": self.location_src.id} ) + + def _create_quant(self, product, qty, location): + return ( + self.env["stock.quant"] + .sudo() + .create( + {"product_id": product.id, "quantity": qty, "location_id": location.id} + ) + ) + + def _create_wizard(self): + return ( + self.env["assign.manual.quants"] + .with_context(active_id=self.move.id) + .create({}) + ) + + def _process_basic_manual_assign_steps(self, wizard): + wizard.quants_lines[0].write({"selected": True}) + wizard.quants_lines[0]._onchange_selected() + wizard.quants_lines[1].write({"selected": True, "qty": 50.0}) + self.assertEqual(wizard.lines_qty, 150.0) + + def test_quant_assign_wizard(self): + wizard = self._create_wizard() self.assertEqual( len(wizard.quants_lines.ids), 3, @@ -105,9 +95,7 @@ def test_quant_assign_wizard(self): self.assertEqual(wizard.move_qty, self.move.product_uom_qty) def test_quant_assign_wizard_constraint(self): - wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create( - {} - ) + wizard = self._create_wizard() self.assertEqual( len(wizard.quants_lines.ids), 3, @@ -129,18 +117,13 @@ def test_quant_assign_wizard_constraint(self): ) def test_quant_manual_assign(self): - wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create( - {} - ) + wizard = self._create_wizard() self.assertEqual( len(wizard.quants_lines.ids), 3, "Three quants created, three quants got by default", ) - wizard.quants_lines[0].write({"selected": True}) - wizard.quants_lines[0]._onchange_selected() - wizard.quants_lines[1].write({"selected": True, "qty": 50.0}) - self.assertEqual(wizard.lines_qty, 150.0) + self._process_basic_manual_assign_steps(wizard) self.assertEqual(wizard.move_qty, 250.0) wizard.assign_quants() self.assertAlmostEqual( @@ -151,24 +134,25 @@ def test_quant_manual_assign(self): self.assertFalse(self.move.picking_type_id.auto_fill_qty_done) self.assertEqual(sum(self.move.move_line_ids.mapped("qty_done")), 0.0) - def test_quant_manual_assign_auto_fill_qty_done(self): - wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create( - {} - ) - wizard.quants_lines[0].write({"selected": True}) - wizard.quants_lines[0]._onchange_selected() - wizard.quants_lines[1].write({"selected": True, "qty": 50.0}) - self.assertEqual(wizard.lines_qty, 150.0) + def _process_quant_manual_assign_auto_fill_qty_done(self): + wizard = self._create_wizard() + self._process_basic_manual_assign_steps(wizard) self.picking_type.auto_fill_qty_done = True wizard.assign_quants() self.assertTrue(self.move.picking_type_id.auto_fill_qty_done) self.assertEqual(sum(self.move.move_line_ids.mapped("qty_done")), 150.0) + def test_quant_manual_assign_auto_fill_qty_done_planned(self): + self.assertFalse(self.picking.immediate_transfer) + self._process_quant_manual_assign_auto_fill_qty_done() + + def test_quant_manual_assign_auto_fill_qty_done_immediate(self): + self.picking.immediate_transfer = True + self._process_quant_manual_assign_auto_fill_qty_done() + def test_quant_assign_wizard_after_availability_check(self): self.move._action_assign() - wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create( - {} - ) + wizard = self._create_wizard() self.assertEqual( len(wizard.quants_lines.ids), 3, diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index 79e8c44e57f4..329b2ee9d792 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -60,13 +60,16 @@ def _compute_qties(self): def assign_quants(self): move = self.move_id - move._do_unreserve() + self.move_id.move_line_ids.unlink() for line in self.quants_lines: line._assign_quant_line() if move.picking_type_id.auto_fill_qty_done: - # Auto-fill all lines as done - for ml in move.move_line_ids: - ml.qty_done = ml.reserved_uom_qty + if move.from_immediate_transfer: + move.quantity_done = self.lines_qty + else: + # Auto-fill all lines as done + for ml in move.move_line_ids: + ml.qty_done = ml.reserved_uom_qty move._recompute_state() move.mapped("picking_id")._compute_state() return {}