2
0
forked from Wavyzz/dolibarr

Fix: regression

This commit is contained in:
Laurent Destailleur
2012-11-06 19:23:23 +01:00
parent 058325b7f2
commit f37c559235
2 changed files with 53 additions and 19 deletions

View File

@@ -130,24 +130,56 @@ class PricesTest extends PHPUnit_Framework_TestCase
$this->savlangs=$langs;
$this->savdb=$db;
global $mysoc;
$mysoc=new Societe($db);
// qty=1, unit_price=1.24, discount_line=0, vat_rate=10, price_base_type='HT'
$result1=calcul_price_total(1, 1.24, 0, 10, 0, 0, 0, 'HT', 0);
$mysoc->country_code='FR';
$mysoc->country_id=1;
$result1=calcul_price_total(1, 1.24, 0, 10, 0, 0, 0, 'HT', 0, 0);
print __METHOD__." result1=".join(', ',$result1)."\n";
// result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount)
$this->assertEquals(array(1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0, 0, 0, 0, 0, 0),$result1);
// 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 1, 0% localtax2 type 0
$result2=calcul_price_total(10, 10, 0, 10, 1.4, 0, 0, 'HT', 0, 0, 1, 0);
// 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 1, 0% localtax2 type 0 (method we provide value)
$mysoc->country_code='ES';
$mysoc->country_id=4;
$mysoc->localtax1_assuj=1;
$mysoc->localtax2_assuj=0;
$result2=calcul_price_total(10, 10, 0, 10, 1.4, 0, 0, 'HT', 0, 0);
print __METHOD__." result2=".join(', ',$result2)."\n";
$this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result2);
// Old function for spain countries. To check backward compatibility.
global $mysoc;
$mysoc=new Societe($db);
$mysoc->country_code='ES';
$result3=calcul_price_total(10, 10, 0, 10, 1.4, 0, 0, 'HT', 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2
// 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 1, 0% localtax2 type 0 (other method autodetect)
$mysoc->country_code='ES';
$mysoc->country_id=4;
$mysoc->localtax1_assuj=1;
$mysoc->localtax2_assuj=0;
$result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0);
print __METHOD__." result2=".join(', ',$result2)."\n";
$this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result2);
// 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, nor localtax2 (method we provide value)
$mysoc->country_code='ES';
$mysoc->country_id=4;
$mysoc->localtax1_assuj=0;
$mysoc->localtax2_assuj=0;
$result3=calcul_price_total(10, 10, 0, 10, 0, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2
print __METHOD__." result3=".join(', ',$result3)."\n";
$this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result3);
// result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount)
$this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0),$result3);
//$this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result3);
// 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, nor localtax2 (other method autodetect)
$mysoc->country_code='ES';
$mysoc->country_id=4;
$mysoc->localtax1_assuj=0;
$mysoc->localtax2_assuj=0;
$result3=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2
print __METHOD__." result3=".join(', ',$result3)."\n";
// result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount)
$this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0),$result3);
//$this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result3);
return true;
}