From 9535baf6d2ebb4fbb02c533b59da5afc5c066a15 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 9 Jan 2025 18:33:26 +0100 Subject: [PATCH 1/2] Fix : getRights has been replaced by loadRights in V20 --- dev/initdata/generate-invoice.php | 2 +- dev/initdata/generate-order.php | 2 +- dev/initdata/generate-proposal.php | 2 +- test/phpunit/SupplierProposalTest.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dev/initdata/generate-invoice.php b/dev/initdata/generate-invoice.php index 3f4a701b0c4..2cd9ecbcae5 100755 --- a/dev/initdata/generate-invoice.php +++ b/dev/initdata/generate-invoice.php @@ -150,7 +150,7 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0) { $fuser = new User($db); $fuser->fetch(mt_rand(1, 2)); - $fuser->getRights(); + $fuser->loadRights(); $result=$object->create($fuser); if ($result >= 0) { diff --git a/dev/initdata/generate-order.php b/dev/initdata/generate-order.php index fc110907ce5..c08675468c1 100755 --- a/dev/initdata/generate-order.php +++ b/dev/initdata/generate-order.php @@ -180,7 +180,7 @@ for ($s = 0; $s < GEN_NUMBER_COMMANDE; $s++) { $fuser = new User($db); $fuser->fetch($listofuserid[mt_rand(0, 2)]); - $fuser->getRights(); + $fuser->loadRights(); $db->begin(); diff --git a/dev/initdata/generate-proposal.php b/dev/initdata/generate-proposal.php index 59298a44e69..7d7f5f59161 100755 --- a/dev/initdata/generate-proposal.php +++ b/dev/initdata/generate-proposal.php @@ -171,7 +171,7 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0) { $fuser = new User($db); $fuser->fetch(mt_rand(1, 2)); - $fuser->getRights(); + $fuser->loadRights(); $object->contactid = $contids[$socids[$socid]][0]; $object->socid = $socids[$socid]; diff --git a/test/phpunit/SupplierProposalTest.php b/test/phpunit/SupplierProposalTest.php index 437857d8381..213938f4a38 100644 --- a/test/phpunit/SupplierProposalTest.php +++ b/test/phpunit/SupplierProposalTest.php @@ -88,7 +88,7 @@ class SupplierProposalTest extends CommonClassTest // Set permission not set by default sql sample $user->addrights(0, 'supplier_proposal'); - $user->getrights('supplier_proposal', 1); + $user->loadRights('supplier_proposal', 1); } /** @@ -183,7 +183,7 @@ class SupplierProposalTest extends CommonClassTest $result = $user->addrights(0, 'supplier_proposal'); $this->assertLessThan($result, 0); - $result = $user->getrights('supplier_proposal', 1); + $result = $user->loadRights('supplier_proposal', 1); //$this->assertLessThan($result, 0); $result = $localobject->valid($user); From ba2dab2a443bb0b1e94780aaf524d4ce1b22cec3 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 10 Jan 2025 16:56:14 +0100 Subject: [PATCH 2/2] =?UTF-8?q?NEW=20:=20auto-detect=20country=20from=20co?= =?UTF-8?q?de=20in=20creation=09(follow-up=E2=81=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/adherents/class/adherent.class.php | 5 +++++ htdocs/compta/bank/class/account.class.php | 10 ++++++++++ htdocs/contact/class/contact.class.php | 5 +++++ htdocs/product/class/product.class.php | 4 ++++ htdocs/product/stock/class/entrepot.class.php | 9 +++++++++ htdocs/societe/class/societe.class.php | 10 +++++----- htdocs/user/class/user.class.php | 5 +++++ 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 0e168adddb2..78d9e15da87 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -761,6 +761,11 @@ class Adherent extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } + $nbrowsaffected = 0; $error = 0; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index d3d0c3c2ddf..45a30fdef82 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -760,6 +760,11 @@ class Account extends CommonObject $this->status = $this->clos; } + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } + // Load the library to validate/check a BAN account require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; @@ -900,6 +905,11 @@ class Account extends CommonObject { global $langs, $conf; + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } + $error = 0; $this->db->begin(); diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index f6acb419e47..83693e150ae 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -605,6 +605,11 @@ class Contact extends CommonObject { global $conf; + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } + $error = 0; $this->id = $id; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 0862b6b1d93..bc6f1df89f2 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1423,6 +1423,10 @@ class Product extends CommonObject if (empty($this->country_id)) { $this->country_id = 0; } + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } if (empty($this->state_id)) { $this->state_id = 0; diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 3ca48bbd39d..76ddc84ecfb 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -255,6 +255,10 @@ class Entrepot extends CommonObject $this->error = "ErrorFieldRequired"; return 0; } + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } $now = dol_now(); @@ -325,6 +329,11 @@ class Entrepot extends CommonObject */ public function update($id, $user, $notrigger = 0) { + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } + $error = 0; if (empty($id)) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1d7278399d1..26ec7f44992 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1010,11 +1010,6 @@ class Societe extends CommonObject $this->fk_multicurrency = 0; } - if (empty($this->country_id) && !empty($this->country_code)) { - $country_id = getCountry($this->country_code, '3'); - $this->country_id = is_int($country_id) ? $country_id : 0; - } - dol_syslog(get_class($this)."::create ".$this->name); $now = dol_now(); @@ -1441,6 +1436,11 @@ class Societe extends CommonObject $id = $this->id; } + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } + $error = 0; dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 1ea16d01c17..549bbb4454d 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2096,6 +2096,11 @@ class User extends CommonObject { global $conf, $langs; + if (empty($this->country_id) && !empty($this->country_code)) { + $country_id = getCountry($this->country_code, '3'); + $this->country_id = is_int($country_id) ? $country_id : 0; + } + $nbrowsaffected = 0; $error = 0;