Fix warnings

This commit is contained in:
Laurent Destailleur 2020-12-26 19:23:25 +01:00
parent 58cd7c97a5
commit f20f4cc599
2 changed files with 23 additions and 20 deletions

View File

@ -493,42 +493,42 @@ function createProductOrService($authentication, $product)
$error = 0; $error = 0;
$fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
// Check parameters // Check parameters
if ($product['price_net'] > 0) $product['price_base_type'] = 'HT'; if (empty($product['price_base_type'])) {
if ($product['price'] > 0) $product['price_base_type'] = 'TTC'; if (isset($product['price_net']) && $product['price_net'] > 0) $product['price_base_type'] = 'HT';
if (isset($product['price']) && $product['price'] > 0) $product['price_base_type'] = 'TTC';
}
if ($product['price_net'] > 0 && $product['price'] > 0) if (isset($product['price_net']) && $product['price_net'] > 0 && isset($product['price']) && $product['price'] > 0)
{ {
$error++; $errorcode = 'KO'; $errorlabel = "You must choose between price or price_net to provide price."; $error++; $errorcode = 'KO'; $errorlabel = "You must choose between price or price_net to provide price.";
} }
if ($product['barcode'] && !$product['barcode_type']) if (!empty($product['barcode']) && empty($product['barcode_type']))
{ {
$error++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode."; $error++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode.";
} }
if (!$error) if (!$error)
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$newobject = new Product($db); $newobject = new Product($db);
$newobject->ref = $product['ref']; $newobject->ref = $product['ref'];
$newobject->ref_ext = $product['ref_ext']; $newobject->ref_ext = empty($product['ref_ext']) ? '' : $product['ref_ext'];
$newobject->type = $product['type']; $newobject->type = empty($product['type']) ? 0 : $product['type'];
$newobject->label = $product['label']; $newobject->label = empty($product['label']) ? '' : $product['label'];
$newobject->description = $product['description']; $newobject->description = empty($product['description']) ? '' : $product['description'];
$newobject->note_public = $product['note_public']; $newobject->note_public = empty($product['note_public']) ? '' : $product['note_public'];
$newobject->note_private = $product['note_private']; $newobject->note_private = empty($product['note_private']) ? '' :$product['note_private'];
$newobject->status = $product['status_tosell']; $newobject->status = empty($product['status_tosell']) ? 0 : $product['status_tosell'];
$newobject->status_buy = $product['status_tobuy']; $newobject->status_buy = empty($product['status_tobuy']) ? 0 : $product['status_tobuy'];
$newobject->price = $product['price_net']; $newobject->price = isset($product['price_net']) ? $product['price_net'] : 0;
$newobject->price_ttc = $product['price']; $newobject->price_ttc = isset($product['price']) ? $product['price'] : 0;
$newobject->tva_tx = $product['vat_rate']; $newobject->tva_tx = empty($product['vat_rate']) ? 0 : $product['vat_rate'];
$newobject->price_base_type = $product['price_base_type']; $newobject->price_base_type = $product['price_base_type'];
$newobject->date_creation = $now; $newobject->date_creation = $now;
if ($product['barcode']) if (!empty($product['barcode']))
{ {
$newobject->barcode = $product['barcode']; $newobject->barcode = $product['barcode'];
$newobject->barcode_type = $product['barcode_type']; $newobject->barcode_type = $product['barcode_type'];
@ -539,7 +539,7 @@ function createProductOrService($authentication, $product)
$newobject->seuil_stock_alert = $product['stock_alert']; $newobject->seuil_stock_alert = $product['stock_alert'];
$newobject->country_id = $product['country_id']; $newobject->country_id = $product['country_id'];
if ($product['country_code']) $newobject->country_id = getCountry($product['country_code'], 3); if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3);
$newobject->customcode = $product['customcode']; $newobject->customcode = $product['customcode'];
$newobject->canvas = $product['canvas']; $newobject->canvas = $product['canvas'];

View File

@ -182,7 +182,10 @@ class WebservicesProductsTest extends PHPUnit\Framework\TestCase
'type'=>1, 'type'=>1,
'description'=>'This is a new product created from WS PHPUnit test case', 'description'=>'This is a new product created from WS PHPUnit test case',
'barcode'=>'123456789012', 'barcode'=>'123456789012',
'barcode_type'=>2 'barcode_type'=>2,
'price_net'=>10,
'status_tosell'=>1,
'status_tobuy'=>1
) )
); );
print __METHOD__." call method ".$WS_METHOD."\n"; print __METHOD__." call method ".$WS_METHOD."\n";