FIX On large proposal or invoice, fix n(n+1) sql into a n sql.

This commit is contained in:
Laurent Destailleur
2022-03-01 14:52:47 +01:00
parent dfba29b3c6
commit bd288f980d
2 changed files with 22 additions and 9 deletions

View File

@@ -872,7 +872,7 @@ class Commande extends CommonOrder
*/
public function create($user, $notrigger = 0)
{
global $conf, $langs;
global $conf, $langs, $mysoc;
$error = 0;
// Clean parameters
@@ -1039,7 +1039,8 @@ class Commande extends CommonOrder
$origintype,
$originid,
0,
$line->ref_ext
$line->ref_ext,
1
);
if ($result < 0) {
if ($result != self::STOCK_NOT_ENOUGH_FOR_ORDER) {
@@ -1056,6 +1057,8 @@ class Commande extends CommonOrder
}
}
$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.
// update ref
$initialref = '(PROV'.$this->id.')';
if (!empty($this->ref)) {
@@ -1433,6 +1436,7 @@ class Commande extends CommonOrder
* @param int $origin_id Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be Id of origin object (aka line id), else object id
* @param double $pu_ht_devise Unit price in currency
* @param string $ref_ext line external reference
* @param int $noupdateafterinsertline No update after insert of line
* @return int >0 if OK, <0 if KO
*
* @see add_product()
@@ -1442,7 +1446,7 @@ class Commande extends CommonOrder
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit)
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
*/
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 = 0, $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $ref_ext = '')
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 = 0, $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $ref_ext = '', $noupdateafterinsertline = 0)
{
global $mysoc, $conf, $langs, $user;
@@ -1653,7 +1657,10 @@ class Commande extends CommonOrder
}
// Mise a jour informations denormalisees au niveau de la commande meme
$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 (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) {
$this->db->commit();
return $this->line->id;