diff --git a/htdocs/admin/confexped.php b/htdocs/admin/confexped.php
index f8d13421b2406646d387ab706a1d1322dc13c2f5..059915df3d8152ea319757419e939c99365d3f6e 100644
--- a/htdocs/admin/confexped.php
+++ b/htdocs/admin/confexped.php
@@ -2,7 +2,8 @@
 /* Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
- * Copyright (C) 2011-2015 Juanjo Menent		<jmenent@2byte.es>
+ * Copyright (C) 2011-2015 Juanjo Menent		<jmenent@2byte.es>ù
+ * Copyright (C) 2015			 Claudio Aschieri	<c.aschieri@19.coop>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +27,7 @@
 
 require '../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
 
 $langs->load("admin");
 $langs->load("sendings");
@@ -76,29 +78,9 @@ llxHeader("","");
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
 print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
 print '<br>';
+$head = expedition_admin_prepare_head();
 
-$h = 0;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
-$head[$h][1] = $langs->trans("Setup");
-$hselected=$h;
-$h++;
-
-if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
-	$head[$h][1] = $langs->trans("Shipment");
-	$h++;
-}
-
-if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
-{
-	$head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
-	$head[$h][1] = $langs->trans("Receivings");
-	$h++;
-}
-
-dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
+dol_fiche_head($head, 'general', $langs->trans("ModuleSetup"), 0, 'sending');
 
 /*
  * Formulaire parametres divers
diff --git a/htdocs/admin/expedition.php b/htdocs/admin/expedition.php
index 555badf11d82dbe279b22c257db19203a4680504..42741b49c7ae7aad54b302f8b05a541b4bf0b19c 100644
--- a/htdocs/admin/expedition.php
+++ b/htdocs/admin/expedition.php
@@ -30,6 +30,7 @@
 
 require '../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
 
 $langs->load("admin");
@@ -219,30 +220,9 @@ llxHeader("","");
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
 print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
 print '<br>';
+$head = expedition_admin_prepare_head();
 
-
-//if ($mesg) print $mesg.'<br>';
-
-
-$h = 0;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
-$head[$h][1] = $langs->trans("Setup");
-$h++;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
-$head[$h][1] = $langs->trans("Shipment");
-$hselected=$h;
-$h++;
-
-if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
-{
-    $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
-    $head[$h][1] = $langs->trans("Receivings");
-    $h++;
-}
-
-dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
+dol_fiche_head($head, 'shipment', $langs->trans("Sendings"), 0, 'sending');
 
 /*
  * Expedition numbering model
diff --git a/htdocs/admin/expedition_extrafields.php b/htdocs/admin/expedition_extrafields.php
new file mode 100644
index 0000000000000000000000000000000000000000..7db9a8f2526648ca14b305848c46857698878d6d
--- /dev/null
+++ b/htdocs/admin/expedition_extrafields.php
@@ -0,0 +1,126 @@
+<?php
+/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
+ * Copyright (C) 2003		Jean-Louis Bergamo		<jlb@j1b.org>
+ * Copyright (C) 2004-2013	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2012		Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2012		Florian Henry			<florian.henry@open-concept.pro>
+ * Copyright (C) 2013		Philippe Grand			<philippe.grand@atoo-net.com>
+ * Copyright (C) 2015		Claudio Aschieri		<c.aschieri@19.coop>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *      \file       htdocs/admin/expedition_extrafields.php
+ *		\ingroup    expedition
+ *		\brief      Page to setup extra fields of expedition
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+
+
+if (!$user->admin)
+	accessforbidden();
+
+$langs->load("admin");
+$langs->load("other");
+$langs->load("sendings");
+$langs->load("deliveries");
+
+
+$extrafields = new ExtraFields($db);
+$form = new Form($db);
+
+// List of supported format
+$tmptype2label=ExtraFields::$type2label;
+$type2label=array('');
+foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
+
+$action=GETPOST('action', 'alpha');
+$attrname=GETPOST('attrname', 'alpha');
+$elementtype='expedition'; //Must be the $table_element of the class that manage extrafield
+
+if (!$user->admin) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
+
+
+
+/*
+ * View
+ */
+
+$textobject=$langs->transnoentitiesnoconv("Sendings");
+
+llxHeader('',$langs->trans("SendingsSetup"));
+
+$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
+print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
+print "<br>\n";
+
+$head = expedition_admin_prepare_head();
+
+dol_fiche_head($head, 'attributes_shipment', $langs->trans("Sendings"), 0, 'sending');
+
+require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
+
+dol_fiche_end();
+
+
+// Buttons
+if ($action != 'create' && $action != 'edit')
+{
+    print '<div class="tabsAction">';
+    print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
+    print "</div>";
+}
+
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Creation d'un champ optionnel											  */
+/*                                                                            */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans('NewAttribute'));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
+}
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Edition d'un champ optionnel                                               */
+/*                                                                            */
+/* ************************************************************************** */
+if ($action == 'edit' && ! empty($attrname))
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans("FieldEdition", $attrname));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
+}
+
+llxFooter();
+
+$db->close();
diff --git a/htdocs/admin/expeditiondet_extrafields.php b/htdocs/admin/expeditiondet_extrafields.php
new file mode 100644
index 0000000000000000000000000000000000000000..caddf621db5eb29ede74e47737b6f920d040ff5f
--- /dev/null
+++ b/htdocs/admin/expeditiondet_extrafields.php
@@ -0,0 +1,126 @@
+<?php
+/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
+ * Copyright (C) 2003		Jean-Louis Bergamo		<jlb@j1b.org>
+ * Copyright (C) 2004-2013	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2012		Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2012		Florian Henry			<florian.henry@open-concept.pro>
+ * Copyright (C) 2013		Philippe Grand			<philippe.grand@atoo-net.com>
+ * Copyright (C) 2013		Florian Henry			<florian.henry@open-concept.pro>
+ * Copyright (C) 2015		Claudio Aschieri		<c.aschieri@19.coop>
+ * 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *      \file       htdocs/admin/expeditiondet_extrafields.php
+ *		\ingroup    expedition
+ *		\brief      Page to setup extra fields of expedition
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+
+
+if (!$user->admin)
+	accessforbidden();
+
+$langs->load("admin");
+$langs->load("other");
+$langs->load("sendings");
+
+$extrafields = new ExtraFields($db);
+$form = new Form($db);
+
+// List of supported format
+$tmptype2label=ExtraFields::$type2label;
+$type2label=array('');
+foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
+
+$action=GETPOST('action', 'alpha');
+$attrname=GETPOST('attrname', 'alpha');
+$elementtype='expeditiondet'; //Must be the $table_element of the class that manage extrafield
+
+if (!$user->admin) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
+
+
+
+/*
+ * View
+ */
+
+$textobject=$langs->transnoentitiesnoconv("Sendings");
+
+llxHeader('',$langs->trans("SendingsSetup"));
+
+$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
+print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
+print "<br>\n";
+
+$head = expedition_admin_prepare_head();
+
+dol_fiche_head($head, 'attributeslines_shipment', $langs->trans("Sendings"), 0, 'sending');
+
+require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
+
+dol_fiche_end();
+
+
+// Buttons
+if ($action != 'create' && $action != 'edit')
+{
+    print '<div class="tabsAction">';
+    print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
+    print "</div>";
+}
+
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Creation d'un champ optionnel											  */
+/*                                                                            */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans('NewAttribute'));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
+}
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Edition d'un champ optionnel                                               */
+/*                                                                            */
+/* ************************************************************************** */
+if ($action == 'edit' && ! empty($attrname))
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans("FieldEdition", $attrname));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
+}
+
+llxFooter();
+
+$db->close();
diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php
index ec00cc7233caa3cb4a32e8ff083c321f4ec71d11..e7112d1fbfe55f095d9663a0a47bb74475ee04f1 100644
--- a/htdocs/admin/livraison.php
+++ b/htdocs/admin/livraison.php
@@ -7,6 +7,7 @@
  * Copyright (C) 2005-2014 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2011-2013 Juanjo Menent        <jmenent@2byte.es>
  * Copyright (C) 2011-2015 Philippe Grand       <philippe.grand@atoo-net.com>
+ * Copyright (C) 2015			 Claudio Aschieri			<c.aschieri@19.coop>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +30,7 @@
  */
 require '../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
 
 $langs->load("admin");
@@ -210,28 +212,10 @@ $form=new Form($db);
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
 print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
 print '<br>';
+$head = expedition_admin_prepare_head();
 
+dol_fiche_head($head, 'receivings', $langs->trans("Receivings"), 0, 'sending');
 
-$h = 0;
-
-$head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
-$head[$h][1] = $langs->trans("Setup");
-$h++;
-
-if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
-{
-    $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
-    $head[$h][1] = $langs->trans("Shipment");
-    $h++;
-}
-
-$head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
-$head[$h][1] = $langs->trans("Receivings");
-$hselected=$h;
-$h++;
-
-
-dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
 
 /*
  * Livraison numbering model
@@ -503,7 +487,7 @@ print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 print '<input type="hidden" name="action" value="set_DELIVERY_FREE_TEXT">';
 print '<tr '.$bc[$var].'><td colspan="2">';
 print $langs->trans("FreeLegalTextOnDeliveryReceipts").' ('.$langs->trans("AddCRIfTooLong").')<br>';
-print '<textarea name="DELIVERY_FREE_TEXT" class="flat" cols="120">'.$conf->global->DELIVERY_FREE_TEXT.'</textarea>';
+$variablename='DELIVERY_FREE_TEXT';
 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
 {
     print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
diff --git a/htdocs/admin/livraison_extrafields.php b/htdocs/admin/livraison_extrafields.php
new file mode 100644
index 0000000000000000000000000000000000000000..a236e4954cf7665a2f71cdc6dd7d049c7e1947ec
--- /dev/null
+++ b/htdocs/admin/livraison_extrafields.php
@@ -0,0 +1,126 @@
+<?php
+/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
+ * Copyright (C) 2003		Jean-Louis Bergamo		<jlb@j1b.org>
+ * Copyright (C) 2004-2013	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2012		Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2012		Florian Henry			<florian.henry@open-concept.pro>
+ * Copyright (C) 2013		Philippe Grand			<philippe.grand@atoo-net.com>
+ * Copyright (C) 2015		Claudio Aschieri		<c.aschieri@19.coop>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *      \file       htdocs/admin/livraison_extrafields.php
+ *		\ingroup    livraison
+ *		\brief      Page to setup extra fields of livraison
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+
+
+if (!$user->admin)
+	accessforbidden();
+
+$langs->load("admin");
+$langs->load("other");
+$langs->load("sendings");
+$langs->load("deliveries");
+
+
+$extrafields = new ExtraFields($db);
+$form = new Form($db);
+
+// List of supported format
+$tmptype2label=ExtraFields::$type2label;
+$type2label=array('');
+foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
+
+$action=GETPOST('action', 'alpha');
+$attrname=GETPOST('attrname', 'alpha');
+$elementtype='livraison'; //Must be the $table_element of the class that manage extrafield
+
+if (!$user->admin) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
+
+
+
+/*
+ * View
+ */
+
+$textobject=$langs->transnoentitiesnoconv("Receivings");
+
+llxHeader('',$langs->trans("SendingsSetup"));
+
+$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
+print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
+print "<br>\n";
+
+$head = expedition_admin_prepare_head();
+
+dol_fiche_head($head, 'attributes_receivings', $langs->trans("Receivings"), 0, 'sending');
+
+require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
+
+dol_fiche_end();
+
+
+// Buttons
+if ($action != 'create' && $action != 'edit')
+{
+    print '<div class="tabsAction">';
+    print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
+    print "</div>";
+}
+
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Creation d'un champ optionnel											  */
+/*                                                                            */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans('NewAttribute'));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
+}
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Edition d'un champ optionnel                                               */
+/*                                                                            */
+/* ************************************************************************** */
+if ($action == 'edit' && ! empty($attrname))
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans("FieldEdition", $attrname));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
+}
+
+llxFooter();
+
+$db->close();
diff --git a/htdocs/admin/livraisondet_extrafields.php b/htdocs/admin/livraisondet_extrafields.php
new file mode 100644
index 0000000000000000000000000000000000000000..ffa00ecf2be926fe2d748640a4379a8ded33fdf0
--- /dev/null
+++ b/htdocs/admin/livraisondet_extrafields.php
@@ -0,0 +1,126 @@
+<?php
+/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
+ * Copyright (C) 2003		Jean-Louis Bergamo		<jlb@j1b.org>
+ * Copyright (C) 2004-2013	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2012		Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2012		Florian Henry			<florian.henry@open-concept.pro>
+ * Copyright (C) 2013		Philippe Grand			<philippe.grand@atoo-net.com>
+ * Copyright (C) 2013		Florian Henry			<florian.henry@open-concept.pro>
+ * Copyright (C) 2015		Claudio Aschieri		<c.aschieri@19.coop>
+ * 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *      \file       htdocs/admin/livraisondet_extrafields.php
+ *		\ingroup    livraison
+ *		\brief      Page to setup extra fields of livraison
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/expedition.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+
+
+if (!$user->admin)
+	accessforbidden();
+
+$langs->load("admin");
+$langs->load("other");
+$langs->load("sendings");
+
+$extrafields = new ExtraFields($db);
+$form = new Form($db);
+
+// List of supported format
+$tmptype2label=ExtraFields::$type2label;
+$type2label=array('');
+foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
+
+$action=GETPOST('action', 'alpha');
+$attrname=GETPOST('attrname', 'alpha');
+$elementtype='livraisondet'; //Must be the $table_element of the class that manage extrafield
+
+if (!$user->admin) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
+
+
+
+/*
+ * View
+ */
+
+$textobject=$langs->transnoentitiesnoconv("Receivings");
+
+llxHeader('',$langs->trans("SendingsSetup"));
+
+$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
+print load_fiche_titre($langs->trans("SendingsSetup"),$linkback,'title_setup');
+print "<br>\n";
+
+$head = expedition_admin_prepare_head();
+
+dol_fiche_head($head, 'attributeslines_receivings', $langs->trans("Receivings"), 0, 'sending');
+
+require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
+
+dol_fiche_end();
+
+
+// Buttons
+if ($action != 'create' && $action != 'edit')
+{
+    print '<div class="tabsAction">';
+    print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
+    print "</div>";
+}
+
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Creation d'un champ optionnel											  */
+/*                                                                            */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans('NewAttribute'));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
+}
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Edition d'un champ optionnel                                               */
+/*                                                                            */
+/* ************************************************************************** */
+if ($action == 'edit' && ! empty($attrname))
+{
+    print "<br>";
+    print load_fiche_titre($langs->trans("FieldEdition", $attrname));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
+}
+
+llxFooter();
+
+$db->close();
diff --git a/htdocs/core/lib/expedition.lib.php b/htdocs/core/lib/expedition.lib.php
new file mode 100644
index 0000000000000000000000000000000000000000..0fa5f0ae64365c6105920d3d532939604b8cc4da
--- /dev/null
+++ b/htdocs/core/lib/expedition.lib.php
@@ -0,0 +1,142 @@
+<?php
+/* Copyright (C) 2006-2012	Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2007		Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2010-2012	Regis Houssin        <regis.houssin@capnetworks.com>
+ * Copyright (C) 2010		Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2015 Claudio Aschieri				<c.aschieri@19.coop>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * or see http://www.gnu.org/
+ */
+
+/**
+ *  \file       htdocs/core/lib/expedition.lib.php
+ *  \brief      Function for expedition module
+ *  \ingroup    expedition
+ */
+
+/**
+ * Prepare array with list of tabs
+ *
+ * @param   Expedition	$object		Object related to tabs
+ * @return  array				Array of tabs to show
+ */
+function expedition_prepare_head(Expedition $object)
+{
+	global $langs, $conf, $user;
+	if (! empty($conf->expedition->enabled)) $langs->load("sendings");
+	$langs->load("orders");
+
+	$h = 0;
+	$head = array();
+	$h = 0;
+	
+	$head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
+	$head[$h][1] = $langs->trans("Setup");
+	$h++;
+	
+	$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
+	$head[$h][1] = $langs->trans("Shipment");
+	$hselected=$h;
+	$h++;
+	
+	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
+	{
+		$head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
+		$head[$h][1] = $langs->trans("Receivings");
+		$h++;
+	}
+	
+
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'order','remove');
+
+    return $head;
+}
+
+/**
+ *  Return array head with list of tabs to view object informations.
+ *
+ *  @return	array   	    		    head array with tabs
+ */
+function expedition_admin_prepare_head()
+{
+	global $langs, $conf, $user;
+	$langs->load("sendings");
+
+	$h = 0;
+	$head = array();
+	
+	$head[$h][0] = DOL_URL_ROOT."/admin/confexped.php";
+	$head[$h][1] = $langs->trans("Setup");
+	$head[$h][2] = 'general';
+	$h++;
+	
+	
+	if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
+	{
+		$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
+		$head[$h][1] = $langs->trans("Shipment");
+		$head[$h][2] = 'shipment';
+		$h++;
+	}
+	
+	
+	if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
+	{
+	$head[$h][0] = DOL_URL_ROOT.'/admin/expedition_extrafields.php';
+	$head[$h][1] = $langs->trans("ExtraFields");
+	$head[$h][2] = 'attributes_shipment';
+	$h++;
+	}
+	
+	if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
+	{
+	$head[$h][0] = DOL_URL_ROOT.'/admin/expeditiondet_extrafields.php';
+	$head[$h][1] = $langs->trans("ExtraFieldsLines");
+	$head[$h][2] = 'attributeslines_shipment';
+	$h++;
+	}
+	
+	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
+	{
+		$head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
+		$head[$h][1] = $langs->trans("Receivings");
+		$head[$h][2] = 'receivings';
+		$h++;
+	}
+	
+	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
+	{
+		$head[$h][0] = DOL_URL_ROOT.'/admin/livraison_extrafields.php';
+		$head[$h][1] = $langs->trans("ExtraFields");
+		$head[$h][2] = 'attributes_receivings';
+		$h++;
+	}
+	
+	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
+	{
+		$head[$h][0] = DOL_URL_ROOT.'/admin/livraisondet_extrafields.php';
+		$head[$h][1] = $langs->trans("ExtraFieldsLines");
+		$head[$h][2] = 'attributeslines_receivings';
+		$h++;
+	}
+	
+	
+	
+	complete_head_from_modules($conf,$langs,null,$head,$h,'expedition_admin','remove');
+
+	return $head;
+}
+
+
diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php
index b29016ac28ba13866603226f4f2f6ede850b97f6..8b38cbc552068b48759140f5d4303598c86996f2 100644
--- a/htdocs/core/tpl/extrafields_view.tpl.php
+++ b/htdocs/core/tpl/extrafields_view.tpl.php
@@ -59,6 +59,8 @@ if (empty($reshook) && ! empty($extrafields->attribute_label))
 			if (isset($user->rights->$keyforperm)) $permok=$user->rights->$keyforperm->creer||$user->rights->$keyforperm->create||$user->rights->$keyforperm->write;
 			if ($object->element=='order_supplier') $permok=$user->rights->fournisseur->commande->creer;
 			if ($object->element=='invoice_supplier') $permok=$user->rights->fournisseur->facture->creer;
+			if ($object->element=='shipping') $permok=$user->rights->expedition->creer;
+			if ($object->element=='delivery') $permok=$user->rights->expedition->livraison->creer;
 
 			if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key])
 				&& $permok && ($action != 'edit_extras' || GETPOST('attribute') != $key))
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index 6a236ab534e128d2ba5e3391bd9857e336bdd8b4..b3db0a40e12f679377d4c0d0cae9f7e31227d983 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -8,6 +8,7 @@
  * Copyright (C) 2013       Marcos García           <marcosgdf@gmail.com>
  * Copyright (C) 2014		Cedric GROSS			<c.gross@kreiz-it.fr>
  * Copyright (C) 2014		Francis Appels			<francis.appels@yahoo.com>
+ * Copyright (C) 2015		Claudio Aschieri		<c.aschieri@19.coop>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,6 +38,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
 if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
 if (! empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
 if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
@@ -75,6 +77,15 @@ $hidedesc 	 = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty(
 $hideref 	 = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
 
 $object = new Expedition($db);
+$extrafields = new ExtraFields($db);
+$extrafieldsline = new ExtraFields($db);
+
+// fetch optionals attributes and labels
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+
+// fetch optionals attributes lines and labels
+$extralabelslines=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+
 
 // Load object. Make an object->fetch
 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be include, not include_once
@@ -111,6 +122,33 @@ if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
 	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
 }
 
+if ($action == 'update_extras')
+{
+	// Fill array 'array_options' with data from update form
+	$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+	$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
+	if ($ret < 0) $error++;
+
+	if (! $error)
+	{
+		// Actions on extra fields (by external module or standard code)
+		// TODO le hook fait double emploi avec le trigger !!
+		$hookmanager->initHooks(array('expeditiondao'));
+		$parameters = array('id' => $object->id);
+		$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+		if (empty($reshook)) {
+			$result = $object->insertExtraFields();
+			if ($result < 0) {
+				$error++;
+			}
+		} else if ($reshook < 0)
+			$error++;
+	}
+
+	if ($error)
+		$action = 'edit_extras';
+}
+
 $parameters=array();
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@@ -119,9 +157,10 @@ if (empty($reshook))
 {
 	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';		// Must be include, not include_once
 
-	if ($action == 'add')
+	if ($action == 'add' && $user->rights->expedition->creer)
 	{
 	    $error=0;
+	    $predef='';
 
 	    $db->begin();
 
@@ -157,7 +196,8 @@ if (empty($reshook))
 		$object->location_incoterms 	= GETPOST('location_incoterms', 'alpha');
 
 	    $batch_line = array();
-
+	    $array_options=array();
+	    
 	    $num=count($objectsrc->lines);
 	    $totalqty=0;
 
@@ -201,8 +241,20 @@ if (empty($reshook))
 				//shipment line for product with no batch management
 				if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
 			}
+			
+			// Extrafields
+			$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+	    $array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i);
+			// Unset extrafield
+			if (is_array($extralabelsline)) {
+				// Get extra fields
+				foreach ($extralabelsline as $key => $value) {
+					unset($_POST["options_" . $key]);
+				}
+			}
+			
 	    }
-		
+	
 	    //var_dump($batch_line[2]);
 
 	    if ($totalqty > 0)		// There is at least one thing to ship
@@ -220,8 +272,8 @@ if (empty($reshook))
 						$idl = "idl".$i;
 						$entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
 						if ($entrepot_id < 0) $entrepot_id='';
-
-						$ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int'));
+						
+						$ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int'),$array_options[$i]);
 						if ($ret < 0)
 						{
 							$mesg='<div class="error">'.$object->error.'</div>';
@@ -234,7 +286,7 @@ if (empty($reshook))
 					// batch mode
 					if ($batch_line[$i]['qty']>0)
 					{
-						$ret=$object->addline_batch($batch_line[$i]);
+						$ret=$object->addline_batch($batch_line[$i],$array_options[$i]);
 						if ($ret < 0)
 						{
 							$mesg='<div class="error">'.$object->error.'</div>';
@@ -242,8 +294,11 @@ if (empty($reshook))
 						}
 					}
 				}
-	        }
-
+	        }	        
+	        // Fill array 'array_options' with data from add form
+	        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
+	        if ($ret < 0) $error++;
+	        
 	        if (! $error)
 	        {
 	            $ret=$object->create($user);		// This create shipment (like Odoo picking) and line of shipments. Stock movement will when validating shipment.
@@ -606,6 +661,15 @@ if ($action == 'create')
             print '<td colspan="3">';
             print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number','alpha').'">';
             print "</td></tr>\n";
+            
+            // Other attributes
+            $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'socid'=>$socid);
+            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action);    // Note that $action and $object may have been modified by hook
+            
+            if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+            	print $expe->showOptionals($extrafields, 'edit');
+            }
+            
 
             // Incoterms
 			if (!empty($conf->incoterm->enabled))
@@ -624,17 +688,13 @@ if ($action == 'create')
 			$liste = ModelePdfExpedition::liste_modeles($db);
 			print $form->selectarray('model', $liste, $conf->global->EXPEDITION_ADDON_PDF);
             print "</td></tr>\n";
-
-            // Other attributes
-            $parameters=array('colspan' => ' colspan="3"');
-            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action);    // Note that $action and $object may have been modified by hook
-
+            
             print "</table>";
 
             dol_fiche_end();
 
             /*
-             * Lignes de commandes
+             * Expedition Lines
              */
 
             $numAsked = count($object->lines);
@@ -898,6 +958,17 @@ if ($action == 'create')
 						print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->libelle);
 					}
 				}
+				
+				
+				//Display lines extrafields
+				if (is_array($extralabelslines) && count($extralabelslines)>0) {
+					$colspan=5;
+					$line = new ExpeditionLigne($db);
+					$line->fetch_optionals($object->id,$extralabelslines);
+					print '<tr '.$bc[$var].'>';
+					print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
+					print '</tr>';
+				}
 
                 $indiceAsked++;
             }
@@ -939,6 +1010,8 @@ else if ($id || $ref)
 
 		$soc = new Societe($db);
 		$soc->fetch($object->socid);
+		
+		$res = $object->fetch_optionals($object->id, $extralabels);
 
 		$head=shipping_prepare_head($object);
 		dol_fiche_head($head, 'shipping', $langs->trans("Shipment"), 0, 'sending');
@@ -1259,9 +1332,9 @@ else if ($id || $ref)
 		}
 
 		// Other attributes
-		$parameters=array('colspan' => ' colspan="3"');
-		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
-
+		$cols = 3;
+		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
+		
 		print "</table>\n";
 
 		/*
@@ -1444,6 +1517,16 @@ else if ($id || $ref)
 				}
 			}
 			print "</tr>";
+			
+			//Display lines extrafields
+			if (is_array($extralabelslines) && count($extralabelslines)>0) {
+				$colspan= empty($conf->productbatch->enabled) ? 5 : 6;
+				$line = new ExpeditionLigne($db);
+				$line->fetch_optionals($lines[$i]->id,$extralabelslines);
+				print '<tr '.$bc[$var].'>';
+				print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
+				print '</tr>';
+			}
 
 			$var=!$var;
 		}
diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php
index d7bfc9aed9873c17a52eeb30e7d071349d0d1948..39b69ffb4474471da770725d7f46cd00237b7a98 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -8,6 +8,7 @@
  * Copyright (C) 2014		Cedric GROSS			<c.gross@kreiz-it.fr>
  * Copyright (C) 2014-2015  Marcos García           <marcosgdf@gmail.com>
  * Copyright (C) 2014-2015  Francis Appels          <francis.appels@yahoo.com>
+ * Copyright (C) 2015				Claudio Aschieri				<c.aschieri@19.coop>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,6 +31,7 @@
  */
 
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
+require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
 if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
 if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
 if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
@@ -43,6 +45,7 @@ class Expedition extends CommonObject
 	public $element="shipping";
 	public $fk_element="fk_expedition";
 	public $table_element="expedition";
+	public $table_element_line="expeditiondet";
 	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
 
 	var $socid;
@@ -167,11 +170,12 @@ class Expedition extends CommonObject
 	 *  Create expedition en base
 	 *
 	 *  @param	User	$user       Objet du user qui cree
+   * 	@param		int		$notrigger	1=Does not execute triggers, 0= execuete triggers
 	 *  @return int 				<0 si erreur, id expedition creee si ok
 	 */
-	function create($user)
+	function create($user, $notrigger=0)
 	{
-		global $conf, $langs;
+		global $conf, $langs, $hookmanager;
 
 		$now=dol_now();
 
@@ -255,14 +259,14 @@ class Expedition extends CommonObject
 				{
 					if (! isset($this->lines[$i]->detail_batch))
 					{	// no batch management
-						if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty) > 0)
+						if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->array_options) > 0)
 						{
 							$error++;
 						}
 					}
 					else
 					{	// with batch management
-						if (! $this->create_line_batch($this->lines[$i]) > 0)
+						if (! $this->create_line_batch($this->lines[$i],$this->lines[$i]->array_options) > 0)
 						{
 							$error++;
 						}
@@ -284,8 +288,26 @@ class Expedition extends CommonObject
 						$error++;
 					}
 				}
+				
+				// Actions on extra fields (by external module or standard code)
+				// TODO le hook fait double emploi avec le trigger !!
+				$hookmanager->initHooks(array('expeditiondao'));
+				$parameters=array('socid'=>$this->id);
+				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
+				if (empty($reshook))
+				{
+					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+					{
+						$result=$this->insertExtraFields();
+						if ($result < 0)
+						{
+							$error++;
+						}
+					}
+				}
+				else if ($reshook < 0) $error++;
 
-				if (! $error)
+				if (! $error && ! $notrigger)
 				{
                     // Call trigger
                     $result=$this->call_trigger('SHIPPING_CREATE',$user);
@@ -340,10 +362,12 @@ class Expedition extends CommonObject
 	 * @param 	int		$entrepot_id		Id of warehouse
 	 * @param 	int		$origin_line_id		Id of source line
 	 * @param 	int		$qty				Quantity
+	 * @param	array		$array_options		extrafields array
 	 * @return	int							<0 if KO, >0 if OK
 	 */
-	function create_line($entrepot_id, $origin_line_id, $qty)
+	function create_line($entrepot_id, $origin_line_id, $qty,$array_options=0)
 	{
+		global $conf;
 		$error = 0;
 
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (";
@@ -363,6 +387,19 @@ class Expedition extends CommonObject
 		{
 			$error++;
 		}
+		
+		if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
+		{
+			$expeditionline = new ExpeditionLigne($this->db);
+			$expeditionline->array_options=$array_options;
+			$expeditionline->id= $this->db->last_insert_id(MAIN_DB_PREFIX.$expeditionline->table_element);
+			$result=$expeditionline->insertExtraFields();
+			if ($result < 0)
+			{
+				$this->error[]=$expeditionline->error;
+				$error++;
+			}
+		}
 
 		if (! $error) return 1;
 		else return -1;
@@ -373,13 +410,14 @@ class Expedition extends CommonObject
 	 * Create the detail (eat-by date) of the expedition line
 	 *
 	 * @param 	object		$line_ext		full line informations
+	 * @param	array		$array_options		extrafields array
 	 * @return	int							<0 if KO, >0 if OK
 	 */
-	function create_line_batch($line_ext)
+	function create_line_batch($line_ext,$array_options=0)
 	{
 		$error = 0;
 
-		if ($this->create_line(($line_ext->entrepot_id?$line_ext->entrepot_id:'null'),$line_ext->origin_line_id,$line_ext->qty) < 0)
+		if ($this->create_line(($line_ext->entrepot_id?$line_ext->entrepot_id:'null'),$line_ext->origin_line_id,$line_ext->qty,$array_options) < 0)
 		{
 			$error++;
 		}
@@ -500,6 +538,13 @@ class Expedition extends CommonObject
 				 * Thirparty
 				 */
 				$result=$this->fetch_thirdparty();
+				
+				// Retrieve all extrafields for expedition
+				// fetch optionals attributes and labels
+				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+				$extrafields=new ExtraFields($this->db);
+				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
+				$this->fetch_optionals($this->id,$extralabels);
 
 				/*
 				 * Lines
@@ -784,9 +829,10 @@ class Expedition extends CommonObject
 	 * @param 	int		$entrepot_id		Id of warehouse
 	 * @param 	int		$id					Id of source line (order line)
 	 * @param 	int		$qty				Quantity
+	 * @param	array		$array_options		extrafields array
 	 * @return	int							<0 if KO, >0 if OK
 	 */
-	function addline($entrepot_id, $id, $qty)
+	function addline($entrepot_id, $id, $qty,$array_options=0)
 	{
 		global $conf, $langs;
 
@@ -824,7 +870,11 @@ class Expedition extends CommonObject
 				}
 			}
 		}
-
+		
+		// extrafields
+		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
+			$line->array_options = $array_options;
+		
 		$this->lines[$num] = $line;
 	}
 
@@ -832,10 +882,13 @@ class Expedition extends CommonObject
 	 * Add a shipment line with batch record
 	 *
 	 * @param 	array		$dbatch		Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index)
+	 * @param	array		$array_options		extrafields array
 	 * @return	int						<0 if KO, >0 if OK
 	 */
-	function addline_batch($dbatch)
+	function addline_batch($dbatch,$array_options=0)
 	{
+		global $conf;
+		
 		$num = count($this->lines);
 		if ($dbatch['qty']>0)
 		{
@@ -872,6 +925,10 @@ class Expedition extends CommonObject
 			$line->qty = $dbatch['qty'];
 			$line->detail_batch=$tab;
 
+			// extrafields
+			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
+				$line->array_options = $array_options;
+			
 			//var_dump($line);
 			$this->lines[$num] = $line;
 		}
@@ -1765,7 +1822,7 @@ class Expedition extends CommonObject
 /**
  * Classe de gestion des lignes de bons d'expedition
  */
-class ExpeditionLigne
+class ExpeditionLigne extends CommonObjectLine
 {
 	var $db;
 
@@ -1790,6 +1847,9 @@ class ExpeditionLigne
 	var $total_localtax1;   // Total Local tax 1
 	var $total_localtax2;   // Total Local tax 2
 
+	public $element='expeditiondet';
+	public $table_element='expeditiondet';
+	
 	public $fk_origin_line;
 
 	// Deprecated
diff --git a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
index 99a042c8c31becf3dfeb3639ea1ea929004c6eb7..6def2432254c4de25002950b6860dab1db9115f8 100755
--- a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
+++ b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
@@ -315,6 +315,54 @@ create table llx_categorie_project
   import_key    varchar(14)
 )ENGINE=innodb;
 
+
+
+
+-- Extrafields Expedition (shipment)
+create table llx_expedition_extrafields
+(
+  rowid                     integer AUTO_INCREMENT PRIMARY KEY,
+  tms                       timestamp,
+  fk_object                 integer NOT NULL,
+  import_key                varchar(14)                          		-- import key
+) ENGINE=innodb;
+
+ALTER TABLE llx_expedition_extrafields ADD INDEX idx_expedition_extrafields (fk_object);
+
+create table llx_expeditiondet_extrafields
+(
+  rowid            integer AUTO_INCREMENT PRIMARY KEY,
+  tms              timestamp,
+  fk_object        integer NOT NULL,    -- object id
+  import_key       varchar(14)      	-- import key
+)ENGINE=innodb;
+
+ALTER TABLE llx_expeditiondet_extrafields ADD INDEX idx_expeditiondet_extrafields (fk_object);
+
+
+
+-- Extrafields Expedition (delivery receipts)
+create table llx_livraison_extrafields
+(
+  rowid                     integer AUTO_INCREMENT PRIMARY KEY,
+  tms                       timestamp,
+  fk_object                 integer NOT NULL,
+  import_key                varchar(14)                          		-- import key
+) ENGINE=innodb;
+
+ALTER TABLE llx_livraison_extrafields ADD INDEX idx_livraison_extrafields (fk_object);
+
+create table llx_livraisondet_extrafields
+(
+  rowid            integer AUTO_INCREMENT PRIMARY KEY,
+  tms              timestamp,
+  fk_object        integer NOT NULL,    -- object id
+  import_key       varchar(14)      	-- import key
+)ENGINE=innodb;
+
+ALTER TABLE llx_livraisondet_extrafields ADD INDEX idx_livraisondet_extrafields (fk_object);
+
+
 ALTER TABLE llx_categorie_project ADD PRIMARY KEY pk_categorie_project (fk_categorie, fk_project);
 ALTER TABLE llx_categorie_project ADD INDEX idx_categorie_project_fk_categorie (fk_categorie);
 ALTER TABLE llx_categorie_project ADD INDEX idx_categorie_project_fk_project (fk_project);
diff --git a/htdocs/install/mysql/tables/llx_expedition_extrafields.key.sql b/htdocs/install/mysql/tables/llx_expedition_extrafields.key.sql
new file mode 100644
index 0000000000000000000000000000000000000000..b539f460a08738467322c8ee0ed3ebecbf146402
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_expedition_extrafields.key.sql
@@ -0,0 +1,20 @@
+-- ===================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+
+ALTER TABLE llx_expedition_extrafields ADD INDEX idx_expedition_extrafields (fk_object);
diff --git a/htdocs/install/mysql/tables/llx_expedition_extrafields.sql b/htdocs/install/mysql/tables/llx_expedition_extrafields.sql
new file mode 100644
index 0000000000000000000000000000000000000000..eff8465fbf66061703152a9772d016e235feed56
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_expedition_extrafields.sql
@@ -0,0 +1,26 @@
+-- ========================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ========================================================================
+
+create table llx_expedition_extrafields
+(
+  rowid                     integer AUTO_INCREMENT PRIMARY KEY,
+  tms                       timestamp,
+  fk_object                 integer NOT NULL,
+  import_key                varchar(14)                          		-- import key
+) ENGINE=innodb;
+
diff --git a/htdocs/install/mysql/tables/llx_expeditiondet_extrafields.key.sql b/htdocs/install/mysql/tables/llx_expeditiondet_extrafields.key.sql
new file mode 100644
index 0000000000000000000000000000000000000000..11e133442d50af2a6e2fd7d320062f6b4c42a1fb
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_expeditiondet_extrafields.key.sql
@@ -0,0 +1,20 @@
+-- ===================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+
+ALTER TABLE llx_expeditiondet_extrafields ADD INDEX idx_expeditiondet_extrafields (fk_object);
diff --git a/htdocs/install/mysql/tables/llx_expeditiondet_extrafields.sql b/htdocs/install/mysql/tables/llx_expeditiondet_extrafields.sql
new file mode 100644
index 0000000000000000000000000000000000000000..e27c7f3e5054386c53bb71f26a4802ea5301e106
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_expeditiondet_extrafields.sql
@@ -0,0 +1,25 @@
+-- ===================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+create table llx_expeditiondet_extrafields
+(
+  rowid            integer AUTO_INCREMENT PRIMARY KEY,
+  tms              timestamp,
+  fk_object        integer NOT NULL,    -- object id
+  import_key       varchar(14)      	-- import key
+)ENGINE=innodb;
diff --git a/htdocs/install/mysql/tables/llx_livraison_extrafields.key.sql b/htdocs/install/mysql/tables/llx_livraison_extrafields.key.sql
new file mode 100644
index 0000000000000000000000000000000000000000..68e1f30bd1544d590cbf4de2b40384fbe08982ca
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_livraison_extrafields.key.sql
@@ -0,0 +1,20 @@
+-- ===================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+
+ALTER TABLE llx_livraison_extrafields ADD INDEX idx_livraison_extrafields (fk_object);
diff --git a/htdocs/install/mysql/tables/llx_livraison_extrafields.sql b/htdocs/install/mysql/tables/llx_livraison_extrafields.sql
new file mode 100644
index 0000000000000000000000000000000000000000..8a140496016ac39883055a942de6765497293667
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_livraison_extrafields.sql
@@ -0,0 +1,26 @@
+-- ========================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ========================================================================
+
+create table llx_livraison_extrafields
+(
+  rowid                     integer AUTO_INCREMENT PRIMARY KEY,
+  tms                       timestamp,
+  fk_object                 integer NOT NULL,
+  import_key                varchar(14)                          		-- import key
+) ENGINE=innodb;
+
diff --git a/htdocs/install/mysql/tables/llx_livraisondet_extrafields.key.sql b/htdocs/install/mysql/tables/llx_livraisondet_extrafields.key.sql
new file mode 100644
index 0000000000000000000000000000000000000000..e3fcb9a0f237c6439358dee8f3b0f81fa85d1b70
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_livraisondet_extrafields.key.sql
@@ -0,0 +1,20 @@
+-- ===================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+
+ALTER TABLE llx_livraisondet_extrafields ADD INDEX idx_livraisondet_extrafields (fk_object);
diff --git a/htdocs/install/mysql/tables/llx_livraisondet_extrafields.sql b/htdocs/install/mysql/tables/llx_livraisondet_extrafields.sql
new file mode 100644
index 0000000000000000000000000000000000000000..18295a90f5a71b1a7fe92c51d57c4efb1ab13056
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_livraisondet_extrafields.sql
@@ -0,0 +1,25 @@
+-- ===================================================================
+-- Copyright (C) 2015      Claudio Aschieri	<c.aschieri@19.coop>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+create table llx_livraisondet_extrafields
+(
+  rowid            integer AUTO_INCREMENT PRIMARY KEY,
+  tms              timestamp,
+  fk_object        integer NOT NULL,    -- object id
+  import_key       varchar(14)      	-- import key
+)ENGINE=innodb;
diff --git a/htdocs/livraison/card.php b/htdocs/livraison/card.php
index ec4feeb6bf998672f4ab27723a583a3ae03d8a48..c08c80536d7b77a6021dc5457b79f2157b05f44d 100644
--- a/htdocs/livraison/card.php
+++ b/htdocs/livraison/card.php
@@ -5,6 +5,7 @@
  * Copyright (C) 2005-2014	Regis Houssin			<regis.houssin@capnetworks.com>
  * Copyright (C) 2007		Franky Van Liedekerke	<franky.van.liedekerke@telenet.be>
  * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
+ * Copyright (C) 2015			  Claudio Aschieri		<c.aschieri@19.coop>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
 require_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
 if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
 	require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
 if (! empty($conf->expedition_bon->enabled))
@@ -55,15 +57,17 @@ if ($user->societe_id) $socid=$user->societe_id;
 $result=restrictedArea($user,'expedition',$id,'livraison','livraison');
 
 $object = new Livraison($db);
+$extrafields = new ExtraFields($db);
+$extrafieldsline = new ExtraFields($db);
 
-// Load object
-if ($id > 0 || ! empty($ref)) {
-	$ret = $object->fetch($id, $ref);
-	if ($ret > 0)
-		$ret = $object->fetch_thirdparty();
-	if ($ret < 0)
-		dol_print_error('', $object->error);
-}
+// fetch optionals attributes and labels
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+
+// fetch optionals attributes lines and labels
+$extralabelslines=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+
+// Load object. Make an object->fetch
+include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be include, not include_once
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 $hookmanager->initHooks(array('deliverycard','globalcard'));
@@ -181,6 +185,64 @@ elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
 	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
 }
 
+// Update extrafields
+if ($action == 'update_extras')
+{
+	// Fill array 'array_options' with data from update form
+	$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
+	$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
+	if ($ret < 0) $error++;
+
+	if (! $error)
+	{
+		// Actions on extra fields (by external module or standard code)
+		// TODO le hook fait double emploi avec le trigger !!
+		$hookmanager->initHooks(array('livraisondao'));
+		$parameters = array('id' => $object->id);
+		$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+		if (empty($reshook)) {
+			$result = $object->insertExtraFields();
+			if ($result < 0) {
+				$error++;
+			}
+		} else if ($reshook < 0)
+			$error++;
+	}
+
+	if ($error)
+		$action = 'edit_extras';
+}
+
+// Extrafields line
+if ($action == 'update_extras_line')
+{
+	$array_options=array();
+	$num=count($object->lines);
+	
+	for ($i = 0; $i < $num; $i++)
+	{
+		// Extrafields
+		$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+		$array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i);
+		// Unset extrafield
+		if (is_array($extralabelsline)) {
+			// Get extra fields
+			foreach ($extralabelsline as $key => $value) {
+				unset($_POST["options_" . $key]);
+			}
+		}
+		
+		$ret = $object->update_line($object->lines[$i]->id,$array_options[$i]);	// extrafields update
+		if ($ret < 0)
+		{
+			$mesg='<div class="error">'.$object->error.'</div>';
+			$error++;
+		}
+	}
+
+}
+
+
 /*
  * Build document
  */
@@ -502,6 +564,14 @@ else
 			/*
 			 *   Livraison
 			 */
+			
+			print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
+			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+			print '<input type="hidden" name="action" value="update_extras_line">';
+			print '<input type="hidden" name="origin" value="'.$origin.'">';
+			print '<input type="hidden" name="id" value="'.$object->id.'">';
+			print '<input type="hidden" name="ref" value="'.$object->ref.'">';
+			
 			print '<table class="border" width="100%">';
 
 			// Shipment
@@ -638,6 +708,10 @@ else
 				print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/product/stock/card.php?id='.$entrepot->id.'">'.$entrepot->libelle.'</a></td>';
 				print '</tr>';
 			}
+			
+			// Other attributes
+			$cols = 2;
+			include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
 
 			print "</table><br>\n";
 
@@ -727,11 +801,29 @@ else
 				print '<td align="center">'.$object->lines[$i]->qty_shipped.'</td>';
 
 				print "</tr>";
+				
+				//Display lines extrafields
+				if (is_array($extralabelslines) && count($extralabelslines)>0) {
+					$colspan=2;
+					$mode = ($object->statut == 0) ? 'edit' : 'view';
+					$line = new LivraisonLigne($db);
+					$line->fetch_optionals($object->lines[$i]->id,$extralabelslines);
+					print '<tr '.$bc[$var].'>';
+					print $line->showOptionals($extrafieldsline, $mode, array('style'=>$bc[$var], 'colspan'=>$colspan),$i);
+					print '</tr>';
+				}
 
 				$i++;
 			}
 
 			print "</table>\n";
+			
+			if($object->statut == 0)	// only if draft
+				print '<br><div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
+			
+			print '</form>';
+				
+			
 
 			print "\n</div>\n";
 
diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php
index f111d6b604d4d5ae40d38085fd6fadbd65c00036..faac4766337148920b16ea48f6fb7679fdf5b51b 100644
--- a/htdocs/livraison/class/livraison.class.php
+++ b/htdocs/livraison/class/livraison.class.php
@@ -42,6 +42,7 @@ class Livraison extends CommonObject
 	public $element="delivery";
 	public $fk_element="fk_livraison";
 	public $table_element="livraison";
+	public $table_element_line="livraisondet";
 
 	var $brouillon;
 	var $socid;
@@ -299,6 +300,14 @@ class Livraison extends CommonObject
 				$this->db->free($result);
 
 				if ($this->statut == 0) $this->brouillon = 1;
+				
+				
+				// Retrieve all extrafields for delivery
+				// fetch optionals attributes and labels
+				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+				$extrafields=new ExtraFields($this->db);
+				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
+				$this->fetch_optionals($this->id,$extralabels);
 
 				/*
 				 * Lignes
@@ -523,7 +532,37 @@ class Livraison extends CommonObject
 		return $this->create($user);
 	}
 
-
+	/**
+	 * Update a livraison line (only extrafields)
+	 *
+	 * @param 	int		$id					Id of line (livraison line)
+	 * @param	array		$array_options		extrafields array
+	 * @return	int							<0 if KO, >0 if OK
+	 */
+	function update_line($id, $array_options=0)
+	{
+		global $conf;
+		$error = 0;
+	
+		if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
+		{
+			$livraisonline = new LivraisonLigne($this->db);
+			$livraisonline->array_options=$array_options;
+			$livraisonline->id=$id;
+			$result=$livraisonline->insertExtraFields();
+			
+			if ($result < 0)
+			{
+				$this->error[]=$livraisonline->error;
+				$error++;
+			}
+		}
+	
+		if (! $error) return 1;
+		else return -1;
+	}
+	
+	
 	/**
 	 * 	Add line
 	 *
@@ -709,6 +748,7 @@ class Livraison extends CommonObject
 
 				$obj = $this->db->fetch_object($resql);
 
+				$line->id					= $obj->rowid;
 				$line->label			= $obj->custom_label;
 				$line->description		= $obj->description;
 				$line->fk_product		= $obj->fk_product;
@@ -1006,6 +1046,8 @@ class Livraison extends CommonObject
  */
 class LivraisonLigne extends CommonObjectLine
 {
+	var $db;
+	
 	// From llx_expeditiondet
 	var $qty;
 	var $qty_asked;
@@ -1028,6 +1070,9 @@ class LivraisonLigne extends CommonObjectLine
 
 	public $product_ref;
 	public $product_label;
+	
+	public $element='livraisondet';
+	public $table_element='livraisondet';
 
 	/**
 	 *	Constructor