Skip to content

Commit 59cdf0b

Browse files
committed
[IMP] delivery_cttexpress: configurable label delay
When we recod a shipping in the CTT Express backend the label API could not be ready in the moment to retrieve the labels. As CTT Express stated, a little delay would add the needed time for the API to be ready. TT46443
1 parent 1408b3e commit 59cdf0b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

delivery_cttexpress/models/delivery_carrier.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2022 Tecnativa - David Vidal
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
import time
34
from odoo import _, api, fields, models
45
from odoo.exceptions import UserError
56

@@ -38,6 +39,13 @@ class DeliveryCarrier(models.Model):
3839
string="Document format",
3940
)
4041
cttexpress_document_offset = fields.Integer(string="Document Offset")
42+
cttexpress_label_delay = fields.Float(
43+
string="Label Fetch Delay (seconds)",
44+
help="The server might not be ready to deliver the label right after the "
45+
"shipping is saved. We need to introduce a little delay. Tipacally 1 s will be "
46+
"enough",
47+
default=1,
48+
)
4149

4250
def _ctt_request(self):
4351
"""Get CTT Request object
@@ -253,6 +261,7 @@ def cttexpress_get_label(self, reference):
253261
if not reference:
254262
return False
255263
ctt_request = self._ctt_request()
264+
time.sleep(self.cttexpress_label_delay)
256265
try:
257266
error, label = ctt_request.get_documents_multi(
258267
reference,

delivery_cttexpress/views/delivery_cttexpress_view.xml

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
name="cttexpress_document_offset"
7373
attrs="{'required': [('delivery_type', '=', 'cttexpress')]}"
7474
/>
75+
<field name="cttexpress_label_delay" />
7576
</group>
7677
</group>
7778
</page>

0 commit comments

Comments
 (0)