diff --git a/base_delivery_carrier_label/models/stock_picking.py b/base_delivery_carrier_label/models/stock_picking.py index 7f0f0fff0c..73143c2008 100644 --- a/base_delivery_carrier_label/models/stock_picking.py +++ b/base_delivery_carrier_label/models/stock_picking.py @@ -59,21 +59,8 @@ def attach_shipping_label(self, label): self.env["shipping.label"].with_context(**context_attachment).create(data) ) - def _set_a_default_package(self): - """Pickings using this module must have a package - If not this method put it one silently - """ - for picking in self: - move_lines = picking.move_line_ids.filtered( - lambda s: not s.result_package_id - ) - if move_lines: - picking._put_in_pack(move_lines) - def send_to_shipper(self): self.ensure_one() - if self.env.context.get("set_default_package", True): - self._set_a_default_package() # We consider that label has already been generated in case we have a # carrier tracking ref, this way we may print the labels before shipping # and not generated in second time during shipment diff --git a/base_delivery_carrier_label/readme/CONTRIBUTORS.rst b/base_delivery_carrier_label/readme/CONTRIBUTORS.rst index b658fd7fb9..8df452dd1a 100644 --- a/base_delivery_carrier_label/readme/CONTRIBUTORS.rst +++ b/base_delivery_carrier_label/readme/CONTRIBUTORS.rst @@ -7,3 +7,4 @@ * Dave Lasley * Timothée Ringeard * Pimolnat Suntian +* Raphaël Reverdy diff --git a/delivery_roulier/__manifest__.py b/delivery_roulier/__manifest__.py index b7a4fbfdfa..f938451d2d 100644 --- a/delivery_roulier/__manifest__.py +++ b/delivery_roulier/__manifest__.py @@ -6,7 +6,7 @@ "version": "16.0.1.0.0", "author": "Akretion,Odoo Community Association (OCA)", "summary": "Integration of multiple carriers", - "maintainers": ["florian-dacosta"], + "maintainers": ["florian-dacosta", "hparfr"], "category": "Delivery", "depends": [ "base_delivery_carrier_label", diff --git a/delivery_roulier/models/stock_quant_package.py b/delivery_roulier/models/stock_quant_package.py index c0fe30c958..c63bd07f34 100644 --- a/delivery_roulier/models/stock_quant_package.py +++ b/delivery_roulier/models/stock_quant_package.py @@ -91,6 +91,8 @@ def _parse_response(self, picking, response): def _roulier_generate_labels(self, picking): # send all packs to roulier. It will decide if it makes one call per pack or # one call for all pack depending on the carrier. + if not self: + raise UserError(_("No pack found for picking %s", picking.name)) response = self._call_roulier_api(picking) self._handle_attachments(picking, response) return self._parse_response(picking, response) diff --git a/delivery_roulier/tests/test_delivery_roulier.py b/delivery_roulier/tests/test_delivery_roulier.py index c04aab2c50..55069d82e8 100644 --- a/delivery_roulier/tests/test_delivery_roulier.py +++ b/delivery_roulier/tests/test_delivery_roulier.py @@ -4,6 +4,7 @@ from odoo_test_helper import FakeModelLoader from roulier import roulier +from odoo.exceptions import UserError from odoo.tests.common import TransactionCase roulier_ret = { @@ -100,13 +101,33 @@ def tearDownClass(cls): roulier.get_carriers_action_available = cls.real_get_carriers_action_available super().tearDownClass() + def test_roulier_no_pack(self): + # having a pack is mandatory for roulier + # it should fail if no pack provided. + # in <16 packs were silently created + roulier.get_carriers_action_available = MagicMock( + return_value={"test": ["get_label"]} + ) + with patch("roulier.roulier.get") as mock_roulier: + mock_roulier.return_value = roulier_ret + self.assertRaises(UserError, self.picking.send_to_shipper) + def test_roulier(self): roulier.get_carriers_action_available = MagicMock( return_value={"test": ["get_label"]} ) with patch("roulier.roulier.get") as mock_roulier: mock_roulier.return_value = roulier_ret + + # create pack + move_lines = self.picking.move_line_ids.filtered( + lambda s: not s.result_package_id + ) + if move_lines: + self.picking._put_in_pack(move_lines) + self.picking.send_to_shipper() + roulier_args = mock_roulier.mock_calls[0][1] self.assertEqual("get_label", roulier_args[1]) roulier_payload = roulier_args[2]