Skip to content

Commit d2d58bc

Browse files
committed
[MIG] delivery_ups_oca: Migration to 15.0
1 parent 3fc130b commit d2d58bc

File tree

9 files changed

+69
-64
lines changed

9 files changed

+69
-64
lines changed

delivery_ups_oca/README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Configuration
4848

4949
To configure this module, you need to:
5050

51-
#. Add a carrier account with delivery type ``ups`` and fill in your credentials (UPS
52-
Client and UPS Client Secret)
51+
#. Add a carrier account with delivery type ``UPS`` and fill in your credentials (
52+
Client ID and Client Secret)
5353
#. Configure in Odoo all required fields of the UPS tab with your account data
5454
https://wwwapps.ups.com/ppc/ppc.html (Shipper number, Default Packaging, Package
5555
Dimension Code, Package Weight Code and File Format).

delivery_ups_oca/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Delivery UPS OCA",
66
"summary": "Integrate UPS webservice",
7-
"version": "14.0.1.0.1",
7+
"version": "15.0.1.0.1",
88
"development_status": "Beta",
99
"category": "Delivery",
1010
"website": "https://github.com/OCA/delivery-carrier",

delivery_ups_oca/i18n/delivery_ups_oca.pot

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@ msgstr ""
375375

376376
#. module: delivery_ups_oca
377377
#: model:ir.model.fields,field_description:delivery_ups_oca.field_delivery_carrier__ups_client_id
378-
msgid "Ups Client"
378+
msgid "Client ID"
379379
msgstr ""
380380

381381
#. module: delivery_ups_oca
382382
#: model:ir.model.fields,field_description:delivery_ups_oca.field_delivery_carrier__ups_client_secret
383-
msgid "Ups Client Secret"
383+
msgid "Client Secret"
384384
msgstr ""
385385

386386
#. module: delivery_ups_oca

delivery_ups_oca/i18n/it.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ msgstr ""
376376

377377
#. module: delivery_ups_oca
378378
#: model:ir.model.fields,field_description:delivery_ups_oca.field_delivery_carrier__ups_client_id
379-
msgid "Ups Client"
379+
msgid "Client ID"
380380
msgstr ""
381381

382382
#. module: delivery_ups_oca
383383
#: model:ir.model.fields,field_description:delivery_ups_oca.field_delivery_carrier__ups_client_secret
384-
msgid "Ups Client Secret"
384+
msgid "Client Secret"
385385
msgstr ""
386386

387387
#. module: delivery_ups_oca

delivery_ups_oca/models/product_packaging.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
class ProductPackaging(models.Model):
77
_inherit = "product.packaging"
88

9-
package_carrier_type = fields.Selection(selection_add=[("ups", "UPS")])
9+
package_carrier_type = fields.Selection(
10+
selection=[("none", "None"), ("ups", "UPS")],
11+
default="none",
12+
ondelete={"ups": "set default"},
13+
)

delivery_ups_oca/models/ups_request.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,21 @@ def tracking_state_update(self, picking):
396396
else:
397397
for warning in shipment.get("warnings"):
398398
states_list.append(
399-
_("{} - Warning: {}").format(
400-
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
401-
warning.get("message"),
402-
)
399+
_("%(datetime)s - Warning: %(message)s")
400+
% {
401+
"datetime": datetime.datetime.now().strftime(
402+
"%Y-%m-%d %H:%M:%S"
403+
),
404+
"message": warning.get("message"),
405+
}
403406
)
404407

405408
except Exception:
406409
states_list.append(
407-
_("{} - Error retrieving the tracking information.").format(
408-
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
409-
)
410+
_("%(datetime)s - Error retrieving the tracking information.")
411+
% {
412+
"datetime": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
413+
}
410414
)
411415
return {
412416
"delivery_state": delivery_state,

delivery_ups_oca/readme/CONFIGURE.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
To configure this module, you need to:
22

3-
#. Add a carrier account with delivery type ``ups`` and fill in your credentials (UPS
4-
Client and UPS Client Secret)
3+
#. Add a Shipping Method with Provider ``UPS`` and fill in your UPS credentials
4+
(Client ID and Client Secret)
55
#. Configure in Odoo all required fields of the UPS tab with your account data
66
https://wwwapps.ups.com/ppc/ppc.html (Shipper number, Default Packaging, Package
77
Dimension Code, Package Weight Code and File Format).

delivery_ups_oca/static/description/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ <h1 class="title">Delivery UPS OCA</h1>
395395
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
396396
<p>To configure this module, you need to:</p>
397397
<ol class="arabic simple">
398-
<li>Add a carrier account with delivery type <tt class="docutils literal">ups</tt> and fill in your credentials (UPS
399-
Client and UPS Client Secret)</li>
398+
<li>Add a Shipping Method with Provider <tt class="docutils literal">UPS</tt> and fill in your UPS credentials
399+
(Client ID and Client Secret)</li>
400400
<li>Configure in Odoo all required fields of the UPS tab with your account data
401401
<a class="reference external" href="https://wwwapps.ups.com/ppc/ppc.html">https://wwwapps.ups.com/ppc/ppc.html</a> (Shipper number, Default Packaging, Package
402402
Dimension Code, Package Weight Code and File Format).</li>

delivery_ups_oca/tests/test_delivery_ups.py

+42-45
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import base64
77
from unittest import mock
88

9-
from odoo.modules import get_module_resource
109
from odoo.tests import Form, common
1110

1211
_module_ns = "odoo.addons.delivery_ups_oca"
1312
_provider_class = _module_ns + ".models.ups_request.UpsRequest"
1413

1514

16-
class TestDeliveryUpsBase(common.SavepointCase):
15+
class TestDeliveryUpsBase(common.TransactionCase):
1716
@classmethod
1817
def setUpClass(cls):
1918
super().setUpClass()
@@ -70,7 +69,8 @@ def _create_sale_order(self):
7069
sale = order_form.save()
7170
delivery_wizard = Form(
7271
self.env["choose.delivery.carrier"].with_context(
73-
{"default_order_id": sale.id, "default_carrier_id": self.carrier.id}
72+
default_order_id=sale.id,
73+
default_carrier_id=self.carrier.id,
7474
)
7575
).save()
7676
delivery_wizard.button_confirm()
@@ -123,47 +123,44 @@ def test_order_ups_rate_shipment_currency_extra(self):
123123
def test_delivery_carrier_ups_integration(self):
124124
self.picking.action_confirm()
125125
self.picking.action_assign()
126-
dummy_pdf_path = get_module_resource(
127-
"delivery_carrier_label_batch", "tests", "dummy.pdf"
128-
)
129-
with open(dummy_pdf_path, "rb") as dummy_pdf:
130-
label = dummy_pdf.read()
131-
with mock.patch(
132-
_provider_class + "._send_shipping",
133-
return_value={
134-
"price": {"CurrencyCode": "USD", "MonetaryValue": "0.0"},
135-
"ShipmentIdentificationNumber": "123456",
136-
"labels": [
137-
{
138-
"tracking_ref": "123456",
139-
"format_code": "png",
140-
"datas": base64.b64encode(label),
141-
}
142-
],
143-
},
144-
):
145-
self.picking.send_to_shipper()
146-
self.assertEqual(self.picking.message_attachment_count, 1)
147-
self.assertTrue(self.picking.carrier_tracking_ref)
148-
self.assertFalse(self.picking.tracking_state_history)
149-
self.assertEqual(
150-
self.picking.delivery_state, "shipping_recorded_in_carrier"
151-
)
152-
if self.picking.carrier_id.ups_tracking_state_update_sync:
153-
with mock.patch(
154-
_provider_class + ".tracking_state_update",
155-
return_value={
156-
"delivery_state": "in_transit",
157-
"tracking_state_history": "history",
158-
},
159-
):
160-
self.picking.tracking_state_update()
161-
self.assertEqual(self.picking.delivery_state, "in_transit")
162-
self.assertTrue(self.picking.tracking_state_history)
126+
# Create a simple PDF-like bytes object for testing
127+
label = b"%PDF-1.4\n%EOF"
128+
with mock.patch(
129+
_provider_class + "._send_shipping",
130+
return_value={
131+
"price": {"CurrencyCode": "USD", "MonetaryValue": "0.0"},
132+
"ShipmentIdentificationNumber": "123456",
133+
"labels": [
134+
{
135+
"tracking_ref": "123456",
136+
"format_code": "png",
137+
"datas": base64.b64encode(label),
138+
}
139+
],
140+
},
141+
):
142+
self.picking.send_to_shipper()
143+
self.assertEqual(self.picking.message_attachment_count, 1)
144+
self.assertTrue(self.picking.carrier_tracking_ref)
145+
self.assertFalse(self.picking.tracking_state_history)
146+
self.assertEqual(
147+
self.picking.delivery_state, "shipping_recorded_in_carrier"
148+
)
149+
if self.picking.carrier_id.ups_tracking_state_update_sync:
163150
with mock.patch(
164-
_provider_class + ".cancel_shipment",
165-
return_value=True,
151+
_provider_class + ".tracking_state_update",
152+
return_value={
153+
"delivery_state": "in_transit",
154+
"tracking_state_history": "history",
155+
},
166156
):
167-
self.picking.cancel_shipment()
168-
self.assertFalse(self.picking.carrier_tracking_ref)
169-
self.assertEqual(self.picking.delivery_state, "canceled_shipment")
157+
self.picking.tracking_state_update()
158+
self.assertEqual(self.picking.delivery_state, "in_transit")
159+
self.assertTrue(self.picking.tracking_state_history)
160+
with mock.patch(
161+
_provider_class + ".cancel_shipment",
162+
return_value=True,
163+
):
164+
self.picking.cancel_shipment()
165+
self.assertFalse(self.picking.carrier_tracking_ref)
166+
self.assertEqual(self.picking.delivery_state, "canceled_shipment")

0 commit comments

Comments
 (0)