Merge pull request #17631 from fappels/14_reception

Fix: Add test to delete supplier order if reception exist
This commit is contained in:
Laurent Destailleur 2021-05-17 13:22:34 +02:00 committed by GitHub
commit 0121150e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View File

@ -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.")";

View File

@ -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 '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a>';
if ($hasreception) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ReceptionExist").'">'.$langs->trans("Delete").'</a>';
} else {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a>';
}
}
}

View File

@ -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