From d21f5eca830a341bb780a39c96f5390421ab0f2d Mon Sep 17 00:00:00 2001 From: amarchal Date: Mon, 9 May 2022 20:13:06 +0200 Subject: [PATCH] add hidden option SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN --- htdocs/fourn/class/fournisseur.commande.class.php | 7 ++++++- htdocs/fourn/commande/dispatch.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 128c2ab3356..1d26fb5cfab 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2084,7 +2084,12 @@ class CommandeFournisseur extends CommonOrder // $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on) $mouv->origin = &$this; $mouv->setOrigin($this->element, $this->id); - $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch); + // Method change if qty < 0 + if (!empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN) && $qty < 0) { + $result = $mouv->livraison($user, $product, $entrepot, $qty*(-1), $price, $comment, $now, $eatby, $sellby, $batch); + } else { + $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch); + } if ($result < 0) { $this->error = $mouv->error; $this->errors = $mouv->errors; diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 166da07ab03..362741e1641 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -802,7 +802,7 @@ if ($id > 0 || !empty($ref)) { $nbfreeproduct++; } else { $remaintodispatch = price2num($objp->qty - ((float) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched - if ($remaintodispatch < 0) { + if ($remaintodispatch < 0 && empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN)) { $remaintodispatch = 0; }