From ad73f9d8799a8d021256f5c66fcf0d1a5d207ccb Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 19 Jul 2026 22:31:25 +0700 Subject: [PATCH 1/8] Fix #39020 avoid duplicate MO when BOM has a sub-BOM (#39163) * Fix #39020 avoid duplicate MO when BOM has a sub-BOM When generating child MOs from a BOM with a sub-BOM line, the lookup of the parent MO consume line used a substring filter (origin_id LIKE '%id%') that was not scoped to the parent MO. It could match an unrelated mrp_production row or none at all. When it matched none, the child MO was still created from the leftover parent POST data, producing a second MO identical to the parent instead of a real child. Scope the lookup to the parent MO with an exact match on origin_id and origin_type via customsql, and skip the iteration when no matching consume line is found so no duplicate parent MO can be created. Signed-off-by: Dolicraft * Fix #39020 use exact-match filter keys instead of customsql per review Add exact-match handling for fk_mo, origin_id and origin_type in MoLine::fetchAll and call it with those keys instead of a customsql clause, so the lookup stays valid on 18.0/19.0 where customsql would be the only alternative to the buggy LIKE. The universal-search filter form is handled separately on 20.0 and later. Signed-off-by: Dolicraft --------- Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/mrp/class/mo.class.php | 4 +++- htdocs/mrp/mo_card.php | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index b1cf985e4f3..d6eacf8b1a4 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -1923,8 +1923,10 @@ class MoLine extends CommonObjectLine $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { - if ($key == 't.rowid') { + if ($key == 't.rowid' || $key == 'fk_mo' || $key == 'origin_id') { $sqlwhere[] = $key." = ".((int) $value); + } elseif ($key == 'origin_type') { + $sqlwhere[] = $key." = '".$this->db->escape($value)."'"; } elseif (strpos($key, 'date') !== false) { $sqlwhere[] = $key." = '".$this->db->idate($value)."'"; } elseif ($key == 'customsql') { diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 6d66e835174..f71afd103ed 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -154,7 +154,15 @@ if (empty($reshook)) { $objectbomchildline->fetch($id_bom_line); - $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line)); + // Find the consume line of the parent MO generated from this BOM line. + // The lookup must be scoped to the parent MO and use an exact match on origin_id/origin_type, + // otherwise the default 'origin_id LIKE %..%' filter can return an unrelated line (or none), + // which would let the child MO be created from the leftover parent POST data (duplicate MO). + $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('fk_mo' => $mo_parent->id, 'origin_id' => $id_bom_line, 'origin_type' => 'bomline')); + + if (empty($TMoLines)) { + continue; + } foreach ($TMoLines as $tmpmoline) { $_POST['fk_bom'] = $objectbomchildline->fk_bom_child; From a270e0852b647065467fd220404191d239a13fb0 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Mon, 20 Jul 2026 09:53:33 +0900 Subject: [PATCH 2/8] FIX #39190 wrong unit price when invoicing time spent with one line per declaration (#39215) * FIX #39190 wrong unit price when invoicing time spent with one line per declaration In projet/tasks/time.php, the 'onelineperperiod' mode (invoice generation option "One line for each time spent declaration") computed the unit price as $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU'); but totalvaluetodivideby3600 is timespent_duration (seconds) * timespent_thm (hourly rate), so dividing by 3600 yields "hours * hourly rate", which is the line total and not a unit price. The quantity passed to addline() is the number of hours, so the line was billed hours * (hours * rate) instead of hours * rate: the time is over-billed by a factor equal to the number of hours. The sibling modes are already correct: 'onelineperuser' and 'onelinepertask' divide by the recorded number of seconds. Up to 16.0 'onelineperuser' had the same /3600 expression; it was fixed there and 'onelineperperiod' was left behind. Align it with that reference implementation, including the same guard against a zero duration. Also reset $pu_ht for each generated line. $pu_ht is initialized once before the loops (with the price of the selected product/service, or 0) and this mode only had an "if (empty($pu_ht))" test, so once a price was computed for the first line every following line reused it, and lines of users with a different hourly rate got the rate of the first line. The base price is saved before the loop and restored on each iteration, so the product/service price path is preserved. * Rename variable for clarity in time.php --------- Co-authored-by: Laurent Destailleur --- htdocs/projet/tasks/time.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 4f3b1395704..ab6d96bf512 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -616,7 +616,9 @@ if ($action == 'confirm_generateinvoice') { $arrayoftasks[$object->timespent_id]['fk_product'] = $object->timespent_fk_product; } + $pu_ht_saved = $pu_ht; // Save the base unit price (price of the selected product/service if any, 0 otherwise) foreach ($arrayoftasks as $timespent_id => $value) { + $pu_ht = $pu_ht_saved; // Reset for each line, so a line does not inherit the unit price computed for the previous one $userid = $value['user']; //$pu_ht = $value['timespent'] * $fuser->thm; @@ -625,7 +627,9 @@ if ($action == 'confirm_generateinvoice') { // If no unit price known if (empty($pu_ht)) { - $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU'); + if ($value['timespent']) { + $pu_ht = price2num(($value['totalvaluetodivideby3600'] / $value['timespent']), 'MU'); + } } // Add lines From 797312579bef01cec9a67b5dab026ecb683c1286 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Mon, 20 Jul 2026 22:30:28 +0900 Subject: [PATCH 3/8] FIX isInt() does not detect sized integer types (tinyint, bigint) (#39236) CommonObject::isInt() decides whether a list-page column gets numeric search mode and is also used when resolving $this->id. The regex /(^int|int$)/ missed sized integer types such as tinyint(4) and bigint(20): they neither start nor end with "int". These types are not exotic: tinyint(4) is used in several core $fields definitions (societe, contact, entrepot, companypaymentmode, ...) and ModuleBuilder-generated tables use bigint(20) for rowid, so isInt() should recognise them rather than requiring callers to change the column type. The new regex /^(?:tiny|small|medium|big)?int|int$/ also handles smallint/mediumint with a size. Anchoring is preserved on purpose so that strings which merely contain "int" (e.g. sellist:Table:...) are still NOT matched, while the Dolibarr foreign-key syntax "integer:Class:path" keeps being detected. Signed-off-by: Jam Balaya --- htdocs/core/class/commonobject.class.php | 2 +- test/phpunit/CommonObjectTest.php | 34 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1da7bc7eb97..c048c968545 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -10059,7 +10059,7 @@ abstract class CommonObject public function isInt($info) { if (is_array($info)) { - if (isset($info['type']) && (preg_match('/(^int|int$)/i', $info['type']))) { + if (isset($info['type']) && (preg_match('/^(?:tiny|small|medium|big)?int|int$/i', $info['type']))) { return true; } else { return false; diff --git a/test/phpunit/CommonObjectTest.php b/test/phpunit/CommonObjectTest.php index 49f63efddc7..2e8e4da47d7 100644 --- a/test/phpunit/CommonObjectTest.php +++ b/test/phpunit/CommonObjectTest.php @@ -117,4 +117,38 @@ class CommonObjectTest extends CommonClassTest $this->assertLessThanOrEqual($result, 0); return $result; } + + /** + * testIsInt + * + * @return void + */ + public function testIsInt() + { + global $conf,$user,$langs,$db; + $conf = $this->savconf; + $user = $this->savuser; + $langs = $this->savlangs; + $db = $this->savdb; + + $localobject = new Commande($db); + + // Integer types, with or without a size/unsigned suffix, must be detected. + $this->assertTrue($localobject->isInt(array('type' => 'int')), 'int'); + $this->assertTrue($localobject->isInt(array('type' => 'int(11)')), 'int(11)'); + $this->assertTrue($localobject->isInt(array('type' => 'integer')), 'integer'); + $this->assertTrue($localobject->isInt(array('type' => 'tinyint(4)')), 'tinyint(4)'); + $this->assertTrue($localobject->isInt(array('type' => 'smallint(6)')), 'smallint(6)'); + $this->assertTrue($localobject->isInt(array('type' => 'bigint(20)')), 'bigint(20)'); + // Dolibarr foreign-key column syntax "integer:Class:path" must keep being detected. + $this->assertTrue($localobject->isInt(array('type' => 'integer:User:user/class/user.class.php')), 'integer:User:...'); + + // Non-integer types must not be detected, including strings that merely contain "int". + $this->assertFalse($localobject->isInt(array('type' => 'varchar(255)')), 'varchar(255)'); + $this->assertFalse($localobject->isInt(array('type' => 'double(24,8)')), 'double(24,8)'); + $this->assertFalse($localobject->isInt(array('type' => 'date')), 'date'); + $this->assertFalse($localobject->isInt(array('type' => 'sellist:llx_c_typent:libelle:id')), 'sellist:...'); + + print __METHOD__." OK\n"; + } } From 136be3c1968cd43dc658c3860da82697a2bffeb9 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Wed, 22 Jul 2026 03:31:00 +0900 Subject: [PATCH 4/8] FIX #34667 checkUserAccessToObject: skip entity check for non-multientity objects (multicompany) (#39246) When the multicompany module is enabled, checkUserAccessToObject() (used by restrictedArea(), e.g. from an ajax tooltip) ran the entity check unconditionally in its default/custom-object branch, building "AND dbt.entity IN (...)". For a custom object whose table has no entity column (ismultientitymanaged = 0), that SQL fails, nb comes back 0 and access is wrongly denied. Guard the branch so the entity test only runs when the object is actually multi-entity managed. Keep the test for legacy classes that never define ismultientitymanaged (null/unset) and for a non-object $object, and skip it only when a class explicitly sets ismultientitymanaged = 0. Supersedes the stale #34667 (by @jyhere) and applies the condition requested by @eldy in its review. Co-authored-by: Claude Opus 4.8 --- htdocs/core/lib/security.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 15c8baec1bf..8c00a057fac 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -1187,7 +1187,7 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")"; $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR sc.fk_user IS NULL)"; } - } elseif (isModEnabled('multicompany')) { + } elseif (isModEnabled('multicompany') && (!empty($object->ismultientitymanaged) || !isset($object->ismultientitymanaged))) { // If multicompany, and user is an internal user with all permissions, check that object is in correct entity $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb"; $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt"; From ed47b61151645dd7ccae0c5ecc1e4b10fb8386d4 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Wed, 22 Jul 2026 10:35:51 +0900 Subject: [PATCH 5/8] FIX mo_production: show very-short unit label instead of untranslated 'UnitPShort' (#39253) The "Unit" column of the consume/produce tables used measuringUnitString(..., 2), which translates a