Fix: The origin of the stock movement is not being recorded

This commit is contained in:
Ferran Marcet 2022-03-22 13:46:55 +01:00
parent dd38f6c35b
commit ccf8b01020
7 changed files with 26 additions and 9 deletions

View File

@ -10,7 +10,7 @@
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2016-2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016-2022 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
*
* 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) {

View File

@ -14,7 +14,7 @@
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016-2022 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2022 Sylvain Legrand <contact@infras.fr>
@ -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));

View File

@ -9,7 +9,7 @@
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2014-2017 Francis Appels <francis.appels@yahoo.com>
* Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
* Copyright (C) 2016-2021 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016-2022 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Lenin Rivas <lenin@leninrivas.com>
@ -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

View File

@ -10,7 +10,7 @@
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018-2021 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018-2022 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2021 Josep Lluís Amador <joseplluis@lliuretic.cat>
*
* 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;

View File

@ -9,7 +9,7 @@
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* Copyright (C) 2015-2019 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015-2022 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
@ -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));

View File

@ -6,7 +6,7 @@
* Copyright (C) 2010-2021 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Cedric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2016 Florian Henry <florian.henry@atm-consulting.fr>
* Copyright (C) 2017-2020 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2017-2022 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019-2020 Christophe Battarel <christophe@altairis.fr>
*
@ -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;

View File

@ -9,7 +9,7 @@
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2014-2020 Francis Appels <francis.appels@yahoo.com>
* Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016-2022 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
*
* 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