From 97c5b132584ee6672ef09f48cb5638cf90ac17ee Mon Sep 17 00:00:00 2001 From: David Date: Mon, 11 Dec 2023 18:25:07 +0100 Subject: [PATCH] [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 --- delivery_cttexpress/models/delivery_carrier.py | 9 +++++++++ delivery_cttexpress/views/delivery_cttexpress_view.xml | 1 + 2 files changed, 10 insertions(+) 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')]}" /> +