From 816d1fcaecab7fdaef8419a722c2c29f6d29c34f Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Mon, 20 Jul 2026 08:43:43 +0200 Subject: [PATCH] Faircot cron --- modules/automation/cron.py | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/modules/automation/cron.py b/modules/automation/cron.py index fd26358..06a4cca 100644 --- a/modules/automation/cron.py +++ b/modules/automation/cron.py @@ -219,6 +219,48 @@ class AutomationCron(ModelSQL, ModelView): rows2 = cursor2.fetchall() + def normalize_bl_number(value): + value = str(value or '').strip() + if value.lower() in {'none', 'null'}: + return '' + return value + + def sync_shipment_from_booking(shipment, bl_number, bl_date, etd_date, + controller): + changed = False + booking_bl_number = normalize_bl_number(bl_number) + shipment_bl_number = normalize_bl_number(shipment.bl_number) + if booking_bl_number and booking_bl_number != shipment_bl_number: + logger.info( + "FREIGHT_BOOKING_SYNC_BL shipment=%s reference=%s " + "old_bl=%s new_bl=%s", + shipment.id, shipment.reference, + shipment.bl_number, booking_bl_number) + shipment.bl_number = booking_bl_number + changed = True + if bl_date and shipment.bl_date != bl_date: + logger.info( + "FREIGHT_BOOKING_SYNC_BL_DATE shipment=%s reference=%s " + "old_bl_date=%s new_bl_date=%s", + shipment.id, shipment.reference, + shipment.bl_date, bl_date) + shipment.bl_date = bl_date + changed = True + if etd_date and shipment.etd != etd_date: + logger.info( + "FREIGHT_BOOKING_SYNC_ETD shipment=%s reference=%s " + "old_etd=%s new_etd=%s", + shipment.id, shipment.reference, + shipment.etd, etd_date) + shipment.etd = etd_date + changed = True + if controller and shipment.controller_target != controller: + shipment.controller_target = controller + changed = True + if changed: + ShipmentIn.save([shipment]) + return changed + for i, row in enumerate(rows2, 1): ( si_number, si_date, si_quantity, si_unit, @@ -242,9 +284,13 @@ class AutomationCron(ModelSQL, ModelView): if existing_shipment: shipment = existing_shipment[0] + sync_shipment_from_booking( + shipment, bl_number, bl_date, etd_date, + controller) if shipment.incoming_moves: logger.info( - "Shipment %s existe deja avec lots, ignore", + "Shipment %s existe deja avec lots, " + "booking data synchronized", si_number) trans_shipment.commit() continue