Clean code and prepare database for reception from any source

This commit is contained in:
Laurent Destailleur
2023-11-14 17:30:50 +01:00
parent 0770ce640e
commit d9df238ac4
7 changed files with 46 additions and 19 deletions

View File

@@ -260,6 +260,21 @@ abstract class CommonObject
*/ */
public $origin_id; 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 * @var string The object's reference
*/ */
@@ -1870,7 +1885,9 @@ abstract class CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // 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 * @return void
*/ */
@@ -1883,15 +1900,18 @@ abstract class CommonObject
if ($this->origin == 'delivery') { if ($this->origin == 'delivery') {
$this->origin = 'livraison'; $this->origin = 'livraison';
} }
if ($this->origin == 'order_supplier') { if ($this->origin == 'order_supplier' || $this->origin == 'supplier_order') {
$this->origin = 'commandeFournisseur'; $this->origin = 'commandeFournisseur';
} }
$origin = $this->origin; $origin = $this->origin;
$classname = ucfirst($origin); $classname = ucfirst($origin);
$this->$origin = new $classname($this->db); $this->origin_object = new $classname($this->db);
$this->$origin->fetch($this->origin_id); $this->origin_object->fetch($this->origin_id);
// TODO Remove this line
$this->$origin = $this->origin_object;
} }
/** /**

View File

@@ -1755,7 +1755,8 @@ if ($action == 'create') {
$typeobject = $object->origin; $typeobject = $object->origin;
$origin = $object->origin; $origin = $object->origin;
$origin_id = $object->origin_id; $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); $soc = new Societe($db);
@@ -1768,7 +1769,7 @@ if ($action == 'create') {
$formconfirm = ''; $formconfirm = '';
// Confirm deleteion // Confirm deletion
if ($action == 'delete') { if ($action == 'delete') {
$formquestion = array(); $formquestion = array();
if ($object->statut == Expedition::STATUS_CLOSED && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { if ($object->statut == Expedition::STATUS_CLOSED && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {

View File

@@ -191,3 +191,5 @@ CREATE TABLE llx_mrp_production_extrafields
) ENGINE=innodb; ) ENGINE=innodb;
ALTER TABLE llx_mrp_production_extrafields ADD INDEX idx_mrp_production_fk_object(fk_object); 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;

View File

@@ -14,21 +14,23 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>. -- along with this program. If not, see <https://www.gnu.org/licenses/>.
-- --
-- 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 -- particular supplier order. A movement with same information is also done
-- into stock_movement so this table may be useless. -- into stock_movement so this table may be useless.
-- --
-- Detail of each lines of a reception (qty, batch and into which warehouse must be -- Detail of each lines of a reception (qty, batch and into which warehouse must be
-- received or has been receveived a purchase order line). -- 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 create table llx_commande_fournisseur_dispatch
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_product integer, fk_product integer,
fk_commande integer, fk_commande integer, -- should be renamed into fk_element
fk_commandefourndet integer, 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_projet integer DEFAULT NULL,
fk_reception integer DEFAULT NULL, fk_reception integer DEFAULT NULL,
qty float, -- qty to move qty float, -- qty to move

View File

@@ -17,6 +17,7 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>. -- along with this program. If not, see <https://www.gnu.org/licenses/>.
-- --
-- Note: a shipment is linked to an order or other object using llx_element_element table.
-- =================================================================== -- ===================================================================
create table llx_expedition 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_ext varchar(255), -- reference into an external system (not used by dolibarr)
ref_customer varchar(255), -- customer number 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_author integer, -- author of creation
fk_user_modif integer, -- author of last change fk_user_modif integer, -- author of last change
date_valid datetime, -- date de validation date_valid datetime, -- date of validation
fk_user_valid integer, -- valideur fk_user_valid integer, -- user that validate
date_delivery datetime DEFAULT NULL, -- date planned of delivery date_delivery datetime DEFAULT NULL, -- date planned of delivery
date_expedition datetime, -- not used (deprecated) date_expedition datetime, -- not used (deprecated)
fk_address integer DEFAULT NULL, -- delivery address (deprecated) fk_address integer DEFAULT NULL, -- delivery address (deprecated)

View File

@@ -17,6 +17,7 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>. -- along with this program. If not, see <https://www.gnu.org/licenses/>.
-- --
-- Note: a reception is linked to a supplier order or other object using llx_element_element table.
-- =================================================================== -- ===================================================================
create table llx_reception create table llx_reception
@@ -29,7 +30,7 @@ create table llx_reception
fk_projet integer DEFAULT NULL, fk_projet integer DEFAULT NULL,
ref_ext varchar(30), -- reference into an external system (not used by dolibarr) 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 date_creation datetime, -- date de creation
fk_user_author integer, -- author of creation fk_user_author integer, -- author of creation

View File

@@ -122,6 +122,7 @@ if ($id > 0 || !empty($ref)) {
$object->fetch($id, $ref); $object->fetch($id, $ref);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$typeobject = '';
if (!empty($object->origin)) { if (!empty($object->origin)) {
$origin = $object->origin; $origin = $object->origin;
@@ -129,11 +130,10 @@ if ($id > 0 || !empty($ref)) {
$typeobject = $object->origin; $typeobject = $object->origin;
} }
// Linked documents // Set $origin_id and $objectsrc
if ($origin == 'order_supplier' && $object->$typeobject->id && isModEnabled("supplier_order")) { if (($origin == 'order_supplier' || $origin == 'supplier_order') && is_object($object->origin_object) && isModEnabled("supplier_order")) {
$origin_id = $object->$typeobject->id; $origin_id = $object->origin_object->id;
$objectsrc = new CommandeFournisseur($db); $objectsrc = $object->origin_object;
$objectsrc->fetch($object->$typeobject->id);
} }
} }