diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 8c810b76b9781c78dfd84b92f2fed9fdd80e518b..bd184469e49f1eb8ef3f86d56814def9817f021b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3330,7 +3330,7 @@ function price2num($amount,$rounding='',$alreadysqlnb=0) * @param float $vatrate Vat rate. Can be '8.5' or '8.5 (VATCODEX)' for example * @param int $local Local tax to search and return (1 or 2 return only tax rate 1 or tax rate 2) * @param Societe $thirdparty_buyer Object of buying third party - * @param Societe $thirdparty_seller Object of selling third party + * @param Societe $thirdparty_seller Object of selling third party ($mysoc if not defined) * @param int $vatnpr If vat rate is NPR or not * @return mixed 0 if not found, localtax rate if found * @see get_default_tva @@ -3389,18 +3389,15 @@ function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller if ($local == 1 && ! $thirdparty_seller->localtax1_assuj) return 0; if ($local == 2 && ! $thirdparty_seller->localtax2_assuj) return 0; } - //if ($local == 0 && ! $thirdparty_seller->localtax1_assuj && ! $thirdparty_seller->localtax2_assuj) return array('localtax1'=>0,'localtax2'=>0); - // Do not enabled this. We want localtax that match the vat rate. - // If we forced a vat, we must also force local tax - /* - if (is_object($thirdparty_buyer)) + // For some country MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY is forced to on. + if (in_array($mysoc->country_code, array('ES'))) { - if ($thirdparty_seller->country_code != $thirdparty_buyer->country_code) return 0; - }*/ - + $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1; + } + // Search local taxes - if ($mysoc->country_code == 'ES' || ! empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY)) + if (! empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY)) { if ($local==1) { diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 3be258f4243bee7dbf754c336939f079c74b7ac4..625b6c29631edce2baeaea98e999e44f68ef0a56 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -246,10 +246,17 @@ if (empty($reshook)) { $obj = $db->fetch_object($resql); $npr = $obj->recuperableonly; - $localtax1 = get_localtax($tva_tx,1); - $localtax2 = get_localtax($tva_tx,2); + $localtax1 = $obj->localtax1; + $localtax2 = $obj->localtax2; $localtax1_type = $obj->localtax1_type; $localtax2_type = $obj->localtax2_type; + + // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule + if (in_array($mysoc->country_code, array('ES'))) + { + $localtax1 = get_localtax($tva_tx,1); + $localtax2 = get_localtax($tva_tx,2); + } } } $pricestoupdate[0] = array(