FIX Delete triggers must be before delete (reverse order compared to

create)
This commit is contained in:
Laurent Destailleur 2016-02-06 12:37:48 +01:00
parent 2e1011ca0c
commit 8f8c63e9c8

View File

@ -291,12 +291,12 @@ class Paiement extends CommonObject
/** /**
* Supprime un paiement ainsi que les lignes qu'il a genere dans comptes * Delete a payment and generated links into account
* Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * - Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse
* Si le paiement porte sur au moins une facture a "payee", on refuse * - Si le paiement porte sur au moins une facture a "payee", on refuse
* *
* @param int $notrigger No trigger * @param int $notrigger No trigger
* @return int <0 si ko, >0 si ok * @return int <0 si ko, >0 si ok
*/ */
function delete($notrigger=0) function delete($notrigger=0)
{ {
@ -326,21 +326,43 @@ class Paiement extends CommonObject
return -2; return -2;
} }
$accline = new AccountLine($this->db);
// Delete bank urls. If payment is on a conciliated line, return error. // Delete bank urls. If payment is on a conciliated line, return error.
if ($bank_line_id) if ($bank_line_id > 0)
{ {
$accline = new AccountLine($this->db);
$result=$accline->fetch($bank_line_id); $result=$accline->fetch($bank_line_id);
if ($result == 0) $accline->rowid=$bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url if ($result == 0) $accline->rowid=$bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
$result=$accline->delete_urls($user); // Delete bank account url lines linked to payment
$result=$accline->delete_urls($user);
if ($result < 0) if ($result < 0)
{ {
$this->error=$accline->error; $this->error=$accline->error;
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
} }
// Delete bank account lines linked to payment
$result=$accline->delete($user);
if ($result < 0)
{
$this->error=$accline->error;
$this->db->rollback();
return -4;
}
}
if (! $notrigger)
{
// Call triggers
$result=$this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
if ($result < 0)
{
$this->db->rollback();
return -1;
}
// End call triggers
} }
// Delete payment (into paiement_facture and paiement) // Delete payment (into paiement_facture and paiement)
@ -361,30 +383,6 @@ class Paiement extends CommonObject
return -3; return -3;
} }
// Supprimer l'ecriture bancaire si paiement lie a ecriture
if ($bank_line_id)
{
$result=$accline->delete($user);
if ($result < 0)
{
$this->error=$accline->error;
$this->db->rollback();
return -4;
}
}
if (! $notrigger)
{
// Appel des triggers
$result=$this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
if ($result < 0)
{
$this->db->rollback();
return -1;
}
// Fin appel triggers
}
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }