Sfoglia il codice sorgente

Fix when reverting a shipment validation or closing and stock empty

Laurent Destailleur 2 anni fa
parent
commit
8ba802ed5d

+ 5 - 0
htdocs/expedition/card.php

@@ -1739,6 +1739,11 @@ if ($action == 'create') {
 		}
 
 		$text = $langs->trans("ConfirmValidateSending", $numref);
+		if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {
+			$text .= ' '.$langs->trans("StockMovementWillBeRecorded").'.';
+		} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
+			$text .= ' '.$langs->trans("StockMovementNotYetRecorded").'.';
+		}
 
 		if (isModEnabled('notification')) {
 			require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';

+ 1 - 1
htdocs/langs/en_US/agenda.lang

@@ -62,7 +62,7 @@ MemberSubscriptionAddedInDolibarr=Subscription %s for member %s added
 MemberSubscriptionModifiedInDolibarr=Subscription %s for member %s modified
 MemberSubscriptionDeletedInDolibarr=Subscription %s for member %s deleted
 ShipmentValidatedInDolibarr=Shipment %s validated
-ShipmentClassifyClosedInDolibarr=Shipment %s classified billed
+ShipmentClassifyClosedInDolibarr=Shipment %s classified closed
 ShipmentUnClassifyCloseddInDolibarr=Shipment %s classified re-open
 ShipmentBackToDraftInDolibarr=Shipment %s go back to draft status
 ShipmentDeletedInDolibarr=Shipment %s deleted

+ 2 - 0
htdocs/langs/en_US/stocks.lang

@@ -318,3 +318,5 @@ StockTransferRightRead=Read stocks transfers
 StockTransferRightCreateUpdate=Create/Update stocks transfers
 StockTransferRightDelete=Delete stocks transfers
 BatchNotFound=Lot / serial not found for this product
+StockMovementWillBeRecorded=Stock movement will be recorded
+StockMovementNotYetRecorded=Stock movement will not be affected by this step

+ 1 - 1
htdocs/langs/fr_FR/agenda.lang

@@ -62,7 +62,7 @@ MemberSubscriptionAddedInDolibarr=Cotisation %s pour l'adhérent %s ajoutée
 MemberSubscriptionModifiedInDolibarr=Cotisation %s pour l'adhérent %s modifié
 MemberSubscriptionDeletedInDolibarr=Cotisation %s pour l'adhérent %s supprimé
 ShipmentValidatedInDolibarr=Expédition %s validée
-ShipmentClassifyClosedInDolibarr=Expédition %s classée payée
+ShipmentClassifyClosedInDolibarr=Expédition %s classée close
 ShipmentUnClassifyCloseddInDolibarr=Expédition %s réouverte
 ShipmentBackToDraftInDolibarr=Expédition %s remise au statut brouillon
 ShipmentDeletedInDolibarr=Expédition %s supprimée

+ 8 - 2
htdocs/product/stock/class/mouvementstock.class.php

@@ -301,7 +301,9 @@ class MouvementStock extends CommonObject
 			// If not found, we add record
 			$sql = "SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix()."product_lot as pb";
 			$sql .= " WHERE pb.fk_product = ".((int) $fk_product)." AND pb.batch = '".$this->db->escape($batch)."'";
+
 			dol_syslog(get_class($this)."::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
+
 			$resql = $this->db->query($sql);
 			if ($resql) {
 				$num = $this->db->num_rows($resql);
@@ -560,6 +562,10 @@ class MouvementStock extends CommonObject
 			if (!$error && isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) {
 				if ($id_product_batch > 0) {
 					$result = $this->createBatch($id_product_batch, $qty);
+					if ($result == -2 && $fk_product_stock > 0) {	// The entry for this product batch does not exists anymore, bu we already have a llx_product_stock, so we recreate the batch entry in product_batch
+						$param_batch = array('fk_product_stock' =>$fk_product_stock, 'batchnumber'=>$batch);
+						$result = $this->createBatch($param_batch, $qty);
+					}
 				} else {
 					$param_batch = array('fk_product_stock' =>$fk_product_stock, 'batchnumber'=>$batch);
 					$result = $this->createBatch($param_batch, $qty);
@@ -863,10 +869,10 @@ class MouvementStock extends CommonObject
 	 * Create or update batch record (update table llx_product_batch). No check is done here, done by parent.
 	 *
 	 * @param	array|int	$dluo	      Could be either
-	 *                                    - int if row id of product_batch table
+	 *                                    - int if row id of product_batch table (for update)
 	 *                                    - or complete array('fk_product_stock'=>, 'batchnumber'=>)
 	 * @param	int			$qty	      Quantity of product with batch number. May be a negative amount.
-	 * @return 	int   				      <0 if KO, else return productbatch id
+	 * @return 	int   				      <0 if KO, -2 if we try to update a product_batchid that does not exist, else return productbatch id
 	 */
 	private function createBatch($dluo, $qty)
 	{