FIX re-open supplier order should not be allowed when there is a reception.

This commit is contained in:
Francis Appels 2023-01-13 09:01:31 +01:00
parent 22720b652c
commit c52fab09e6
2 changed files with 28 additions and 19 deletions

View File

@ -2440,6 +2440,19 @@ if ($action == 'create') {
if (empty($reshook)) { if (empty($reshook)) {
$object->fetchObjectLinked(); // Links are used to show or not button, so we load them now. $object->fetchObjectLinked(); // Links are used to show or not button, so we load them now.
// check if reception
$hasreception = 0;
if ($conf->reception->enabled) {
if (!empty($object->linkedObjects['reception'])) {
foreach ($object->linkedObjects['reception'] as $element) {
if ($element->statut >= 0) {
$hasreception = 1;
break;
}
}
}
}
// Validate // Validate
if ($object->statut == 0 && $num > 0) { if ($object->statut == 0 && $num > 0) {
if ($usercanvalidate) { if ($usercanvalidate) {
@ -2515,6 +2528,9 @@ if ($action == 'create') {
// Reopen // Reopen
if (in_array($object->statut, array(CommandeFournisseur::STATUS_ACCEPTED))) { if (in_array($object->statut, array(CommandeFournisseur::STATUS_ACCEPTED))) {
$buttonshown = 0; $buttonshown = 0;
if ($hasreception) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ReceptionExist").'">'.$langs->trans("Disapprove").'</a>';
} else {
if (!$buttonshown && $usercanapprove) { if (!$buttonshown && $usercanapprove) {
if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY)
|| (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) { || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) {
@ -2529,6 +2545,7 @@ if ($action == 'create') {
} }
} }
} }
}
if (in_array($object->statut, array(3, 4, 5, 6, 7, 9))) { if (in_array($object->statut, array(3, 4, 5, 6, 7, 9))) {
if ($usercanorder) { if ($usercanorder) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>';
@ -2536,19 +2553,10 @@ if ($action == 'create') {
} }
// Ship // Ship
$hasreception = 0;
if (isModEnabled('stock') && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) { if (isModEnabled('stock') && (!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'); $labelofbutton = $langs->trans('ReceiveProducts');
if ($conf->reception->enabled) { if ($conf->reception->enabled) {
$labelofbutton = $langs->trans("CreateReception"); $labelofbutton = $langs->trans("CreateReception");
if (!empty($object->linkedObjects['reception'])) {
foreach ($object->linkedObjects['reception'] as $element) {
if ($element->statut >= 0) {
$hasreception = 1;
break;
}
}
}
} }
if (in_array($object->statut, array(3, 4, 5))) { if (in_array($object->statut, array(3, 4, 5))) {

View File

@ -204,3 +204,4 @@ StatusSupplierOrderApproved=Approved
StatusSupplierOrderRefused=Refused StatusSupplierOrderRefused=Refused
StatusSupplierOrderReceivedPartially=Partially received StatusSupplierOrderReceivedPartially=Partially received
StatusSupplierOrderReceivedAll=All products received StatusSupplierOrderReceivedAll=All products received
NeedAtLeastOneInvoice = There has to be at least one Invoice