diff --git a/htdocs/delivery/card.php b/htdocs/delivery/card.php index 00975946f6b..8082c654a55 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -256,9 +256,10 @@ llxHeader('', $title, 'Livraison'); $form = new Form($db); $formfile = new FormFile($db); -if ($action == 'create') { // Create. Seems to no be used -} else // View -{ +if ($action == 'create') { + // Create. Seems to no be used +} else { + // View if ($object->id > 0) { // Origin of a 'livraison' (delivery receipt) is ALWAYS 'expedition' (shipment). // However, origin of shipment in future may differs (commande, proposal, ...) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index d16885faa0f..29336772269 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -405,11 +405,17 @@ if (empty($reshook)) { } } elseif ($action == 'create_delivery' && $conf->delivery_note->enabled && $user->rights->expedition->delivery->creer) { // Build a receiving receipt + $db->begin(); + $result = $object->create_delivery($user); if ($result > 0) { + $db->commit(); + header("Location: ".DOL_URL_ROOT.'/delivery/card.php?action=create_delivery&id='.$result); exit; } else { + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'confirm_valid' && $confirm == 'yes' && diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index 4add688b880..86b3da418a0 100644 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -194,11 +194,13 @@ delete from llx_delivery where rowid not in (select fk_target from llx_elemen -- Fix delete element_element orphelins (right side) delete from llx_element_element where targettype='shipping' and fk_target not in (select rowid from llx_expedition); +delete from llx_element_element where targettype='delivery' and fk_target not in (select rowid from llx_delivery); delete from llx_element_element where targettype='propal' and fk_target not in (select rowid from llx_propal); delete from llx_element_element where targettype='facture' and fk_target not in (select rowid from llx_facture); delete from llx_element_element where targettype='commande' and fk_target not in (select rowid from llx_commande); -- Fix delete element_element orphelins (left side) delete from llx_element_element where sourcetype='shipping' and fk_source not in (select rowid from llx_expedition); +delete from llx_element_element where sourcetype='delivery' and fk_source not in (select rowid from llx_delivery); delete from llx_element_element where sourcetype='propal' and fk_source not in (select rowid from llx_propal); delete from llx_element_element where sourcetype='facture' and fk_source not in (select rowid from llx_facture); delete from llx_element_element where sourcetype='commande' and fk_source not in (select rowid from llx_commande);