This is from an external module and I don't know the tables structure.
But this is wrong:
K.key_value
What's "K"?
INNER JOIN ps_order_detail OD on O.id_order = OD.id_order INNER JOIN ps_keymanager OD on O.id_order = OD.id_order
same alias "OD" for two JOINs