diff --git a/delivery_cttexpress/models/delivery_carrier.py b/delivery_cttexpress/models/delivery_carrier.py index 436d839fcf..5981106b65 100644 --- a/delivery_cttexpress/models/delivery_carrier.py +++ b/delivery_cttexpress/models/delivery_carrier.py @@ -1,5 +1,6 @@ # Copyright 2022 Tecnativa - David Vidal # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import time from odoo import _, api, fields, models from odoo.exceptions import UserError @@ -43,6 +44,13 @@ class DeliveryCarrier(models.Model): string="Document format", ) cttexpress_document_offset = fields.Integer(string="Document Offset") + cttexpress_label_delay = fields.Float( + string="Label Fetch Delay (seconds)", + help="The server might not be ready to deliver the label right after the " + "shipping is saved. We need to introduce a little delay. Tipacally 1 s will be " + "enough", + default=1, + ) def _ctt_request(self): """Get CTT Request object @@ -258,6 +266,7 @@ def cttexpress_get_label(self, reference): if not reference: return False ctt_request = self._ctt_request() + time.sleep(self.cttexpress_label_delay) try: error, label = ctt_request.get_documents_multi( reference, diff --git a/delivery_cttexpress/views/delivery_cttexpress_view.xml b/delivery_cttexpress/views/delivery_cttexpress_view.xml index 46cba0aa75..3a413556c5 100644 --- a/delivery_cttexpress/views/delivery_cttexpress_view.xml +++ b/delivery_cttexpress/views/delivery_cttexpress_view.xml @@ -72,6 +72,10 @@ name="cttexpress_document_offset" attrs="{'required': [('delivery_type', '=', 'cttexpress')]}" /> +