Faircot cron
This commit is contained in:
@@ -225,6 +225,12 @@ class AutomationCron(ModelSQL, ModelView):
|
||||
return ''
|
||||
return value
|
||||
|
||||
def normalize_booking_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
|
||||
@@ -271,33 +277,45 @@ class AutomationCron(ModelSQL, ModelView):
|
||||
etd_date, bl_date, controller,
|
||||
comments, fintrade_booking_key
|
||||
) = row
|
||||
si_reference = normalize_booking_number(si_number)
|
||||
|
||||
logger.info(f"Traitement shipment {i}/{len(rows2)} : SI {si_number}")
|
||||
logger.info(
|
||||
"Traitement shipment %s/%s : SI %s reference=%s",
|
||||
i, len(rows2), si_number, si_reference)
|
||||
|
||||
try:
|
||||
with Transaction().new_transaction() as trans_shipment:
|
||||
logger.info(f"Debut transaction pour SI {si_number}")
|
||||
logger.info(
|
||||
"Debut transaction pour SI %s reference=%s",
|
||||
si_number, si_reference)
|
||||
|
||||
existing_shipment = ShipmentIn.search([
|
||||
('reference', '=', si_number)
|
||||
], limit=1)
|
||||
existing_shipments = ShipmentIn.search([
|
||||
('reference', '=', si_reference)
|
||||
])
|
||||
|
||||
if existing_shipment:
|
||||
shipment = existing_shipment[0]
|
||||
sync_shipment_from_booking(
|
||||
shipment, bl_number, bl_date, etd_date,
|
||||
controller)
|
||||
if existing_shipments:
|
||||
if len(existing_shipments) > 1:
|
||||
logger.info(
|
||||
"FREIGHT_BOOKING_DUPLICATE_SHIPMENT_REFERENCE "
|
||||
"reference=%s shipment_ids=%s",
|
||||
si_reference,
|
||||
[shipment.id for shipment in existing_shipments])
|
||||
for existing in existing_shipments:
|
||||
sync_shipment_from_booking(
|
||||
existing, bl_number, bl_date, etd_date,
|
||||
controller)
|
||||
shipment = existing_shipments[0]
|
||||
if shipment.incoming_moves:
|
||||
logger.info(
|
||||
"Shipment %s existe deja avec lots, "
|
||||
"booking data synchronized",
|
||||
si_number)
|
||||
si_reference)
|
||||
trans_shipment.commit()
|
||||
continue
|
||||
|
||||
logger.info(
|
||||
"Shipment %s existe deja sans lots, verification freight_booking_lots",
|
||||
si_number)
|
||||
si_reference)
|
||||
with Transaction().set_context(
|
||||
_purchase_trade_skip_physical_lot_tolerance_warning=True):
|
||||
inv_date, inv_nb = (
|
||||
@@ -313,11 +331,11 @@ class AutomationCron(ModelSQL, ModelView):
|
||||
ShipmentIn.save([shipment])
|
||||
logger.info(
|
||||
"Shipment %s mis a jour avec %s incoming move(s)",
|
||||
si_number, len(shipment.incoming_moves))
|
||||
si_reference, len(shipment.incoming_moves))
|
||||
else:
|
||||
logger.info(
|
||||
"Shipment %s existe sans lots et aucun lot disponible pour l'instant",
|
||||
si_number)
|
||||
si_reference)
|
||||
trans_shipment.commit()
|
||||
continue
|
||||
|
||||
@@ -377,7 +395,7 @@ class AutomationCron(ModelSQL, ModelView):
|
||||
raise ValueError(error_msg)
|
||||
|
||||
shipment = ShipmentIn()
|
||||
shipment.reference = si_number
|
||||
shipment.reference = si_reference
|
||||
shipment.from_location = loc_from
|
||||
shipment.to_location = loc_to
|
||||
shipment.carrier = None # carrier
|
||||
|
||||
Reference in New Issue
Block a user