From ccf8b01020330d0d012e131a13fe6ce68649901d Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Tue, 22 Mar 2022 13:46:55 +0100 Subject: [PATCH] Fix: The origin of the stock movement is not being recorded --- htdocs/commande/class/commande.class.php | 5 ++++- htdocs/compta/facture/class/facture.class.php | 5 ++++- htdocs/expedition/class/expedition.class.php | 5 ++++- htdocs/fourn/class/fournisseur.commande.class.php | 6 +++--- htdocs/fourn/class/fournisseur.facture.class.php | 4 +++- htdocs/fourn/commande/dispatch.php | 4 +++- htdocs/reception/class/reception.class.php | 6 +++++- 7 files changed, 26 insertions(+), 9 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 429996ee314..f51c8026672 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -10,7 +10,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Marcos García * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2016-2018 Ferran Marcet + * Copyright (C) 2016-2022 Ferran Marcet * Copyright (C) 2021 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -518,6 +518,7 @@ class Commande extends CommonOrder if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We decrement stock of product (and sub-products) $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderValidatedInDolibarr", $num)); if ($result < 0) { @@ -645,6 +646,7 @@ class Commande extends CommonOrder if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We increment stock of product (and sub-products) $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("OrderBackToDraftInDolibarr", $this->ref)); if ($result < 0) { @@ -823,6 +825,7 @@ class Commande extends CommonOrder for ($i = 0; $i < $num; $i++) { if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->setOrigin($this->element, $this->id); // We increment stock of product (and sub-products) $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("OrderCanceledInDolibarr", $this->ref)); // price is 0, we don't want WAP to be changed if ($result < 0) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5e61499464c..55fa26d3c6b 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -14,7 +14,7 @@ * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2013 Cedric Gross * Copyright (C) 2013 Florian Henry - * Copyright (C) 2016 Ferran Marcet + * Copyright (C) 2016-2022 Ferran Marcet * Copyright (C) 2018 Alexandre Spangaro * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2022 Sylvain Legrand @@ -2323,6 +2323,7 @@ class Facture extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We decrease stock for product if ($this->type == self::TYPE_CREDIT_NOTE) { $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr", $this->ref)); @@ -2759,6 +2760,7 @@ class Facture extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We decrease stock for product if ($this->type == self::TYPE_CREDIT_NOTE) { $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceValidatedInDolibarr", $num)); @@ -3051,6 +3053,7 @@ class Facture extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We decrease stock for product if ($this->type == self::TYPE_CREDIT_NOTE) { $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref)); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 600f498da7c..a29919b7346 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2014-2015 Marcos García * Copyright (C) 2014-2017 Francis Appels * Copyright (C) 2015 Claudio Aschieri - * Copyright (C) 2016-2021 Ferran Marcet + * Copyright (C) 2016-2022 Ferran Marcet * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018-2020 Frédéric France * Copyright (C) 2020 Lenin Rivas @@ -753,6 +753,7 @@ class Expedition extends CommonObject //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = dol_clone($this, 1); + $mouvS->setOrigin($this->element, $this->id); if (empty($obj->edbrowid)) { // line without batch detail @@ -2233,6 +2234,7 @@ class Expedition extends CommonObject $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; + $mouvS->setOrigin($this->element, $this->id); if (empty($obj->edbrowid)) { // line without batch detail @@ -2404,6 +2406,7 @@ class Expedition extends CommonObject //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; + $mouvS->setOrigin($this->element, $this->id); if (empty($obj->edbrowid)) { // line without batch detail diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 649fb0e106f..a20075295d9 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -10,7 +10,7 @@ * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018-2020 Frédéric France - * Copyright (C) 2018-2021 Ferran Marcet + * Copyright (C) 2018-2022 Ferran Marcet * Copyright (C) 2021 Josep Lluís Amador * * This program is free software; you can redistribute it and/or modify @@ -1071,6 +1071,7 @@ class CommandeFournisseur extends CommonOrder $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We decrement stock of product (and sub-products) $up_ht_disc = $this->lines[$i]->subprice; if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) { @@ -2037,8 +2038,7 @@ class CommandeFournisseur extends CommonOrder if ($product > 0) { // $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on) $mouv->origin = &$this; - $mouv->origin_type = $this->element; - $mouv->origin_id = $this->id; + $mouv->setOrigin($this->element, $this->id); $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch); if ($result < 0) { $this->error = $mouv->error; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 2a1a54e70d3..bd25fbea6ec 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2016 Marcos García * Copyright (C) 2015 Bahfir Abbes - * Copyright (C) 2015-2019 Ferran Marcet + * Copyright (C) 2015-2022 Ferran Marcet * Copyright (C) 2016-2021 Alexandre Spangaro * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018-2022 Frédéric France @@ -1605,6 +1605,7 @@ class FactureFournisseur extends CommonInvoice $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We increase stock for product $up_ht_disc = $this->lines[$i]->pu_ht; if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) { @@ -1734,6 +1735,7 @@ class FactureFournisseur extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; + $mouvP->setOrigin($this->element, $this->id); // We increase stock for product if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) { $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref)); diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index bb56e5d4555..a1ddef959a0 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -6,7 +6,7 @@ * Copyright (C) 2010-2021 Juanjo Menent * Copyright (C) 2014 Cedric Gross * Copyright (C) 2016 Florian Henry - * Copyright (C) 2017-2020 Ferran Marcet + * Copyright (C) 2017-2022 Ferran Marcet * Copyright (C) 2018 Frédéric France * Copyright (C) 2019-2020 Christophe Battarel * @@ -423,6 +423,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoreceive $mouv = new MouvementStock($db); if ($product > 0) { $mouv->origin = &$object; + $mouv->setOrigin($object->element, $object->id); $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch); if ($result < 0) { $errors = $mouv->errors; @@ -469,6 +470,7 @@ if ($action == 'updateline' && $permissiontoreceive) { $mouv = new MouvementStock($db); if ($product > 0) { $mouv->origin = &$object; + $mouv->setOrigin($object->element, $object->id); $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch); if ($result < 0) { $errors = $mouv->errors; diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 28fb783e2c9..b8246b7fe8e 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2014-2015 Marcos García * Copyright (C) 2014-2020 Francis Appels * Copyright (C) 2015 Claudio Aschieri - * Copyright (C) 2016 Ferran Marcet + * Copyright (C) 2016-2022 Ferran Marcet * Copyright (C) 2018 Quentin Vial-Gouteyron * * This program is free software; you can redistribute it and/or modify @@ -591,6 +591,7 @@ class Reception extends CommonObject //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; + $mouvS->setOrigin($this->element, $this->id); if (empty($obj->batch)) { // line without batch detail @@ -1632,6 +1633,7 @@ class Reception extends CommonObject $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; + $mouvS->setOrigin($this->element, $this->id); if (empty($obj->batch)) { // line without batch detail @@ -1796,6 +1798,7 @@ class Reception extends CommonObject //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; + $mouvS->setOrigin($this->element, $this->id); if (empty($obj->batch)) { // line without batch detail @@ -1926,6 +1929,7 @@ class Reception extends CommonObject //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; + $mouvS->setOrigin($this->element, $this->id); if (empty($obj->batch)) { // line without batch detail