diff --git a/delivery_cttexpress/models/delivery_carrier.py b/delivery_cttexpress/models/delivery_carrier.py index bf1d0eaf1f..47a896d70f 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 @@ -38,6 +39,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 @@ -253,6 +261,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 4748a4a3d5..40fda6a633 100644 --- a/delivery_cttexpress/views/delivery_cttexpress_view.xml +++ b/delivery_cttexpress/views/delivery_cttexpress_view.xml @@ -72,6 +72,7 @@ name="cttexpress_document_offset" attrs="{'required': [('delivery_type', '=', 'cttexpress')]}" /> +