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][FIX]delivery_deliverea:Fixes error when recording shipments #891

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
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
19 changes: 10 additions & 9 deletions delivery_deliverea/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion delivery_deliverea/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ def deliverea_get_label(self):
return
return self.carrier_id.deliverea_get_label(self)

def is_deliverea_pickup(self):
self.ensure_one()
return (
self.carrier_id.delivery_type == "deliverea"
and self.carrier_id.deliverea_return_label
)

def send_to_shipper(self):
self.ensure_one()
if self.delivery_type == "deliverea":
if self.is_deliverea_pickup():
self.carrier_id.deliverea_return_shipping(self)
self.carrier_id.deliverea_get_return_label(self)
return super().send_to_shipper()
Expand Down
47 changes: 37 additions & 10 deletions delivery_deliverea/tests/test_delivery_deliverea.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -437,23 +463,24 @@ def test_12_get_exception(self):
requests_mock_call = mock.MagicMock(
return_value=MockResponse(return_value, code=200)
)

with self.assertRaises(UserError):
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)

def test_13_get_return_label(self):
self.picking.deliverea_reference = "Sbe2fd53e94869d"
self.picking_incoming.deliverea_reference = "Sbe2fd53e94869d"
return_value = {"type": "zpl", "content": "TEST"}
requests_mock_call = mock.MagicMock(
return_value=MockResponse(return_value, code=200)
)
with mock.patch.object(requests, "get", new=requests_mock_call):
self.carrier.deliverea_get_return_label(self.picking)
self.carrier.deliverea_get_return_label(self.picking_incoming)

attachment = self.env["ir.attachment"].search(
[
("res_model", "=", "stock.picking"),
("res_id", "=", self.picking.id),
("res_id", "=", self.picking_incoming.id),
]
)
self.assertTrue(attachment)
Loading