Force date of movement in MouvementStock propagated to subproducts (When using the class MouvementStock, it's possible to force a date of movement

by specifying a date (parameter). If this MouvementStock is affected to a product containing sub-product.s, this date of movement forced will
also be applied to the MouvementStock of the related sub-products.)
This commit is contained in:
Nicolas MANAUD 2022-09-02 16:29:02 +02:00
parent f56abb1e5f
commit f52680a7e0

View File

@ -586,7 +586,7 @@ class MouvementStock extends CommonObject
// Add movement for sub products (recursive call) // Add movement for sub products (recursive call)
if (!$error && !empty($conf->global->PRODUIT_SOUSPRODUITS) && empty($conf->global->INDEPENDANT_SUBPRODUCT_STOCK) && empty($disablestockchangeforsubproduct)) { if (!$error && !empty($conf->global->PRODUIT_SOUSPRODUITS) && empty($conf->global->INDEPENDANT_SUBPRODUCT_STOCK) && empty($disablestockchangeforsubproduct)) {
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode); // we use 0 as price, because AWP must not change for subproduct $error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode, $datem); // we use 0 as price, because AWP must not change for subproduct
} }
if ($movestock && !$error) { if ($movestock && !$error) {
@ -713,9 +713,10 @@ class MouvementStock extends CommonObject
* @param int $price Price * @param int $price Price
* @param string $label Label of movement * @param string $label Label of movement
* @param string $inventorycode Inventory code * @param string $inventorycode Inventory code
* @param integer|string $datem Force date of movement
* @return int <0 if KO, 0 if OK * @return int <0 if KO, 0 if OK
*/ */
private function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '') private function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '', $datem = '')
{ {
global $langs; global $langs;
@ -747,7 +748,7 @@ class MouvementStock extends CommonObject
if (!$error) { if (!$error) {
$tmpmove = dol_clone($this, 1); $tmpmove = dol_clone($this, 1);
$result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode); // This will also call _createSubProduct making this recursive $result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode, $datem); // This will also call _createSubProduct making this recursive
if ($result < 0) { if ($result < 0) {
$this->error = $tmpmove->error; $this->error = $tmpmove->error;
$this->errors = array_merge($this->errors, $tmpmove->errors); $this->errors = array_merge($this->errors, $tmpmove->errors);