From 9f53beeb32f1381aba8342e7bb2b36e06842063d Mon Sep 17 00:00:00 2001 From: Zahra Velasco Date: Mon, 30 Sep 2024 17:11:40 +0200 Subject: [PATCH] [FIX]delivery_deliverea:Fixes error when recording shipments When you try to record a shipment in Deliverea, it is calling the pickup URL, not allowing any shipment to be recorded and returning an error. --- delivery_deliverea/models/delivery_carrier.py | 19 ++++----- delivery_deliverea/models/stock_picking.py | 2 +- .../tests/test_delivery_deliverea.py | 39 ++++++++++++++++--- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/delivery_deliverea/models/delivery_carrier.py b/delivery_deliverea/models/delivery_carrier.py index aefb9be9a6..3dc2725107 100644 --- a/delivery_deliverea/models/delivery_carrier.py +++ b/delivery_deliverea/models/delivery_carrier.py @@ -458,15 +458,16 @@ def _deliverea_check_response(self, response): def deliverea_return_shipping(self, pickings): deliverea_request = DelivereaRequest(self) for picking in pickings: - vals = self._prepare_deliverea_order(picking) - response = deliverea_request.create_return(vals) - self._deliverea_check_response(response) - picking.write( - { - "carrier_tracking_ref": response.get("carrierReference", ""), - "deliverea_reference": response.get("delivereaReference", ""), - } - ) + if picking.picking_type_code == "incoming": + vals = self._prepare_deliverea_order(picking) + response = deliverea_request.create_return(vals) + self._deliverea_check_response(response) + picking.write( + { + "carrier_tracking_ref": response.get("carrierReference", ""), + "deliverea_reference": response.get("delivereaReference", ""), + } + ) return True def deliverea_cancel_shipment(self, pickings): diff --git a/delivery_deliverea/models/stock_picking.py b/delivery_deliverea/models/stock_picking.py index ffc42b4ab4..ae13019598 100644 --- a/delivery_deliverea/models/stock_picking.py +++ b/delivery_deliverea/models/stock_picking.py @@ -21,7 +21,7 @@ def deliverea_get_label(self): def send_to_shipper(self): self.ensure_one() - if self.delivery_type == "deliverea": + if self.delivery_type == "deliverea" and self.carrier_id.deliverea_return_label: self.carrier_id.deliverea_return_shipping(self) self.carrier_id.deliverea_get_return_label(self) return super().send_to_shipper() diff --git a/delivery_deliverea/tests/test_delivery_deliverea.py b/delivery_deliverea/tests/test_delivery_deliverea.py index 4f2c77e576..37df956231 100644 --- a/delivery_deliverea/tests/test_delivery_deliverea.py +++ b/delivery_deliverea/tests/test_delivery_deliverea.py @@ -144,6 +144,32 @@ def setUp(self): } ) self.picking.action_assign() + self.picking_incoming = self.env["stock.picking"].create( + { + "name": "Test Picking Incoming", + "partner_id": self.partner.id, + "move_ids": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom_qty": 1, + "product_uom": self.product.uom_id.id, + "name": self.product.name, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + }, + ) + ], + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + "picking_type_id": self.env.ref("stock.picking_type_in").id, + "carrier_id": self.carrier.id, + "number_of_packages": 2, + "deliverea_reference": "Sbe2fd53e94869d", + } + ) def test_00_get_services(self): def _call_side_effect(*args, **kwargs): @@ -300,16 +326,16 @@ def test_04_create_return_and_delete(self): return_value=MockResponse(return_value, code=200) ) with mock.patch.object(requests, "post", new=requests_mock_call): - self.carrier.deliverea_return_shipping(self.picking) + self.carrier.deliverea_return_shipping(self.picking_incoming) self.assertEqual( - self.picking.deliverea_reference, + self.picking_incoming.deliverea_reference, "Sbe2fd53e94869d", ) requests_mock_call = mock.MagicMock( return_value=MockResponse("DELETE", code=200) ) with mock.patch.object(requests, "delete", new=requests_mock_call): - self.carrier.deliverea_cancel_shipment(self.picking) + self.carrier.deliverea_cancel_shipment(self.picking_incoming) requests_mock_call.assert_called() def test_05_get_tracking_shipment(self): @@ -363,16 +389,16 @@ def test_06_create_return(self): return_value=MockResponse(return_value, code=200) ) with mock.patch.object(requests, "post", new=requests_mock_call): - self.carrier.deliverea_return_shipping(self.picking) + self.carrier.deliverea_return_shipping(self.picking_incoming) self.assertEqual( - self.picking.deliverea_reference, + self.picking_incoming.deliverea_reference, "Sbe2fd53e94869d", ) requests_mock_call = mock.MagicMock( return_value=MockResponse("DELETE", code=200) ) with mock.patch.object(requests, "delete", new=requests_mock_call): - self.carrier.deliverea_cancel_shipment(self.picking) + self.carrier.deliverea_cancel_shipment(self.picking_incoming) requests_mock_call.assert_called() def test_07_get_exception(self): @@ -430,6 +456,7 @@ def test_11_get_exception(self): def test_12_get_exception(self): return_value = { "delivereaReference": "Sbe2fd53e94869d", + "carrierReference": "test", "carrierCode": "dummy", "serviceCode": "standard", "costCenterCode": "DEFAULT",