From 1102dc272e09884bbed92f7d061a8a3a2fbb8da3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Dec 2022 22:04:09 +0100 Subject: [PATCH] Debug log inalterable to allow tracking of stock movement --- htdocs/blockedlog/class/blockedlog.class.php | 63 ++++++++++++++----- ..._modBlockedlog_ActionsBlockedLog.class.php | 15 +++-- .../stock/class/mouvementstock.class.php | 7 +++ .../product/stock/tpl/stockcorrection.tpl.php | 2 +- 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php index 15af4a532fa..70ba9a2b531 100644 --- a/htdocs/blockedlog/class/blockedlog.class.php +++ b/htdocs/blockedlog/class/blockedlog.class.php @@ -204,6 +204,7 @@ class BlockedLog } // Add more action to track from a conf variable + // For example: STOCK_MOVEMENT,... if (!empty($conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED)) { $tmparrayofmoresupportedevents = explode(',', $conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED); foreach ($tmparrayofmoresupportedevents as $val) { @@ -305,6 +306,15 @@ class BlockedLog } else { $this->error++; } + } elseif ($this->element === 'stockmouvement') { + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; + + $object = new MouvementStock($this->db); + if ($object->fetch($this->fk_object) > 0) { + return $object->getNomUrl(1); + } else { + $this->error++; + } } elseif ($this->action == 'MODULE_SET') { return ''.$langs->trans("BlockedLogEnabled").''; } elseif ($this->action == 'MODULE_RESET') { @@ -378,9 +388,14 @@ class BlockedLog $this->date_object = $object->dateh; } elseif ($object->element == 'cashcontrol') { $this->date_object = $object->date_creation; - } else { + } elseif (property_exists($object, 'date')) { + // Generic case $this->date_object = $object->date; + } elseif (property_exists($object, 'datem')) { + // Generic case (second chance, for example for stock movement) + $this->date_object = $object->datem; } + // ref $this->ref_object = ((!empty($object->newref)) ? $object->newref : $object->ref); // newref is set when validating a draft, ref is set in other cases // type of object @@ -395,11 +410,18 @@ class BlockedLog $arrayoffieldstoexclude = array( 'table_element', 'fields', 'ref_previous', 'ref_next', 'origin', 'origin_id', 'oldcopy', 'picto', 'error', 'errors', 'model_pdf', 'modelpdf', 'last_main_doc', 'civility_id', 'contact', 'contact_id', 'table_element_line', 'ismultientitymanaged', 'isextrafieldmanaged', + 'array_languages', + 'childtables', + 'contact_ids', + 'context', + 'labelStatus', + 'labelStatusShort', 'linkedObjectsIds', 'linkedObjects', 'fk_delivery_address', - 'context', - 'projet' // There is already ->fk_project + 'projet', // There is already ->fk_project + 'restrictiononfksoc', + 'specimen', ); // Add more fields to exclude depending on object type if ($this->element == 'cashcontrol') { @@ -428,7 +450,7 @@ class BlockedLog continue; // Discard if not into a dedicated list } if (!is_object($value) && !is_null($value) && $value !== '') { - $this->object_data->thirdparty->{$key} = $value; + $this->object_data->thirdparty->$key = $value; } } } @@ -448,7 +470,7 @@ class BlockedLog continue; // Discard if not into a dedicated list } if (!is_object($value) && !is_null($value) && $value !== '') { - $this->object_data->mycompany->{$key} = $value; + $this->object_data->mycompany->$key = $value; } } } @@ -486,12 +508,12 @@ class BlockedLog } if (!is_object($valueline) && !is_null($valueline) && $valueline !== '') { - $this->object_data->invoiceline[$lineid]->{$keyline} = $valueline; + $this->object_data->invoiceline[$lineid]->$keyline = $valueline; } } } } elseif (!is_object($value) && !is_null($value) && $value !== '') { - $this->object_data->{$key} = $value; + $this->object_data->$key = $value; } } @@ -509,7 +531,7 @@ class BlockedLog continue; // Discard if not into a dedicated list } if (!is_object($value) && !is_null($value) && $value !== '') { - $this->object_data->{$key} = $value; + $this->object_data->$key = $value; } } @@ -601,7 +623,7 @@ class BlockedLog continue; // Discard if not into a dedicated list } if (!is_object($value) && !is_null($value) && $value !== '') { - $paymentpart->thirdparty->{$key} = $value; + $paymentpart->thirdparty->$key = $value; } } } @@ -625,11 +647,11 @@ class BlockedLog } if (!is_object($value) && !is_null($value) && $value !== '') { if ($this->element == 'payment_donation') { - $paymentpart->donation->{$key} = $value; + $paymentpart->donation->$key = $value; } elseif ($this->element == 'payment_various') { - $paymentpart->various->{$key} = $value; + $paymentpart->various->$key = $value; } else { - $paymentpart->invoice->{$key} = $value; + $paymentpart->invoice->$key = $value; } } } @@ -664,21 +686,30 @@ class BlockedLog continue; // Discard if not into a dedicated list } if (!is_object($value) && !is_null($value) && $value !== '') { - $this->object_data->{$key} = $value; + $this->object_data->$key = $value; } } if (!empty($object->newref)) { $this->object_data->ref = $object->newref; } - } else // Generic case - { + } elseif ($this->element == 'stockmouvement') { foreach ($object as $key => $value) { if (in_array($key, $arrayoffieldstoexclude)) { continue; // Discard some properties } if (!is_object($value) && !is_null($value) && $value !== '') { - $this->object_data->{$key} = $value; + $this->object_data->$key = $value; + } + } + } else { + // Generic case + foreach ($object as $key => $value) { + if (in_array($key, $arrayoffieldstoexclude)) { + continue; // Discard some properties + } + if (!is_object($value) && !is_null($value) && $value !== '') { + $this->object_data->$key = $value; } } diff --git a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php index 275fc954ece..502fe33e980 100644 --- a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php +++ b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php @@ -64,9 +64,12 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers } // Test if event/record is qualified - $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol'); - if (!in_array($object->element, $listofqualifiedelement)) { - return 1; + if (empty($conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED) || !in_array($action, explode(',', $conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED))) { + // If custom actions are not set or if action not into custom actions, we can exclude action if object->elementis not valid + $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol'); + if (!in_array($object->element, $listofqualifiedelement)) { + return 1; + } } dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id); @@ -100,7 +103,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers $amounts = (double) $object->amount; } elseif ($action == 'CASHCONTROL_VALIDATE') { $amounts = (double) $object->cash + (double) $object->cheque + (double) $object->card; - } else { + } elseif (property_exists($object, 'total_ttc')) { $amounts = (double) $object->total_ttc; } } @@ -132,7 +135,9 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers return 0; // not implemented action log } - $result = $b->setObjectData($object, $action, $amounts, $user); // Set field date_object, ref_object, fk_object, element, object_data + // Set field date_object, ref_object, fk_object, element, object_data + $result = $b->setObjectData($object, $action, $amounts, $user); + //var_dump($b); exit; if ($result < 0) { $this->error = $b->error; diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 282f09e276e..ac5d612394b 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -1094,6 +1094,13 @@ class MouvementStock extends CommonObject $label .= '
'; $label .= ''.$langs->trans('Label').': '.$this->label; $label .= '
'.$langs->trans('Qty').': '.($this->qty > 0 ? '+' : '').$this->qty; + if ($this->batch) { + $label .= '
'.$langs->trans('Batch').': '.$this->batch; + } + /* TODO Get also warehouse label in a property instead of id + if ($this->warehouse_id > 0) { + $label .= '
'.$langs->trans('Warehouse').': '.$this->warehouse_id; + }*/ $label .= '
'; // Link to page of warehouse tab diff --git a/htdocs/product/stock/tpl/stockcorrection.tpl.php b/htdocs/product/stock/tpl/stockcorrection.tpl.php index 69ae5eda5e0..793c0dcd1e4 100644 --- a/htdocs/product/stock/tpl/stockcorrection.tpl.php +++ b/htdocs/product/stock/tpl/stockcorrection.tpl.php @@ -122,7 +122,7 @@ if ($object->element == 'stock') { print ''.$langs->trans("NumberOfUnit").''; print ''; if ($object->element == 'product' || $object->element == 'stock') { - print ''; print ''; print ''; print '';