From 3e88db5b67f53ca326e8b8ab2f6091280a69d0b5 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 25 Oct 2024 15:16:43 +0200 Subject: [PATCH 1/6] fix(TCO): missing ticket_tco field in table object --- fields/field.constant.php | 3 +++ inc/type.class.php | 2 ++ setup.php | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fields/field.constant.php b/fields/field.constant.php index 368b4a43..7a3f1bfb 100644 --- a/fields/field.constant.php +++ b/fields/field.constant.php @@ -116,6 +116,9 @@ $GO_FIELDS['is_helpdesk_visible']['name'] = __("Associable to a ticket"); $GO_FIELDS['is_helpdesk_visible']['input_type'] = 'bool'; +$GO_FIELDS['ticket_tco']['name'] = __("TCO"); +$GO_FIELDS['ticket_tco']['input_type'] = 'decimal'; + $GO_FIELDS['locations_id']['name'] = __("Item location"); $GO_FIELDS['locations_id']['input_type'] = 'dropdown'; diff --git a/inc/type.class.php b/inc/type.class.php index 3440f398..bbcbbf8d 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -1101,6 +1101,8 @@ public function checkNecessaryFieldsUpdate() if ($this->canUseTickets()) { //TODO rename is_helpdesk_visible into is_helpdeskvisible PluginGenericobjectField::addNewField($table, 'is_helpdesk_visible', 'comment'); + PluginGenericobjectField::addNewField($table, 'ticket_tco'); + } else { PluginGenericobjectField::deleteField($table, 'is_helpdesk_visible'); } diff --git a/setup.php b/setup.php index a7efcbd5..d6927a61 100644 --- a/setup.php +++ b/setup.php @@ -117,12 +117,12 @@ function plugin_init_genericobject() global $PLUGIN_HOOKS, $GO_BLACKLIST_FIELDS, $GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS, $CFG_GLPI; - $GO_READONLY_FIELDS = ["is_helpdesk_visible", "comment"]; + $GO_READONLY_FIELDS = ["is_helpdesk_visible", "comment", "ticket_tco"]; $GO_BLACKLIST_FIELDS = ["itemtype", "table", "is_deleted", "id", "entities_id", "is_recursive", "is_template", "notepad", "template_name", "date_mod", "name", "is_helpdesk_visible", "comment", - "date_creation" + "date_creation", "ticket_tco" ]; $GO_LINKED_TYPES = ['Computer', 'Phone', 'Peripheral', 'Software', 'Monitor', From 509a7bdbaca41a5d9d65c09d65a04be009130f09 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 29 Nov 2024 09:46:25 +0100 Subject: [PATCH 2/6] fix: remove TCO field in object form --- inc/object.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/object.class.php b/inc/object.class.php index 94e9a585..2f6dca20 100644 --- a/inc/object.class.php +++ b/inc/object.class.php @@ -638,7 +638,7 @@ public function showForm($id, $options = [], $previsualisation = false) public static function getFieldsToHide() { return ['id', 'is_recursive', 'is_template', 'template_name', 'is_deleted', - 'entities_id', 'notepad', 'date_mod', 'date_creation' + 'entities_id', 'notepad', 'date_mod', 'date_creation', 'ticket_tco' ]; } From 8fd605a0346882fe213a5a8c037569591f4161bb Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 26 Dec 2024 12:48:32 +0100 Subject: [PATCH 3/6] fix lint --- inc/type.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/type.class.php b/inc/type.class.php index bbcbbf8d..30feb214 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -1102,7 +1102,6 @@ public function checkNecessaryFieldsUpdate() //TODO rename is_helpdesk_visible into is_helpdeskvisible PluginGenericobjectField::addNewField($table, 'is_helpdesk_visible', 'comment'); PluginGenericobjectField::addNewField($table, 'ticket_tco'); - } else { PluginGenericobjectField::deleteField($table, 'is_helpdesk_visible'); } From f0720ecd68a4d7a112b20412706dbec0cbb15ea9 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 15 Jan 2025 09:55:01 +0100 Subject: [PATCH 4/6] add migration infocoms --- inc/type.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inc/type.class.php b/inc/type.class.php index 30feb214..71b8147a 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -2486,6 +2486,13 @@ public static function install(Migration $migration) $preference->add($tmp); } } + + $types = new self(); + $object_use_infocoms = $types->getFromDBByCrit(['use_infocoms' => 1]); + foreach ($object_use_infocoms as $object) { + $object_table = $object->getTable(); + $migration->addField($object_table, "ticket_tco", "decimal"); + } } From 5875626155466128d83650dbeb35a6c866c8a851 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 15 Jan 2025 10:43:45 +0100 Subject: [PATCH 5/6] fix migration --- inc/type.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inc/type.class.php b/inc/type.class.php index 71b8147a..ed6d3790 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -2488,10 +2488,11 @@ public static function install(Migration $migration) } $types = new self(); - $object_use_infocoms = $types->getFromDBByCrit(['use_infocoms' => 1]); + $object_use_infocoms = $types->find(['use_infocoms' => 1]); foreach ($object_use_infocoms as $object) { - $object_table = $object->getTable(); + $object_table = $object['itemtype']::getTable(); $migration->addField($object_table, "ticket_tco", "decimal"); + $migration->migrationOneTable($object_table); } } From 05455ce3876efdfb927a18a228578acb7f285787 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 27 Feb 2025 11:07:59 +0100 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f279b483..21137a3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Improve global performance when using many genericobject +- The `TCO` (Total Cost of Ownership) is now correctly updated based on the costs associated with an item. ## [2.14.11] - 2024-12-27