From 27d82d0e8e723ba26784cbb3da9c2d7227af153e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 Oct 2018 14:41:00 +0100 Subject: [PATCH] FIX Delete of draft invoice --- htdocs/compta/facture/card.php | 4 ++-- htdocs/core/class/commoninvoice.class.php | 5 +++-- htdocs/fourn/facture/card.php | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 8c80c5caa9c..7589801787c 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -190,7 +190,7 @@ if (empty($reshook)) $qualified_for_stock_change = $object->hasProductsOrServices(1); } - if ($object->is_erasable()) + if ($object->is_erasable() > 0) { $result = $object->delete($user, 0, $idwarehouse); if ($result > 0) { @@ -4812,7 +4812,7 @@ else if ($id > 0 || ! empty($ref)) // Delete $isErasable = $object->is_erasable(); - if ($user->rights->facture->supprimer || $isErasable == 1) // isErasable = 1 means draft (draft can always be deleted with no need of permissions) + if ($user->rights->facture->supprimer || $isErasable == 1) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions) { //var_dump($isErasable); if ($isErasable == -4) { diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 9bab103d2e4..3aa8eb4e1ab 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -328,12 +328,13 @@ abstract class CommonInvoice extends CommonObject /** * Return if an invoice can be deleted * Rule is: - * If invoice is draft and has a temporary ref -> yes + * If invoice is draft and has a temporary ref -> yes (1) * If hidden option INVOICE_CAN_NEVER_BE_REMOVED is on -> no (0) * If invoice is dispatched in bookkeeping -> no (-1) * If invoice has a definitive ref, is not last and INVOICE_CAN_ALWAYS_BE_REMOVED off -> no (-2) * If invoice not last in a cycle -> no (-3) * If there is payment -> no (-4) + * Otherwise -> yes (2) * * @return int <=0 if no, >0 if yes */ @@ -381,7 +382,7 @@ abstract class CommonInvoice extends CommonObject // Test if there is at least one payment. If yes, refuse to delete. if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0) return -4; - return 1; + return 2; } /** diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 36785a154dc..75e0f15220d 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -3117,9 +3117,9 @@ else } // Delete - if ($action != 'confirm_edit' && $user->rights->fournisseur->facture->supprimer) + $isErasable=$object->is_erasable(); + if ($action != 'confirm_edit' && ($user->rights->fournisseur->facture->supprimer || $isErasable == 1)) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions) { - $isErasable=$object->is_erasable(); //var_dump($isErasable); if ($isErasable == -4) { print '
' . $langs->trans('Delete') . '
';