Solved !!!

I applied your suggested modifications and your sw runs correctly.

I tried both with an admin order and with an order produced by the front end.

Many thanks for your fundamental help.