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