diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index f73f6ab1eb6..85dc4f2cbf1 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2223,6 +2223,12 @@ if (empty($reshook)) { $object->situation_counter += 1; + // Set extrafields from the create form BEFORE createFromCurrent(), so they are already + // present when create() inserts them and fires the BILL_CREATE trigger. This avoids firing + // BILL_CREATE a second time just to expose the extrafields (#32217). + $extrafields->fetch_name_optionals_label($object->table_element); + $extrafields->setOptionalsFromPost(null, $object); + $id = $object->createFromCurrent($user); if ($id <= 0) { $mesg = $object->error; @@ -2230,13 +2236,6 @@ if (empty($reshook)) { $nextSituationInvoice = new Facture($db); $nextSituationInvoice->fetch($id); - // create extrafields with data from create form - $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element); - $ret = $extrafields->setOptionalsFromPost(null, $nextSituationInvoice); - if ($ret > 0) { - $nextSituationInvoice->insertExtraFields(); - } - // Hooks $parameters = array('origin_type' => $object->origin_type, 'origin_id' => $object->origin_id); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $nextSituationInvoice, $action); // Note that $action and $object may have been diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index cd146bc69b4..a42f9585221 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1171,7 +1171,10 @@ class Facture extends CommonInvoice // Retrieve all extrafield // fetch optionals attributes and labels - $this->fetch_optionals(); + // (unless the caller already set array_options, e.g. from a create form, so we don't overwrite them) + if (empty($this->array_options)) { + $this->fetch_optionals(); + } if (!empty($this->array_options)) { $facture->array_options = $this->array_options; diff --git a/htdocs/contrat/class/contratligne.class.php b/htdocs/contrat/class/contratligne.class.php index 7815f701dd6..fa29de19cb4 100644 --- a/htdocs/contrat/class/contratligne.class.php +++ b/htdocs/contrat/class/contratligne.class.php @@ -526,8 +526,8 @@ class ContratLigne extends CommonObjectLine $this->ref = $obj->rowid; $this->tms = $this->db->jdate($obj->tms); - $this->fk_contrat = $obj->fk_contrat; - $this->fk_product = $obj->fk_product; + $this->fk_contrat = (int) $obj->fk_contrat; + $this->fk_product = (int) $obj->fk_product; $this->statut = $obj->statut; $this->product_ref = $obj->product_ref; $this->product_label = $obj->product_label; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 914727a5053..5a668879cb2 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -10185,7 +10185,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/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index ae863fd2104..c2051952c10 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -1191,7 +1191,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"; diff --git a/htdocs/mrp/class/moline.class.php b/htdocs/mrp/class/moline.class.php index 832c341ee98..8103d96ff52 100644 --- a/htdocs/mrp/class/moline.class.php +++ b/htdocs/mrp/class/moline.class.php @@ -298,8 +298,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[] = $this->db->sanitize($key)." = ".((int) $value); + } elseif ($key == 'origin_type') { + $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'"; } elseif (strpos($key, 'date') !== false) { $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate((int) $value)."'"; } else { diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 606108a5c32..f0e8aa75e96 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -170,7 +170,15 @@ if (empty($reshook)) { $objectbomchildline->fetch($id_bom_line); - $TMoLines = $moline->fetchAll('DESC', 'rowid', 1, 0, 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, 0, 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; diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 1a69a080a33..6ca6fa3e46d 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -621,7 +621,9 @@ if ($action == 'confirm_generateinvoice' && $user->hasRight('facture', 'creer')) $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; @@ -630,7 +632,9 @@ if ($action == 'confirm_generateinvoice' && $user->hasRight('facture', 'creer')) // 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 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"; + } }