Merge pull request #32622 from atm-maxime/new_detect_country_code2

NEW : auto-detect country from code in creation	(follow-up⁾
This commit is contained in:
Laurent Destailleur 2025-01-21 08:33:16 +01:00 committed by GitHub
commit 87333363d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 43 additions and 5 deletions

View File

@ -763,6 +763,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;

View File

@ -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();

View File

@ -607,6 +607,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;

View File

@ -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;

View File

@ -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)) {

View File

@ -1012,11 +1012,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();
@ -1446,6 +1441,11 @@ class Societe extends CommonObject
$this->country_id = dol_getIdFromCode($this->db, $this->country_code, 'c_country', 'code', 'rowid');
}
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);

View File

@ -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;