diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php
index 936e20e25d3..8dfad632335 100644
--- a/htdocs/bom/class/bom.class.php
+++ b/htdocs/bom/class/bom.class.php
@@ -432,7 +432,6 @@ class BOM extends CommonObject
* Load object lines in memory from the database by type of product
*
* @param int<0,1> $typeproduct 0 type product, 1 type service
- *
* @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK
*/
public function fetchLinesbytypeproduct($typeproduct = 0)
@@ -469,6 +468,11 @@ class BOM extends CommonObject
'@phan-var-force BOMLine $newline';
$newline->setVarsFromFetchObj($obj);
+ // Load also extrafields for the line
+ //if (empty($noextrafields)) {
+ $newline->fetch_optionals();
+ //}
+
$this->lines[] = $newline;
}
$i++;
diff --git a/htdocs/bom/lib/bom.lib.php b/htdocs/bom/lib/bom.lib.php
index 360e6a868ff..57828cfc798 100644
--- a/htdocs/bom/lib/bom.lib.php
+++ b/htdocs/bom/lib/bom.lib.php
@@ -32,6 +32,11 @@ function bomAdminPrepareHead()
{
global $langs, $conf;
+ global $db;
+ $extrafields = new ExtraFields($db);
+ $extrafields->fetch_name_optionals_label('bom_bom');
+ $extrafields->fetch_name_optionals_label('bom_bomline');
+
$langs->load("mrp");
$h = 0;
@@ -44,11 +49,19 @@ function bomAdminPrepareHead()
$head[$h][0] = DOL_URL_ROOT."/admin/bom_extrafields.php";
$head[$h][1] = $langs->trans("ExtraFields");
+ $nbExtrafields = is_countable($extrafields->attributes['bom_bom']['label']) ? count($extrafields->attributes['bom_bom']['label']) : 0;
+ if ($nbExtrafields > 0) {
+ $head[$h][1] .= '' . $nbExtrafields . '';
+ }
$head[$h][2] = 'bom_extrafields';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php";
$head[$h][1] = $langs->trans("ExtraFieldsLines");
+ $nbExtrafields = is_countable($extrafields->attributes['bom_bomline']['label']) ? count($extrafields->attributes['bom_bomline']['label']) : 0;
+ if ($nbExtrafields > 0) {
+ $head[$h][1] .= '' . $nbExtrafields . '';
+ }
$head[$h][2] = 'bomline_extrafields';
$h++;
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 9efa79bcf33..3a61269e81c 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -5354,8 +5354,8 @@ abstract class CommonObject
print "\n";
foreach ($this->lines as $line) {
- //Line extrafield
- $line->fetch_optionals();
+ // Line extrafield. TODO Remove this. extrafields should be already loaded.
+ //$line->fetch_optionals();
if (is_object($hookmanager)) {
if (empty($line->fk_parent_line)) {
@@ -5366,7 +5366,7 @@ abstract class CommonObject
$reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
}
- if (empty($reshook) && $buyer !== null) {
+ if (empty($reshook)) {
$this->printObjectLine($action, $line, '', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
}
@@ -5387,7 +5387,7 @@ abstract class CommonObject
* @param int $i I
* @param int $dateSelector 1=Show also date range input fields
* @param Societe $seller Object of seller third party
- * @param Societe $buyer Object of buyer third party
+ * @param ?Societe $buyer Object of buyer third party
* @param int $selected ID line selected
* @param ?ExtraFields $extrafields Object of extrafields
* @param string $defaulttpldir Directory where to find the template (deprecated)
@@ -6348,7 +6348,6 @@ abstract class CommonObject
$sql .= " WHERE type_object = '".$this->db->escape($element)."'";
$sql .= " AND fk_object = ".((int) $this->id);
- //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose
$resql = $this->db->query($sql);
if ($resql) {
$numrows = $this->db->num_rows($resql);
@@ -10716,11 +10715,10 @@ abstract class CommonObject
'@phan-var-force CommonObjectLine $newline';
$newline->setVarsFromFetchObj($obj);
- // Note: extrafields load of line not yet supported
- /*
- if (empty($noextrafields)) {
- // Load extrafields of line
- }*/
+ // Load also extrafields for the line
+ if (empty($noextrafields)) {
+ $newline->fetch_optionals();
+ }
$this->lines[] = $newline;
}
diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php
index 1cc807a21e6..ea63be80aea 100644
--- a/htdocs/core/class/commonobjectline.class.php
+++ b/htdocs/core/class/commonobjectline.class.php
@@ -1,8 +1,8 @@
* Copyright (C) 2012 Cedric Salvador
- * Copyright (C) 2024-2025 MDW
- * Copyright (C) 2024 Frédéric France
+ * Copyright (C) 2024-2025 MDW
+ * Copyright (C) 2024 Frédéric France
*
* 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
diff --git a/htdocs/modulebuilder/template/lib/mymodule.lib.php b/htdocs/modulebuilder/template/lib/mymodule.lib.php
index d432a35b4af..e03a8b962a2 100644
--- a/htdocs/modulebuilder/template/lib/mymodule.lib.php
+++ b/htdocs/modulebuilder/template/lib/mymodule.lib.php
@@ -49,10 +49,19 @@ function mymoduleAdminPrepareHead()
$head[$h][1] = $langs->trans("ExtraFields");
$nbExtrafields = is_countable($extrafields->attributes['myobject']['label']) ? count($extrafields->attributes['myobject']['label']) : 0;
if ($nbExtrafields > 0) {
- $head[$h][1] .= ' ' . $nbExtrafields . '';
+ $head[$h][1] .= '' . $nbExtrafields . '';
}
$head[$h][2] = 'myobject_extrafields';
$h++;
+
+ $head[$h][0] = dol_buildpath("/mymodule/admin/myobjectline_extrafields.php", 1);
+ $head[$h][1] = $langs->trans("ExtraFieldsLines");
+ $nbExtrafields = is_countable($extrafields->attributes['myobjectline']['label']) ? count($extrafields->attributes['myobject']['label']) : 0;
+ if ($nbExtrafields > 0) {
+ $head[$h][1] .= '' . $nbExtrafields . '';
+ }
+ $head[$h][2] = 'myobject_extrafieldsline';
+ $h++;
*/
$head[$h][0] = dol_buildpath("/mymodule/admin/about.php", 1);