diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 331e211e5ac..83251c93499 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -2070,6 +2070,18 @@ class CommandeFournisseur extends CommonOrder
// End call triggers
}
+ // Test we can delete
+ $this->fetchObjectLinked(null, 'order_supplier');
+ if (!empty($this->linkedObjects)) {
+ foreach ($this->linkedObjects['reception'] as $element) {
+ if ($element->statut >= 0) {
+ $this->errors[] = $langs->trans('ReceptionExist');
+ $error++;
+ break;
+ }
+ }
+ }
+
$main = MAIN_DB_PREFIX.'commande_fournisseurdet';
$ef = $main."_extrafields";
$sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".$this->id.")";
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index bb0ad661c82..9c201497566 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -2325,7 +2325,7 @@ if ($action == 'create') {
print dol_get_fiche_end();
/**
- * Boutons actions
+ * Buttons for actions
*/
if ($user->socid == 0 && $action != 'editline' && $action != 'delete') {
@@ -2433,11 +2433,19 @@ if ($action == 'create') {
}
// Ship
-
+ $hasreception = 0;
if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) {
$labelofbutton = $langs->trans('ReceiveProducts');
if ($conf->reception->enabled) {
$labelofbutton = $langs->trans("CreateReception");
+ if (!empty($object->linkedObjects)) {
+ foreach ($object->linkedObjects['reception'] as $element) {
+ if ($element->statut >= 0) {
+ $hasreception = 1;
+ break;
+ }
+ }
+ }
}
if (in_array($object->statut, array(3, 4, 5))) {
@@ -2508,7 +2516,11 @@ if ($action == 'create') {
// Delete
if (!empty($usercandelete) || ($object->statut == CommandeFournisseur::STATUS_DRAFT && !empty($usercancreate))) {
- print 'id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'';
+ if ($hasreception) {
+ print ''.$langs->trans("Delete").'';
+ } else {
+ print 'id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'';
+ }
}
}
diff --git a/htdocs/langs/en_US/receptions.lang b/htdocs/langs/en_US/receptions.lang
index 760ff884fa0..338602e722e 100644
--- a/htdocs/langs/en_US/receptions.lang
+++ b/htdocs/langs/en_US/receptions.lang
@@ -44,4 +44,4 @@ ValidateOrderFirstBeforeReception=You must first validate the order before being
ReceptionsNumberingModules=Numbering module for receptions
ReceptionsReceiptModel=Document templates for receptions
NoMorePredefinedProductToDispatch=No more predefined products to dispatch
-
+ReceptionExist=A reception exists