diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index a53e9cbaf0d..2bb9df4724e 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -260,6 +260,21 @@ abstract class CommonObject
*/
public $origin_id;
+ /**
+ * @var Object Origin object. This is set by fetch_origin() from this->origin and this->origin_id.
+ */
+ public $origin_object;
+
+ // TODO Remove this. Has been replaced with ->origin_object.
+ // This is set by fetch_origin() from this->origin and this->origin_id
+ /** @deprecated */
+ public $expedition;
+ /** @deprecated */
+ public $livraison;
+ /** @deprecated */
+ public $commandeFournisseur;
+
+
/**
* @var string The object's reference
*/
@@ -1870,7 +1885,9 @@ abstract class CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
- * Read linked origin object
+ * Read linked origin object.
+ * Set ->origin_object
+ * Set also ->expedition or ->livraison or ->commandFournisseur (deprecated)
*
* @return void
*/
@@ -1883,15 +1900,18 @@ abstract class CommonObject
if ($this->origin == 'delivery') {
$this->origin = 'livraison';
}
- if ($this->origin == 'order_supplier') {
+ if ($this->origin == 'order_supplier' || $this->origin == 'supplier_order') {
$this->origin = 'commandeFournisseur';
}
$origin = $this->origin;
$classname = ucfirst($origin);
- $this->$origin = new $classname($this->db);
- $this->$origin->fetch($this->origin_id);
+ $this->origin_object = new $classname($this->db);
+ $this->origin_object->fetch($this->origin_id);
+
+ // TODO Remove this line
+ $this->$origin = $this->origin_object;
}
/**
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index 3690c6e75d4..50ca67b83ab 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -1755,7 +1755,8 @@ if ($action == 'create') {
$typeobject = $object->origin;
$origin = $object->origin;
$origin_id = $object->origin_id;
- $object->fetch_origin(); // Load property $object->commande, $object->propal, ...
+
+ $object->fetch_origin(); // Load property $object->origin_object (old $object->commande, $object->propal, ...)
}
$soc = new Societe($db);
@@ -1768,7 +1769,7 @@ if ($action == 'create') {
$formconfirm = '';
- // Confirm deleteion
+ // Confirm deletion
if ($action == 'delete') {
$formquestion = array();
if ($object->statut == Expedition::STATUS_CLOSED && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
diff --git a/htdocs/install/mysql/migration/18.0.0-19.0.0.sql b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql
index 4dc0417d54d..13433b716fd 100644
--- a/htdocs/install/mysql/migration/18.0.0-19.0.0.sql
+++ b/htdocs/install/mysql/migration/18.0.0-19.0.0.sql
@@ -191,3 +191,5 @@ CREATE TABLE llx_mrp_production_extrafields
) ENGINE=innodb;
ALTER TABLE llx_mrp_production_extrafields ADD INDEX idx_mrp_production_fk_object(fk_object);
+
+ALTER TABLE llx_commande_fournisseur_dispatch ADD COLUMN element_type varchar(50) DEFAULT 'supplier_order' NOT NULL;
diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql b/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql
index fa7cd92ba1f..6bbaea61c45 100644
--- a/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql
+++ b/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql
@@ -14,21 +14,23 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
--
--- This table is just an history table to track all receiving done for a
+-- This table is just an history table to track all receiption to do or done for a
-- particular supplier order. A movement with same information is also done
-- into stock_movement so this table may be useless.
--
-- Detail of each lines of a reception (qty, batch and into which warehouse must be
-- received or has been receveived a purchase order line).
--- This table should have been named llx_receptiondet_batch
+--
+-- This table should be renamed into llx_receptiondet_batch
-- ===================================================================
create table llx_commande_fournisseur_dispatch
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_product integer,
- fk_commande integer,
- fk_commandefourndet integer,
+ fk_commande integer, -- should be renamed into fk_element
+ fk_commandefourndet integer, -- should be renamed into fk_elementdet
+ element_type varchar(50) DEFAULT 'supplier_order' NOT NULL, -- Type of source ('supplier_order', ...)
fk_projet integer DEFAULT NULL,
fk_reception integer DEFAULT NULL,
qty float, -- qty to move
diff --git a/htdocs/install/mysql/tables/llx_expedition.sql b/htdocs/install/mysql/tables/llx_expedition.sql
index f61ab8224f0..f5c910af583 100644
--- a/htdocs/install/mysql/tables/llx_expedition.sql
+++ b/htdocs/install/mysql/tables/llx_expedition.sql
@@ -17,6 +17,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
--
+-- Note: a shipment is linked to an order or other object using llx_element_element table.
-- ===================================================================
create table llx_expedition
@@ -31,11 +32,11 @@ create table llx_expedition
ref_ext varchar(255), -- reference into an external system (not used by dolibarr)
ref_customer varchar(255), -- customer number
- date_creation datetime, -- date de creation
+ date_creation datetime, -- date of creation
fk_user_author integer, -- author of creation
fk_user_modif integer, -- author of last change
- date_valid datetime, -- date de validation
- fk_user_valid integer, -- valideur
+ date_valid datetime, -- date of validation
+ fk_user_valid integer, -- user that validate
date_delivery datetime DEFAULT NULL, -- date planned of delivery
date_expedition datetime, -- not used (deprecated)
fk_address integer DEFAULT NULL, -- delivery address (deprecated)
diff --git a/htdocs/install/mysql/tables/llx_reception.sql b/htdocs/install/mysql/tables/llx_reception.sql
index d506215ee4a..26f9ed00863 100644
--- a/htdocs/install/mysql/tables/llx_reception.sql
+++ b/htdocs/install/mysql/tables/llx_reception.sql
@@ -17,6 +17,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
--
+-- Note: a reception is linked to a supplier order or other object using llx_element_element table.
-- ===================================================================
create table llx_reception
@@ -29,7 +30,7 @@ create table llx_reception
fk_projet integer DEFAULT NULL,
ref_ext varchar(30), -- reference into an external system (not used by dolibarr)
- ref_supplier varchar(255), -- supplier number
+ ref_supplier varchar(255), -- reference of reception on supplier side
date_creation datetime, -- date de creation
fk_user_author integer, -- author of creation
diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php
index 913bfa11e94..131359ca999 100644
--- a/htdocs/reception/card.php
+++ b/htdocs/reception/card.php
@@ -122,6 +122,7 @@ if ($id > 0 || !empty($ref)) {
$object->fetch($id, $ref);
$object->fetch_thirdparty();
+ $typeobject = '';
if (!empty($object->origin)) {
$origin = $object->origin;
@@ -129,11 +130,10 @@ if ($id > 0 || !empty($ref)) {
$typeobject = $object->origin;
}
- // Linked documents
- if ($origin == 'order_supplier' && $object->$typeobject->id && isModEnabled("supplier_order")) {
- $origin_id = $object->$typeobject->id;
- $objectsrc = new CommandeFournisseur($db);
- $objectsrc->fetch($object->$typeobject->id);
+ // Set $origin_id and $objectsrc
+ if (($origin == 'order_supplier' || $origin == 'supplier_order') && is_object($object->origin_object) && isModEnabled("supplier_order")) {
+ $origin_id = $object->origin_object->id;
+ $objectsrc = $object->origin_object;
}
}