Fix regression

This commit is contained in:
Laurent Destailleur 2017-09-13 21:50:14 +02:00
parent dc38ec5051
commit 6d40f797d2
2 changed files with 34 additions and 19 deletions

View File

@ -342,7 +342,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
}
// Multicurrency
if ($conf->multicurrency->enabled && $multicurrency_tx != 1)
if ($multicurrency_tx != 1)
{
// Recal function using the multicurrency price as reference price. We must set param $multicurrency_tx to 1 to avoid infinite loop.
$newresult = calcul_price_total($qty, $pu_devise, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller, $localtaxes_array, $progress, 1, 0);
@ -367,10 +367,17 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
}
else
{
$result[16] = price2num($result[0], 'MT');
$result[17] = price2num($result[1], 'MT');
$result[18] = price2num($result[2], 'MT');
$result[19] = price2num($result[3], 'MU');
$result[16] = $result[0];
$result[17] = $result[1];
$result[18] = $result[2];
$result[19] = $result[3];
$result[20] = $result[4];
$result[21] = $result[5];
$result[22] = $result[6];
$result[23] = $result[7];
$result[24] = $result[8];
$result[25] = $result[9];
$result[26] = $result[10];
}
//var_dump($result);

View File

@ -1,4 +1,7 @@
<?php
use OAuth\OAuth1\Token\StdOAuth1Token;
use Luracast\Restler\Data\Object;
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
*
@ -141,6 +144,11 @@ class PricesTest extends PHPUnit_Framework_TestCase
global $mysoc;
$mysoc=new Societe($db);
// To force status that say module multicompany is on
//$conf->multicurrency=new stdClass();
//$conf->multicurrency->enabled = 0;
/*
* Country France
*/
@ -151,7 +159,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$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, 1.24, 0.12, 1.36, 1.24),$result1,'Test1 FR');
$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, 1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0),$result1,'Test1 FR');
// qty=1, unit_price=1.24, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value)
$mysoc->country_code='FR';
@ -159,7 +167,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result1=calcul_price_total(2, 8.56, 0, 10, 0, 0, 0, 'HT', 0, 0, '', '', 100, 1.09205);
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(17.12, 1.71, 18.83, 8.56, 0.856, 9.416, 17.12, 1.71, 18.83, 0, 0, 0, 0, 0, 0, 0, 18.7, 1.87, 20.57, 9.34795, 0.93479, 10.28274, 18.7, 1.87, 20.57, 0, 0),$result1,'Test1 FR');
$this->assertEquals(array(17.12, 1.71, 18.83, 8.56, 0.856, 9.416, 17.12, 1.71, 18.83, 0, 0, 0, 0, 0, 0, 0, 18.7, 1.87, 20.57, 9.34795, 0.93479, 10.28274, 18.7, 1.87, 20.57, 0, 0),$result1,'Test1b FR');
// qty=2, unit_price=0, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value), pu_ht_devise=100
$mysoc->country_code='FR';
@ -167,7 +175,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result1=calcul_price_total(2, 0, 0, 10, 0, 0, 0, 'HT', 0, 0, '', '', 100, 1.09205, 20);
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(36.63, 3.66, 40.29, 18.31418, 1.83142, 20.1456, 36.63, 3.66, 40.29, 0, 0, 0, 0, 0, 0, 0, 40, 4, 44, 20, 2, 22, 40, 4, 44, 0, 0),$result1,'Test1 FR');
$this->assertEquals(array(36.63, 3.66, 40.29, 18.31418, 1.83142, 20.1456, 36.63, 3.66, 40.29, 0, 0, 0, 0, 0, 0, 0, 40, 4, 44, 20, 2, 22, 40, 4, 44, 0, 0),$result1,'Test1c FR');
/*
* Country Spain
@ -181,7 +189,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result2=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__." result2=".join(', ',$result2)."\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, 100, 10, 110, 10),$result2,'Test1 ES');
$this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0),$result2,'Test1 ES');
// 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, not localtax2 (other method autodetect)
$mysoc->country_code='ES';
@ -191,7 +199,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result2=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__." result2=".join(', ',$result2)."\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, 100, 10, 110, 10),$result2,'Test2 ES');
$this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0),$result2,'Test2 ES');
// --------------------------------------------------------
@ -203,7 +211,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result2=calcul_price_total(10, 10, 0, 10, 1.4, 0, 0, 'HT', 0, 0);
print __METHOD__." result2=".join(', ',$result2)."\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, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0, 100, 10, 111.4, 10),$result2,'Test3 ES');
$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, 100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0),$result2,'Test3 ES');
// 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect)
$mysoc->country_code='ES';
@ -213,7 +221,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0);
print __METHOD__." result2=".join(', ',$result2)."\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, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0, 100, 10, 111.4, 10),$result2,'Test4 ES');
$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, 100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0),$result2,'Test4 ES');
// --------------------------------------------------------
@ -224,7 +232,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$mysoc->localtax2_assuj=1;
$result2=calcul_price_total(10, 10, 0, 10, 0, -19, 0, 'HT', 0, 1);
// 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, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10),$result2,'Test5 ES for service');
$this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19),$result2,'Test5 ES for service');
// 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 21% localtax2 type 5 (other method autodetect), we provide a service and not a product
$mysoc->country_code='ES';
@ -234,7 +242,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0);
print __METHOD__." result2=".join(', ',$result2)."\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, 100, 10, 110, 10),$result2,'Test6 ES for product');
$this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0),$result2,'Test6 ES for product');
// 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 21% localtax2 type 5 (other method autodetect), we provide a product and not a service
$mysoc->country_code='ES';
@ -244,7 +252,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 1);
print __METHOD__." result2=".join(', ',$result2)."\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, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10),$result2,'Test6 ES for service');
$this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19),$result2,'Test6 ES for service');
// --------------------------------------------------------
@ -256,7 +264,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result2=calcul_price_total(10, -10, 0, 10, 0, 19, 0, 'HT', 0, 0);
print __METHOD__." result2=".join(', ',$result2)."\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, -100, -10, -110, -10),$result2,'Test7 ES for product');
$this->assertEquals(array(-100, -10, -110, -10, -1, -11, -100, -10, -110, 0, 0, 0, 0, 0, 0, 0, -100, -10, -110, -10, -1, -11, -100, -10, -110, 0, 0),$result2,'Test7 ES for product');
// Credit Note: 10 * -10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect), we provide a service and not a product
$mysoc->country_code='ES';
@ -265,7 +273,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$mysoc->localtax2_assuj=1;
$result2=calcul_price_total(10, -10, 0, 10, -1, -1, 0, 'HT', 0, 1);
print __METHOD__." result2=".join(', ',$result2)."\n";
$this->assertEquals(array(-100, -10, -91, -10, -1, -9.1, -100, -10, -91, 0, 19, 0, 1.90, 0, 0, 19, -100, -10, -91, -10),$result2,'Test8 ES for service');
$this->assertEquals(array(-100, -10, -91, -10, -1, -9.1, -100, -10, -91, 0, 19, 0, 1.90, 0, 0, 19, -100, -10, -91, -10, -1, -9.1, -100, -10, -91, 0, 19),$result2,'Test8 ES for service');
/*
@ -282,7 +290,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result3=calcul_price_total(10, 10, 0, 18, 7.5, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% 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, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10),$result3,'Test9 CI');
$this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0),$result3,'Test9 CI');
// 10 * 10 HT - 0% discount with 18% vat, seller using localtax1 type 2, not localtax2 (other method autodetect)
$mysoc->country_code='CI';
@ -292,7 +300,7 @@ class PricesTest extends PHPUnit_Framework_TestCase
$result3=calcul_price_total(10, 10, 0, 18, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% 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, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10),$result3,'Test10 CI');
$this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0),$result3,'Test10 CI');
return true;
}