Merge pull request #20302 from marc-dll/13.0_FIX_product_price_update_error_management

FIX: better error management at product selling price update
This commit is contained in:
Laurent Destailleur 2022-03-23 16:48:15 +01:00 committed by GitHub
commit 6167d8a02c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 15 deletions

View File

@ -2049,7 +2049,8 @@ class Product extends CommonObject
$this->db->commit(); $this->db->commit();
} else { } else {
$this->db->rollback(); $this->db->rollback();
dol_print_error($this->db); $this->error = $this->db->lasterror();
return -1;
} }
} }

View File

@ -163,11 +163,15 @@ if (empty($reshook))
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
if ($error) if (!$error) {
{
//$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2); //$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
$localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them. $localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them.
$object->updatePrice(0, $object->price_base_type, $user, $tva_tx, '', 0, $npr, 0, 0, $localtaxarray, $vatratecode); $ret = $object->updatePrice(0, $object->price_base_type, $user, $tva_tx, '', 0, $npr, 0, 0, $localtaxarray, $vatratecode);
if ($ret < 0) {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
} }
if (!$error) if (!$error)
@ -400,14 +404,22 @@ if (empty($reshook))
{ {
// Activating product price by quantity add a new price line with price_by_qty set to 1 // Activating product price by quantity add a new price line with price_by_qty set to 1
$level = GETPOST('level', 'int'); $level = GETPOST('level', 'int');
$object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1); $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1);
if ($ret < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
} }
// Unset Price by quantity // Unset Price by quantity
if ($action == 'disable_price_by_qty') if ($action == 'disable_price_by_qty')
{ {
// Disabling product price by quantity add a new price line with price_by_qty set to 0 // Disabling product price by quantity add a new price line with price_by_qty set to 0
$level = GETPOST('level', 'int'); $level = GETPOST('level', 'int');
$object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 0); $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 0);
if ($ret < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
} }
if ($action == 'edit_price_by_qty') if ($action == 'edit_price_by_qty')
@ -1448,14 +1460,18 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul
// On l'ajoute donc pour remettre a niveau (pb vieilles versions) // On l'ajoute donc pour remettre a niveau (pb vieilles versions)
// We emulate the change of the price from interface with the same value than the one into table llx_product // We emulate the change of the price from interface with the same value than the one into table llx_product
if (!empty($conf->global->PRODUIT_MULTIPRICES)) { if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
$object->updatePrice(($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_ttc[1] : $object->multiprices[1]), $object->multiprices_base_type[1], $user, (empty($object->multiprices_tva_tx[1]) ? 0 : $object->multiprices_tva_tx[1]), ($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_min_ttc[1] : $object->multiprices_min[1]), 1); $ret = $object->updatePrice(($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_ttc[1] : $object->multiprices[1]), $object->multiprices_base_type[1], $user, (empty($object->multiprices_tva_tx[1]) ? 0 : $object->multiprices_tva_tx[1]), ($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_min_ttc[1] : $object->multiprices_min[1]), 1);
} else { } else {
$object->updatePrice(($object->price_base_type == 'TTC' ? $object->price_ttc : $object->price), $object->price_base_type, $user, $object->tva_tx, ($object->price_base_type == 'TTC' ? $object->price_min_ttc : $object->price_min)); $ret = $object->updatePrice(($object->price_base_type == 'TTC' ? $object->price_ttc : $object->price), $object->price_base_type, $user, $object->tva_tx, ($object->price_base_type == 'TTC' ? $object->price_min_ttc : $object->price_min));
} }
if ($ret < 0) {
dol_print_error($db, $object->error, $object->errors);
} else {
$result = $db->query($sql); $result = $db->query($sql);
$num = $db->num_rows($result); $num = $db->num_rows($result);
} }
}
if ($num > 0) { if ($num > 0) {
// Default prices or // Default prices or

View File

@ -534,7 +534,14 @@ class ProductCombination
$new_price += $variation_price; $new_price += $variation_price;
} }
$child->updatePrice($new_price, $new_type, $user, $new_vat, $new_min_price, $i, $new_npr, $new_psq, 0, array(), $parent->default_vat_code); $ret = $child->updatePrice($new_price, $new_type, $user, $new_vat, $new_min_price, $i, $new_npr, $new_psq, 0, array(), $parent->default_vat_code);
if ($ret < 0) {
$this->db->rollback();
$this->error = $child->error;
$this->errors = $child->errors;
return $ret;
}
} }
} }
} else { } else {
@ -556,7 +563,14 @@ class ProductCombination
$new_price += $this->variation_price; $new_price += $this->variation_price;
} }
$child->updatePrice($new_price, $new_type, $user, $new_vat, $new_min_price, 1, $new_npr, $new_psq); $ret = $child->updatePrice($new_price, $new_type, $user, $new_vat, $new_min_price, 1, $new_npr, $new_psq);
if ($ret < 0) {
$this->db->rollback();
$this->error = $child->error;
$this->errors = $child->errors;
return $ret;
}
} }
$this->db->commit(); $this->db->commit();
@ -565,6 +579,8 @@ class ProductCombination
} }
$this->db->rollback(); $this->db->rollback();
$this->error = $child->error;
$this->errors = $child->errors;
return -1; return -1;
} }