Debug log inalterable to allow tracking of stock movement

This commit is contained in:
Laurent Destailleur 2022-12-14 22:04:09 +01:00
parent 1033991486
commit 1102dc272e
4 changed files with 65 additions and 22 deletions

View File

@ -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 '<i class="opacitymedium">'.$langs->trans("BlockedLogEnabled").'</i>';
} 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;
}
}

View File

@ -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;

View File

@ -1094,6 +1094,13 @@ class MouvementStock extends CommonObject
$label .= '<div width="100%">';
$label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
$label .= '<br><b>'.$langs->trans('Qty').':</b> '.($this->qty > 0 ? '+' : '').$this->qty;
if ($this->batch) {
$label .= '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
}
/* TODO Get also warehouse label in a property instead of id
if ($this->warehouse_id > 0) {
$label .= '<br><b>'.$langs->trans('Warehouse').':</b> '.$this->warehouse_id;
}*/
$label .= '</div>';
// Link to page of warehouse tab

View File

@ -122,7 +122,7 @@ if ($object->element == 'stock') {
print '<td class="fieldrequired">'.$langs->trans("NumberOfUnit").'</td>';
print '<td>';
if ($object->element == 'product' || $object->element == 'stock') {
print '<select name="mouvement" id="mouvement" class="minwidth125 valignmiddle">';
print '<select name="mouvement" id="mouvement" class="minwidth100 valignmiddle">';
print '<option value="0">'.$langs->trans("Add").'</option>';
print '<option value="1"'.(GETPOST('mouvement') ? ' selected="selected"' : '').'>'.$langs->trans("Delete").'</option>';
print '</select>';