2
0
forked from Wavyzz/dolibarr

Fix test to execute workflow actions. Add more info in trigger errors.

This commit is contained in:
Laurent Destailleur
2024-02-10 21:25:26 +01:00
parent c27774463f
commit 9abdc1229a
5 changed files with 132 additions and 114 deletions

View File

@@ -216,6 +216,8 @@ $workflowcodes = array_filter($workflowcodes, function ($var) {
return $var['enabled'];
});
/*
* View
*/

View File

@@ -38,6 +38,11 @@ class Interfaces
public $dir; // Directory with all core and external triggers files
/**
* @var string Last module name in error
*/
public $lastmoduleerror;
/**
* @var string[] Error codes (or messages)
*/
@@ -90,13 +95,13 @@ class Interfaces
}
$nbfile = $nbtotal = $nbok = $nbko = 0;
$this->lastmoduleerror = '';
$files = array();
$modules = array();
$orders = array();
$i = 0;
$dirtriggers = array_merge(array('/core/triggers'), $conf->modules_parts['triggers']);
foreach ($dirtriggers as $reldir) {
$dir = dol_buildpath($reldir, 0);
@@ -215,6 +220,7 @@ class Interfaces
//dol_syslog("Error in trigger ".$action." - result = ".$result." - Nb of error string returned = ".count($objMod->errors), LOG_ERR);
$nbtotal++;
$nbko++;
$this->lastmoduleerror = $modName;
if (!empty($objMod->errors)) {
$this->errors = array_merge($this->errors, $objMod->errors);
} elseif (!empty($objMod->error)) {
@@ -228,7 +234,7 @@ class Interfaces
}
if ($nbko) {
dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko." - Nb of error string returned in this->errors = ".count($this->errors), LOG_ERR);
dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko.($this->lastmoduleerror ? " - Last module in error: ".$this->lastmoduleerror : "")." - Nb of error string returned in this->errors = ".count($this->errors), LOG_ERR);
return -$nbko;
} else {
//dol_syslog(get_class($this)."::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG);

View File

@@ -368,9 +368,12 @@ class InterfaceWorkflowManager extends DolibarrTriggers
) {
$qtyshipped = array();
$qtyordred = array();
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
// Find all shipments on order origin
// The original sale order is id in $object->origin_id
// Find all shipments on sale order origin
if (($object->origin == 'order' || $object->origin = 'commande') && $object->origin_id > 0) {
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
$order = new Commande($this->db);
$ret = $order->fetch($object->origin_id);
if ($ret < 0) {
@@ -425,12 +428,13 @@ class InterfaceWorkflowManager extends DolibarrTriggers
}
}
}
}
// If we validate or close a shipment
if (($action == 'RECEPTION_VALIDATE') || ($action == 'RECEPTION_CLOSED')) {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ((isModEnabled("fournisseur") || isModEnabled("supplier_order")) && isModEnabled("reception") && !empty($conf->workflow->enabled) &&
if ((isModEnabled("fournisseur") || isModEnabled("supplier_order")) && isModEnabled("reception") && isModEnabled('workflow') &&
(
(getDolGlobalString('WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION') && ($action == 'RECEPTION_VALIDATE')) ||
(getDolGlobalString('WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION_CLOSED') && ($action == 'RECEPTION_CLOSED'))
@@ -438,9 +442,12 @@ class InterfaceWorkflowManager extends DolibarrTriggers
) {
$qtyshipped = array();
$qtyordred = array();
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
// The original purchase order is id in $object->origin_id
// Find all reception on purchase order origin
if (($object->origin == 'order_supplier' || $object->origin == 'supplier_order' || $object->origin = 'commandeFournisseur') && $object->origin_id > 0) {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
$order = new CommandeFournisseur($this->db);
$ret = $order->fetch($object->origin_id);
if ($ret < 0) {
@@ -452,6 +459,7 @@ class InterfaceWorkflowManager extends DolibarrTriggers
$this->setErrorsFromObject($order);
return $ret;
}
// Build array of quantity received by product for a purchase order
if (is_array($order->linkedObjects) && count($order->linkedObjects) > 0) {
foreach ($order->linkedObjects as $type => $shipping_array) {
@@ -495,6 +503,7 @@ class InterfaceWorkflowManager extends DolibarrTriggers
}
}
}
}
if ($action == 'TICKET_CREATE') {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);

View File

@@ -5357,6 +5357,7 @@ class Societe extends CommonObject
}
// Merge categories
include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$static_cat = new Categorie($this->db);
$custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');

View File

@@ -163,10 +163,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
*
* Check that a Reception object can be fetched from database.
*
* @param $id The id of an existing Reception object to fetch.
* @param int $id The id of an existing Reception object to fetch.
* @return Reception $localobject
*
* @depends testReceptionCreate
* @return Reception $localobject
*/
public function testReceptionFetch($id)
{
@@ -185,10 +185,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
*
* Check that a Reception object can be updated.
*
* @param $localobject An existing Reception object to update.
* @param Object $localobject An existing Reception object to update.
* @return Reception a Reception object with data fetched and name changed
*
* @depends testReceptionFetch
* @return Reception a Reception object with data fetched and name changed
*/
public function testReceptionUpdate($localobject)
{
@@ -209,10 +209,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
* Check that a Reception with status == Reception::STATUS_DRAFT can be
* re-opened with the Reception::reOpen() function.
*
* @param $localobject An existing Reception object to validate.
* @param Object $localobject An existing Reception object to validate.
* @return Reception a Reception object with data fetched and STATUS_VALIDATED
*
* @depends testReceptionUpdate
* @return Reception a Reception object with data fetched and STATUS_VALIDATED
*/
public function testReceptionValid($localobject)
{
@@ -249,10 +249,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
* Check that a Reception can be closed with the Reception::setClosed()
* function, after it has been validated.
*
* @param $localobject An existing validated Reception object to close.
* @param Object $localobject An existing validated Reception object to close.
* @return Reception a Reception object with data fetched and STATUS_CLOSED
*
* @depends testReceptionValid
* @return Reception a Reception object with data fetched and STATUS_CLOSED
*/
public function testReceptionSetClosed($localobject)
{
@@ -302,10 +302,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
* Check that a Reception with status == Reception::STATUS_CLOSED can be
* re-opened with the Reception::reOpen() function.
*
* @param $localobject An existing closed Reception object to re-open.
* @param Object $localobject An existing closed Reception object to re-open.
* @return Reception A Reception object with data fetched and STATUS_VALIDATED
*
* @depends testReceptionSetClosed
* @return Reception a Reception object with data fetched and STATUS_VALIDATED
*/
public function testReceptionReOpen($localobject)
{
@@ -338,10 +338,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
* Check that a Reception with status == Reception::STATUS_CLOSED can be
* re-opened with the Reception::reOpen() function.
*
* @param $localobject An existing validated Reception object to mark as Draft.
* @param Object $localobject An existing validated Reception object to mark as Draft.
* @return Reception A Reception object with data fetched and STATUS_DRAFT
*
* @depends testReceptionReOpen
* @return Reception a Reception object with data fetched and STATUS_DRAFT
*/
public function testReceptionSetDraft($localobject)
{
@@ -376,10 +376,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
* Check that a Reception referencing a Societe object being merged into
* another is correctly migrated to use the new Societe object.
*
* @param $localobject An existing validated Reception object to mark as Draft.
* @param Object $localobject An existing validated Reception object to mark as Draft.
* @return Reception A Reception object with data fetched
*
* @depends testReceptionSetDraft
* @return Reception a Reception object with data fetched
*/
public function testReceptionMergeCompanies($localobject)
{
@@ -405,10 +405,10 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
*
* Check that a Reception object can be deleted.
*
* @param $localobject An existing Reception object to delete.
* @param Object $localobject An existing Reception object to delete.
* @return int The result of the delete operation
*
* @depends testReceptionReOpen
* @return int the result of the delete operation
*/
public function testReceptionDelete($localobject)
{