Merge pull request #14327 from FHenry/dev_refac_classproduct

->error rather than dol_print_error into product class
This commit is contained in:
Laurent Destailleur 2020-08-02 01:21:19 +02:00 committed by GitHub
commit d44a16bdfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 17 deletions

View File

@ -890,7 +890,10 @@ if ($rowid > 0) {
if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) {
$prodtmp = new Product($db);
$prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
$result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
if ($result < 0) {
setEventMessage($prodtmp->error, 'errors');
}
print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
}
print '<br>';
@ -912,7 +915,10 @@ if ($rowid > 0) {
if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) {
$prodtmp = new Product($db);
$prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
$result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
if ($result < 0) {
setEventMessage($prodtmp->error, 'errors');
}
print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
}
print '<br>';

View File

@ -419,8 +419,10 @@ class Documents extends DolibarrApi
$object = new Product($this->db);
$result = $object->fetch($id, $ref);
if (!$result) {
if ($result==0) {
throw new RestException(404, 'Product not found');
} elseif ($result<0) {
throw new RestException(500, 'Error while fetching object: '.$object->error);
}
$upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
@ -630,7 +632,7 @@ class Documents extends DolibarrApi
}
elseif ($result < 0)
{
throw new RestException(500, 'Error while fetching object.');
throw new RestException(500, 'Error while fetching object: '.$object->error);
}
}

View File

@ -57,9 +57,11 @@ $thirdpartytmp = new Societe($db);
if (GETPOST('submitproduct') && GETPOST('submitproduct'))
{
$action = ''; // We reset because we don't want to build doc
if (GETPOST('productid') > 0)
{
$producttmp->fetch(GETPOST('productid'));
if (GETPOST('productid') > 0) {
$result = $producttmp->fetch(GETPOST('productid'));
if ($result < 0) {
setEventMessage($producttmp->error, 'errors');
}
$forbarcode = $producttmp->barcode;
$fk_barcode_type = $producttmp->barcode_type;

View File

@ -1004,7 +1004,11 @@ class BOM extends CommonObject
foreach ($this->lines as &$line) {
$tmpproduct = new Product($this->db);
$tmpproduct->fetch($line->fk_product);
$result= $tmpproduct->fetch($line->fk_product);
if ($result < 0) {
$this->error=$tmpproduct->error;
return -1;
}
$line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
if (empty($line->unit_cost)) {
if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0)

View File

@ -52,8 +52,15 @@ foreach ($linkedObjectBlock as $key => $objectlink)
}
echo '</td>';
echo '<td class="linkedcol-name nowraponall" >'.$objectlink->getNomUrl(1).'</td>';
$product_static->fetch($objectlink->fk_product);
echo '<td class="linkedcol-ref" align="center">'.$product_static->getNomUrl(1).'</td>';
echo '<td class="linkedcol-ref" align="center">';
$result=$product_static->fetch($objectlink->fk_product);
if ($result<0) {
setEventMessage($product_static->error, 'errors');
} elseif ($result>0) {
$product_static->getNomUrl(1);
}
print '</td>';
echo '<td class="linkedcol-date" align="center">'.dol_print_date($objectlink->date_creation, 'day').'</td>';
echo '<td class="linkedcol-amount right">';
if ($user->rights->commande->lire) {

View File

@ -2209,7 +2209,7 @@ class Product extends CommonObject
}
}*/
} else {
dol_print_error($this->db);
$this->error=$this->db->lasterror;
return -1;
}
}
@ -2254,12 +2254,12 @@ class Product extends CommonObject
}
$this->prices_by_qty_list[0] = $resultat;
} else {
dol_print_error($this->db);
return -1;
$this->error=$this->db->lasterror;
return -1;
}
}
} else {
dol_print_error($this->db);
$this->error=$this->db->lasterror;
return -1;
}
} elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES) && empty($ignore_price_load)) // prices per customer and quantity
@ -2313,12 +2313,12 @@ class Product extends CommonObject
}
$this->prices_by_qty_list[$i] = $resultat;
} else {
dol_print_error($this->db);
$this->error=$this->db->lasterror;
return -1;
}
}
} else {
dol_print_error($this->db);
$this->error=$this->db->lasterror;
return -1;
}
}
@ -2345,7 +2345,7 @@ class Product extends CommonObject
return 0;
}
} else {
dol_print_error($this->db);
$this->error=$this->db->lasterror;
return -1;
}
}