From 729a8017c32419ddb177216f8999c7160123af37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Fri, 11 Jan 2013 17:13:37 +0100 Subject: [PATCH 1/5] Added test for Adherent class functions setUserId and setThirdPartyId --- test/phpunit/AdherentTest.php | 103 ++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 5 deletions(-) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index e6ed5ebdddb..1a613fe4845 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -139,7 +139,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase /** * testAdherentFetch * - * @param int $id Id of object to fecth + * @param int $id Id of object to fetch * @return object Fetched object * * @depends testAdherentCreate @@ -225,6 +225,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase $this->assertEquals($localobject->town, $newobject->town); $this->assertEquals($localobject->country_id, $newobject->country_id); $this->assertEquals('BE', $newobject->country_code); + $this->assertEquals('Belgium', $newobject->country); $this->assertEquals($localobject->statut, $newobject->statut); $this->assertEquals($localobject->phone, $newobject->phone); $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); @@ -233,7 +234,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase $this->assertEquals($localobject->naiss, $timestamp); $this->assertEquals($localobject->morphy, $newobject->morphy); - return $localobject; + //We return newobject because of new values + return $newobject; } /** @@ -258,8 +260,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase '%NOM%,%SOCIETE%,%ADRESSE%,%CP%,%VILLE%,%PAYS%'; $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',0,New firstname,New name,New firstname New name,'. - 'New company,New address,New zip,New town,,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'. - 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,'; + 'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'. + 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium'; $result = $localobject->makeSubstitution($template); print __METHOD__." result=".$result."\n"; @@ -268,13 +270,104 @@ class AdherentTest extends PHPUnit_Framework_TestCase return $localobject; } + /** + * testAdherentSetUserId + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentMakeSubstitution + * The depends says test is run only if previous is ok + */ + public function testAdherentSetUserId(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //We associate member with user + $result = $localobject->setUserId($user->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); + + //We update user object + $user->fetch($user->id); + print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; + + $this->assertEquals($user->fk_member, $localobject->id); + + //We remove association with user + $result = $localobject->setUserId(0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); + + //We update user object + $user->fetch($user->id); + print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; + + $this->assertNull($user->fk_member); + + return $localobject; + } + + /** + * testAdherentSetThirdPartyId + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentSetUserId + * The depends says test is run only if previous is ok + */ + public function testAdherentSetThirdPartyId(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //Create a Third Party + $thirdparty = new Societe($db); + $thirdparty->initAsSpecimen(); + $result = $thirdparty->create($user); + print __METHOD__." id=".$localobject->id." third party id=".$thirdparty->id." result=".$result."\n"; + $this->assertTrue($result > 0); + + //Set Third Party ID + $result = $localobject->setThirdPartyId($thirdparty->id); + $this->assertEquals($result, 1); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + + //Adherent is updated with new data + $localobject->fetch($localobject->id); + $this->assertEquals($localobject->fk_soc, $thirdparty->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + + //We remove the third party association + $result = $localobject->setThirdPartyId(0); + $this->assertEquals($result, 1); + + //And check if it has been updated + $localobject->fetch($localobject->id); + $this->assertNull($localobject->fk_soc); + + //Now we remove the third party + $result = $thirdparty->delete($thirdparty->id); + $this->assertEquals($result, 1); + + return $localobject; + } + /** * testAdherentValid * * @param Adherent $localobject Member instance * @return Adherent * - * @depends testAdherentMakeSubstitution + * @depends testAdherentSetThirdPartyId * The depends says test is run only if previous is ok */ public function testAdherentValid(Adherent $localobject) From 96c5eacf4aa669786b90b4ce6c6930a5dda8fd1b Mon Sep 17 00:00:00 2001 From: simnandez Date: Sat, 12 Jan 2013 09:58:21 +0100 Subject: [PATCH 2/5] [ task #652 ] Reduce clicks into creaton of orders, invoices, etc. --- htdocs/compta/facture.php | 164 +++++++++++++----------- htdocs/core/menus/standard/eldy.lib.php | 4 +- 2 files changed, 92 insertions(+), 76 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 75a67be6bff..adecacd40ef 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -5,7 +5,7 @@ * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010-2012 Juanjo Menent + * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2012 Christophe Battarel * * This program is free software; you can redistribute it and/or modify @@ -1804,7 +1804,7 @@ if ($action == 'create') print ''.$langs->trans('Ref').''.$langs->trans('Draft').''; // Factures predefinies - if (empty($origin) && empty($originid)) + if (empty($origin) && empty($originid) && $socid) { $sql = 'SELECT r.rowid, r.titre, r.total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as r'; @@ -1834,16 +1834,27 @@ if ($action == 'create') $db->free($resql); } else - { + { dol_print_error($db); } } // Tiers - print ''.$langs->trans('Customer').''; - print $soc->getNomUrl(1); - print ''; - print ''; + print ''; + print ''.$langs->trans('Customer').''; + if($socid) + { + print ''; + print $soc->getNomUrl(1); + print ''; + print ''; + } + else + { + print ''; + print $form->select_company('','socid','s.client = 1',1); + print ''; + } print ''."\n"; // Type de facture @@ -1916,72 +1927,77 @@ if ($action == 'create') print $desc; print ''."\n"; } - - // Replacement - print ''; - print ''; - print ''; - $text=$langs->trans("InvoiceReplacementAsk").' '; - $text.=''; - $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1); - print $desc; - print ''."\n"; - - // Credit note - print ''; - print ''; - print ''; - $text=$langs->transnoentities("InvoiceAvoirAsk").' '; - // $text.=''; - $text.=''; - $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1); - print $desc; - print ''."\n"; - - print ''; - print ''; - - // Discounts for third party - print ''.$langs->trans('Discounts').''; - if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",''.$soc->remise_client.''); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - print ' ('.$langs->trans("EditRelativeDiscount").')'; - print '. '; - print '
'; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",''.price($absolute_discount).'',$langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print ' ('.$langs->trans("EditGlobalDiscounts").')'; - print '.'; - print ''; - + + if ($socid) + { + // Replacement + print ''; + print ''; + print ''; + $text=$langs->trans("InvoiceReplacementAsk").' '; + $text.=''; + $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1); + print $desc; + print ''."\n"; + + // Credit note + print ''; + print ''; + print ''; + $text=$langs->transnoentities("InvoiceAvoirAsk").' '; + // $text.=''; + $text.=''; + $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1); + print $desc; + print ''."\n"; + } + print ''; + print ''; + + if($socid) + { + // Discounts for third party + print ''.$langs->trans('Discounts').''; + if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",''.$soc->remise_client.''); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + print ' ('.$langs->trans("EditRelativeDiscount").')'; + print '. '; + print '
'; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",''.price($absolute_discount).'',$langs->trans("Currency".$conf->currency)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print ' ('.$langs->trans("EditGlobalDiscounts").')'; + print '.'; + print ''; + } + // Date invoice print ''.$langs->trans('Date').''; $form->select_date($dateinvoice,'','','','',"add",1,1); @@ -1998,7 +2014,7 @@ if ($action == 'create') print ''; // Project - if (! empty($conf->projet->enabled)) + if (! empty($conf->projet->enabled) && $socid) { $langs->load('projects'); print ''.$langs->trans('Project').''; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 7fdff999410..51e61dfb6c9 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1,7 +1,7 @@ * Copyright (C) 2010 Regis Houssin - * Copyright (C) 2012 Juanjo Menent + * Copyright (C) 2012-2013 Juanjo Menent * * 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 @@ -913,7 +913,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after) $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("BillsCustomers"),0,$user->rights->facture->lire, '', $mainmenu, 'customers_bills'); if (empty($user->societe_id)) { - $newmenu->add("/compta/clients.php?action=facturer&leftmenu=customers_bills",$langs->trans("NewBill"),1,$user->rights->facture->creer); + $newmenu->add("/compta/facture.php?action=create&leftmenu=customers_bills",$langs->trans("NewBill"),1,$user->rights->facture->creer); } $newmenu->add("/compta/facture/fiche-rec.php?leftmenu=customers_bills",$langs->trans("Repeatables"),1,$user->rights->facture->lire); From d39368fd369bd23ea5ffad6703ebbcd85ac5c1b6 Mon Sep 17 00:00:00 2001 From: fhenry Date: Sat, 12 Jan 2013 14:02:39 +0100 Subject: [PATCH 3/5] Add boolean (checkbox) standard extrafield feature --- htdocs/core/class/extrafields.class.php | 42 +++++++++++++++++-- htdocs/core/tpl/admin_extrafields.tpl.php | 1 + htdocs/core/tpl/admin_extrafields_add.tpl.php | 1 + .../core/tpl/admin_extrafields_edit.tpl.php | 1 + htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/fr_FR/admin.lang | 1 + 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 87e3eb5dce7..b387537165b 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -52,7 +52,8 @@ class ExtraFields 'int'=>'Int', 'double'=>'Float', 'date'=>'Date', - 'datetime'=>'DateAndTime' + 'datetime'=>'DateAndTime', + 'boolean'=>'Boolean' ); /** @@ -135,7 +136,14 @@ class ExtraFields if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $field_desc = array('type'=>$type, 'value'=>$length, 'null'=>($required?'NOT NULL':'NULL')); + if ($type=='boolean') { + $typedb='int'; + $lengthdb='1'; + } else { + $typedb=$type; + $lengthdb=$length; + } + $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL')); $result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); if ($result > 0) { @@ -304,7 +312,14 @@ class ExtraFields if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $field_desc = array('type'=>$type, 'value'=>$length, 'null'=>($required?'NOT NULL':'NULL')); + if ($type=='boolean') { + $typedb='int'; + $lengthdb='1'; + } else { + $typedb=$type; + $lengthdb=$length; + } + $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL')); $result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); if ($result > 0) { @@ -487,7 +502,7 @@ class ExtraFields function showInputField($key,$value,$moreparam='') { global $conf; - + $label=$this->attribute_label[$key]; $type =$this->attribute_type[$key]; $size =$this->attribute_size[$key]; @@ -534,6 +549,16 @@ class ExtraFields $doleditor=new DolEditor('options_'.$key,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,5,100); $out=$doleditor->Create(1); } + else if ($type == 'boolean') + { + $checked=''; + if (!empty($value)) { + $checked=' checked="checked" value="1" '; + } else { + $checked=' value="1" '; + } + $out=''; + } // Add comments if ($type == 'date') $out.=' (YYYY-MM-DD)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; @@ -550,6 +575,7 @@ class ExtraFields */ function showOutputField($key,$value,$moreparam='') { + $label=$this->attribute_label[$key]; $type=$this->attribute_type[$key]; $size=$this->attribute_size[$key]; @@ -568,6 +594,14 @@ class ExtraFields { $showsize=10; } + elseif ($type == 'boolean') + { + $checked=''; + if (!empty($value)) { + $checked=' checked="checked" '; + } + $value=''; + } else { $showsize=round($size); diff --git a/htdocs/core/tpl/admin_extrafields.tpl.php b/htdocs/core/tpl/admin_extrafields.tpl.php index d8f23a4c183..f2ce0efa59b 100644 --- a/htdocs/core/tpl/admin_extrafields.tpl.php +++ b/htdocs/core/tpl/admin_extrafields.tpl.php @@ -29,6 +29,7 @@ else if (type == 'int') { size.val('10').removeAttr('disabled'); } else if (type == 'text') { size.val('2000').removeAttr('disabled'); } else if (type == 'varchar') { size.val('255').removeAttr('disabled'); } + else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} else size.val('').attr('disabled','disabled'); } init_typeoffields(); diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index d28fe1c33b2..3215c235281 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -31,6 +31,7 @@ else if (type == 'int') { size.val('10').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } else if (type == 'text') { size.val('2000').removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); } else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } + else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} else size.val('').attr('disabled','disabled'); } init_typeoffields(''); diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index d681d7cf82c..4df48df6702 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -31,6 +31,7 @@ else if (type == 'int') { size.removeAttr('disabled'); } else if (type == 'text') { size.removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); } else if (type == 'varchar') { size.removeAttr('disabled'); } + else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');} else size.val('').attr('disabled','disabled'); } init_typeoffields(jQuery("#type").val()); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 6007be581fc..9ecda1dbcef 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -351,6 +351,7 @@ Int=Integer Float=Float DateAndTime=Date and hour Unique=Unique +Boolean=Boolean (Checkbox) LibraryToBuildPDF=Library used to build PDF WarningUsingFPDF=Warning: Your conf.php contains directive dolibarr_pdf_force_fpdf=1. This means you use the FPDF library to generate PDF files. This library is old and does not support a lot of features (Unicode, image transparency, cyrillic, arab and asiatic languages, ...), so you may experience errors during PDF generation.
To solve this and have a full support of PDF generation, please download TCPDF library, then comment or remove the line $dolibarr_pdf_force_fpdf=1, and add instead $dolibarr_lib_TCPDF_PATH='path_to_TCPDF_dir' LocalTaxDesc=Some countries apply 2 or 3 taxes on each invoice line. If this is the case, choose type for second and third tax and its rate. Possible type are:
1 : local tax apply on products and services without vat (vat is not applied on local tax)
2 : local tax apply on products and services before vat (vat is calculated on amount + localtax)
3 : local tax apply on products without vat (vat is not applied on local tax)
4 : local tax apply on products before vat (vat is calculated on amount + localtax)
5 : local tax apply on services without vat (vat is not applied on local tax)
6 : local tax apply on services before vat (vat is calculated on amount + localtax) diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index d077ffedb4e..0effda388ec 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -346,6 +346,7 @@ TextLong=Texte long Int=Numérique entier Float=Décimal DateAndTime=Date et heure +Boolean=Booleen (Checkbox) LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF WarningUsingFPDF=Attention: Votre fichier conf.php contient la directive dolibarr_pdf_force_fpdf=1. Cela signifie que vous utilisez la librairie FPDF pour générer vos fichiers PDF. Cette librairie est ancienne et ne couvre pas de nombreuses fonctionnalitée (Unicode, transparence des images, langues cyrillic, arabes ou asiatiques...), aussi vous pouvez rencontrez des problèmes durant la génération des PDF.
Pour résoudre cela et avoir un support complet de PDF, vous pouvez télécharger la librairie TCPDF puis commenter ou supprimer la ligne $dolibarr_pdf_force_fpdf=1, et ajouter à la place $dolibarr_lib_TCPDF_PATH='chemin_vers_TCPDF' LocalTaxDesc=Certains pays appliquent 2 voir 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:
1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)
2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)
3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)
4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)
5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)
6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale) From aff96e50503a00f081f72a670333f8313d042629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Sat, 12 Jan 2013 14:14:36 +0100 Subject: [PATCH 4/5] Added test for functions fetch_login and resiliate --- test/phpunit/AdherentTest.php | 84 ++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 1a613fe4845..493783ae2eb 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -161,13 +161,38 @@ class AdherentTest extends PHPUnit_Framework_TestCase return $localobject; } + /** + * testAdherentFetchLogin + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentFetch + * The depends says test is run only if previous is ok + */ + public function testAdherentFetchLogin(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $newobject = new Adherent($this->savdb); + $result = $newobject->fetch_login($localobject->login); + + $this->assertEquals($newobject, $localobject); + + return $localobject; + } + /** * testAdherentUpdate * * @param Adherent $localobject Member instance * @return Adherent * - * @depends testAdherentFetch + * @depends testAdherentFetchLogin * The depends says test is run only if previous is ok */ public function testAdherentUpdate(Adherent $localobject) @@ -259,7 +284,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase '%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%,%EMAIL%,%NAISS%,%PHOTO%,%LOGIN%,%PASSWORD%,%PRENOM%,'. '%NOM%,%SOCIETE%,%ADRESSE%,%CP%,%VILLE%,%PAYS%'; - $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',0,New firstname,New name,New firstname New name,'. + $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',,New firstname,New name,New firstname New name,'. 'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'. 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium'; @@ -370,7 +395,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase * @depends testAdherentSetThirdPartyId * The depends says test is run only if previous is ok */ - public function testAdherentValid(Adherent $localobject) + public function testAdherentValidate(Adherent $localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -391,7 +416,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase * @param Adherent $localobject Member instance * @return int Id of object * - * @depends testAdherentValid + * @depends testAdherentValidate * The depends says test is run only if previous is ok */ public function testAdherentOther(Adherent $localobject) @@ -411,19 +436,56 @@ class AdherentTest extends PHPUnit_Framework_TestCase print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; $this->assertNotEquals($localobject->date_creation, ''); - return $localobject->id; + return $localobject; + } + + /** + * testAdherentResiliate + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentOther + * The depends says test is run only if previous is ok + */ + public function testAdherentResiliate(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //Let's resilie un adherent + $result = $localobject->resiliate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); + + //Is statut updated? + $this->assertEquals($localobject->statut, 0); + + //We update the object and let's check if it was updated on DB + $localobject->fetch($localobject->id); + $this->assertEquals($localobject->statut, 0); + + //Now that status=0, resiliate should return 0 + $result = $localobject->resiliate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 0); + + return $localobject; } /** * testAdherentDelete * - * @param int $id Id of object to delete + * @param Adherent $localobject Member instance * @return void * - * @depends testAdherentOther + * @depends testAdherentResiliate * The depends says test is run only if previous is ok */ - public function testAdherentDelete($id) + public function testAdherentDelete($localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -431,10 +493,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $localobject=new Adherent($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($id); - print __METHOD__." id=".$id." result=".$result."\n"; + $result=$localobject->delete($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $result; From 2cdeb95b675c75f79417e9825f0fe637fd0515ba Mon Sep 17 00:00:00 2001 From: fhenry Date: Sat, 12 Jan 2013 15:16:38 +0100 Subject: [PATCH 5/5] Set member id on create not by sql request after. Mandatory for trigger USER_CREATE to do action if user is member --- htdocs/user/class/user.class.php | 42 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 441186179b3..ef1bba983a0 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -980,6 +980,8 @@ class User extends CommonObject $this->lastname = $member->lastname; $this->firstname = $member->firstname; $this->email = $member->email; + $this->fk_member = $member->id; + if ($member->fk_soc) $sql.= ", fk_societe=".$member->fk_soc; $this->pass = $member->pass; if (empty($login)) $login=strtolower(substr($member->firstname, 0, 4)) . strtolower(substr($member->lastname, 0, 4)); @@ -992,26 +994,26 @@ class User extends CommonObject if ($result > 0) { $result=$this->setPassword($user,$this->pass); - - $sql = "UPDATE ".MAIN_DB_PREFIX."user"; - $sql.= " SET fk_member=".$member->id; - if ($member->fk_soc) $sql.= ", fk_societe=".$member->fk_soc; - $sql.= " WHERE rowid=".$this->id; - - dol_syslog(get_class($this)."::create_from_member sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return $this->id; - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::create_from_member - 1 - ".$this->error, LOG_ERR); - - $this->db->rollback(); - return -1; + if ($member->fk_soc) { + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; + $sql.= " SET fk_societe=".$member->fk_soc; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::create_from_member sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::create_from_member - 1 - ".$this->error, LOG_ERR); + + $this->db->rollback(); + return -1; + } } } else