Skip to content

Commit

Permalink
Merge PR #853 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by rousseldenis
  • Loading branch information
OCA-git-bot committed Sep 23, 2024
2 parents 0c29bca + 3720516 commit 97f24d3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
13 changes: 0 additions & 13 deletions base_delivery_carrier_label/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions base_delivery_carrier_label/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
* Dave Lasley <dave@laslabs.com>
* Timothée Ringeard <timothee.ringeard@camptocamp.com>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
* Raphaël Reverdy <raphael.reverdy@akretion.com>
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

0 comments on commit 97f24d3

Please sign in to comment.