PrestaShopCorp / chronopost

5 stars 13 forks source link

Duplicate payment with Lengow module #32

Open Klemart3D opened 8 years ago

Klemart3D commented 8 years ago

Hi, From recently, I found incompatibility between Chronopost and Lengow modules. Lengow imports orders from marketplaces (like Amazon, Fnac…) to Prestashop. With other carriers there is no problem, but with Chronopost when I'm generating waybill (or "LT"), status auto-change to "Shipped" (or "Expédié"), generating invoice and a duplicated payment is created. Sum up :

Direct website order + Chronopost = OK Lengow import order + Chronopost = ERROR (duplicate payment, cf picture) Lengow import order + Other carrier = OK

Fortunately, Lengow module is free and findable on addons Prestashop store, but I'm not enough familiarized with Prestashop classes and methods to find where and what's going bad. Any help is welcome ;)

duplicate-payment-error

francoisfeugeas commented 8 years ago

Hi,

What is the status of the orders created by Lengow ? The Chronopost module does not create payment entries, so it's probably an issue with either the Lengow module or the way your order status are created.

Klemart3D commented 8 years ago

Hi & thanks @francoisfeugeas, Default order status when order is coming from Lengow is "Payment accepted". But I disabled auto-creation of invoice from this status. Status must change to "Shipped" (manually or automatically with Chronopost) to view/download invoice. If it's not Chronopost module, may be it's when module calling a Prestashop's method to change order status and adding Invoice reference to payment ?

francoisfeugeas commented 8 years ago

I can confirm then that it's not related to our module. It is indeed related to the status change, which for some reason creates a second payment entry.

@Quetzacoalt91 is this a Prestashop bug ?

francoisfeugeas commented 8 years ago

@chronoweb

Klemart3D commented 8 years ago

Lengow can't do nothing from their side. It's seems I must go back to generate invoices from "Payment accepted" status. I hope remains an another solution ? Here is their answer that explains process, if can helps (sorry for the french) :

Quand on remonte une commande avec lengow on va créer un paiement (et prestashop génère la facture si c'est configuré dans prestashop pour générer la facture dans l'écran => Commande > Statut). Le probleme c'est qu'une fois que chronopost met le numéro de tracking il passe dans le fichier /classes/order/OrderHistory.php A cause de cette ligne de code dans le fichier chronopost.php : $history = new OrderHistory(); $history->id_order = (int)($o->id); $history->id_order_state = _PS_OSSHIPPING; $history->changeIdOrderState(_PS_OSSHIPPING, $id_order); $history->save();

Dans ce fichier après la ligne // set orders as paid Il vérifie si il reste un montant à payer : avec $rest_paid = $invoice->getRestPaid(); Mais comme la facture n'existe pas dans la table : ps_order_invoice Il pense que le montant payé est de 0, alors il va créer un nouveau paiement : $payment = new OrderPayment(); $payment->save();

Si le transporteur n'est pas chronopost il ne passe pas dans OrderHistory.php donc il ne vas pas créer de doublon de paiement. Malheureusement, on ne va pas pouvoir gérer ce cas de figure dans notre module, il faut vraiment que vous acceptiez de généré un numéro de facture sinon ca ne peux pas marcher.