Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] delivery_roulier: raise when no pack found and fix tests #855

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion delivery_roulier/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions delivery_roulier/models/stock_quant_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions delivery_roulier/tests/test_delivery_roulier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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]
Expand Down
Loading