This commit is contained in:
Laurent Destailleur
2025-02-10 18:09:32 +01:00
parent 0064958589
commit 95622c22df
6 changed files with 89 additions and 62 deletions

View File

@@ -1097,6 +1097,7 @@ class Commande extends CommonOrder
$line->ref_ext,
1
);
if ($result < 0) {
if ($result != self::STOCK_NOT_ENOUGH_FOR_ORDER) {
$this->error = $this->db->lasterror();
@@ -1536,11 +1537,11 @@ class Commande extends CommonOrder
*/
public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $info_bits = 0, $fk_remise_except = 0, $price_base_type = 'HT', $pu_ttc = 0, $date_start = '', $date_end = '', $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $array_options = array(), $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $ref_ext = '', $noupdateafterinsertline = 0)
{
global $mysoc, $conf, $langs, $user;
global $mysoc, $langs, $user;
$logtext = "::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent";
$logtext .= ", info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start";
$logtext .= ", date_end=$date_end, type=$type special_code=$special_code, fk_unit=$fk_unit, origin=$origin, origin_id=$origin_id, pu_ht_devise=$pu_ht_devise, ref_ext=$ref_ext";
$logtext .= ", date_end=$date_end, type=$type special_code=$special_code, fk_unit=$fk_unit, origin=$origin, origin_id=$origin_id, pu_ht_devise=$pu_ht_devise, ref_ext=$ref_ext rang=$rang";
dol_syslog(get_class($this).$logtext, LOG_DEBUG);
if ($this->statut == self::STATUS_DRAFT) {
@@ -1666,6 +1667,7 @@ class Commande extends CommonOrder
// Rang to use
$ranktouse = $rang;
if ($ranktouse == -1) {
$rangmax = $this->line_max($fk_parent_line);
$ranktouse = $rangmax + 1;
@@ -1738,25 +1740,29 @@ class Commande extends CommonOrder
$result = $this->line->insert($user);
if ($result > 0) {
// Reorder if child line
if (!empty($fk_parent_line)) {
$this->line_order(true, 'DESC');
} elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines
$linecount = count($this->lines);
for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
$this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
}
}
// Mise a jour information denormalisees au niveau de la commande meme
// Update denormalized fields at the order level
if (empty($noupdateafterinsertline)) {
$result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode.
}
if ($result > 0) {
if (!isset($this->context['createfromclone'])) {
if (!empty($fk_parent_line)) {
// Always reorder if child line
$this->line_order(true, 'DESC');
} elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
// Update all rank of all other lines starting from the same $ranktouse
$linecount = count($this->lines);
for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
$this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
}
}
$this->lines[] = $this->line;
}
$this->db->commit();
$this->lines[] = $this->line;
return $this->line->id;
return $line->id;
} else {
$this->db->rollback();
return -1;