Merge pull request #20392 from thomas-Ngr/develop_fix_ticket_workflow_create_ficheinter_from_public_interface

Fix: ticket/workflow: automatically create ficheinter
This commit is contained in:
Laurent Destailleur 2022-04-05 15:08:10 +02:00 committed by GitHub
commit 2303553fd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 25 deletions

View File

@ -71,6 +71,12 @@ $workflowcodes = array(
'enabled'=>(!empty($conf->commande->enabled) && !empty($conf->facture->enabled)),
'picto'=>'bill'
),
'WORKFLOW_TICKET_CREATE_INTERVENTION' => array (
'family'=>'create',
'position'=>25,
'enabled'=>(!empty($conf->ticket->enabled) && !empty($conf->ficheinter->enabled)),
'picto'=>'ticket'
),
'separator1'=>array('family'=>'separator', 'position'=>25, 'title'=>''),

View File

@ -95,7 +95,8 @@ class modWorkflow extends DolibarrModules
8=>array('WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER', 'chaine', '1', 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER', 0, 'current', 0),
9=>array('WORKFLOW_BILL_ON_RECEPTION', 'chaine', '1', 'WORKFLOW_BILL_ON_RECEPTION', 0, 'current', 0),
10=>array('WORKFLOW_TICKET_LINK_CONTRACT', 'chaine', '0', 'Automatically link a ticket to available contracts', 0, 'current', 0),
11=>array('WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS', 'chaine', '0', 'Search among parent companies contracts when automatically linking a ticket to available contracts', 0, 'current', 0)
11=>array('WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS', 'chaine', '0', 'Search among parent companies contracts when automatically linking a ticket to available contracts', 0, 'current', 0),
11=>array('WORKFLOW_TICKET_CREATE_INTERVENTION', 'chaine', '1', 'WORKFLOW_TICKET_CREATE_INTERVENTION', 0, 'current', 0)
);
// Boxes

View File

@ -435,7 +435,6 @@ class InterfaceWorkflowManager extends DolibarrTriggers
$number_contracts_found = 0;
foreach ($company_ids as $company_id) {
$contrat->socid = $company_id;
$list = $contrat->getListOfContracts($option = 'all', $status = [Contrat::STATUS_DRAFT, Contrat::STATUS_VALIDATED], $product_categories = [$conf->global->TICKET_PRODUCT_CATEGORY], $line_status = [ContratLigne::STATUS_INITIAL, ContratLigne::STATUS_OPEN]);
if (is_array($list) && !empty($list)) {
$number_contracts_found = count($list);
@ -457,6 +456,28 @@ class InterfaceWorkflowManager extends DolibarrTriggers
if (empty(NOLOGIN)) setEventMessage($langs->trans('TicketNoContractFoundToLink'), 'mesgs');
}
}
// Automatically create intervention
if (!empty($conf->ficheinter->enabled) && !empty($conf->ticket->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_TICKET_CREATE_INTERVENTION)) {
$fichinter = new Fichinter($this->db);
$fichinter->socid = (int) $object->fk_soc;
$fichinter->fk_project = $projectid;
$fichinter->fk_contrat = (int) $object->fk_contract;
$fichinter->author = $user->id;
$fichinter->model_pdf = (!empty($conf->global->FICHEINTER_ADDON_PDF)) ? $conf->global->FICHEINTER_ADDON_PDF : 'soleil';
$fichinter->origin = $object->element;
$fichinter->origin_id = $object->id;
// Extrafields
$extrafields = new ExtraFields($this->db);
$extrafields->fetch_name_optionals_label($fichinter->table_element);
$array_options = $extrafields->getOptionalsFromPost($fichinter->table_element);
$fichinter->array_options = $array_options;
$id = $fichinter->create($user);
if ($id <= 0) {
setEventMessages($fichinter->error, null, 'errors');
}
}
}
return 0;
}

View File

@ -255,7 +255,7 @@ class Fichinter extends CommonObject
}
if ($this->socid <= 0) {
$this->error = 'ErrorBadParameterForFunc';
$this->error = 'ErrorFicheinterCompanyDoesNotExist';
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
return -1;
}

View File

@ -117,6 +117,7 @@ INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) value
ALTER TABLE llx_ticket ADD COLUMN date_last_msg_sent datetime AFTER date_read;
UPDATE llx_const SET name = 'WORKFLOW_TICKET_LINK_CONTRACT' WHERE name = 'TICKET_AUTO_ASSIGN_CONTRACT_CREATE';
UPDATE llx_const SET name = 'WORKFLOW_TICKET_CREATE_INTERVENTION' WHERE name = 'TICKET_AUTO_CREATE_FICHINTER_CREATE';
CREATE TABLE llx_stock_mouvement_extrafields (
rowid integer AUTO_INCREMENT PRIMARY KEY,

View File

@ -67,3 +67,4 @@ ToCreateAPredefinedIntervention=To create a predefined or recurring intervention
ConfirmReopenIntervention=Are you sure you want to open back the intervention <b>%s</b>?
GenerateInter=Generate intervention
FichinterNoContractLinked=Intervention %s has been created without a linked contract.
ErrorFicheinterCompanyDoesNotExist=Company does not exist. Intervention has not been created.

View File

@ -7,6 +7,7 @@ descWORKFLOW_PROPAL_AUTOCREATE_ORDER=Automatically create a sales order after a
descWORKFLOW_PROPAL_AUTOCREATE_INVOICE=Automatically create a customer invoice after a commercial proposal is signed (the new invoice will have same amount as the proposal)
descWORKFLOW_CONTRACT_AUTOCREATE_INVOICE=Automatically create a customer invoice after a contract is validated
descWORKFLOW_ORDER_AUTOCREATE_INVOICE=Automatically create a customer invoice after a sales order is closed (the new invoice will have same amount as the order)
descWORKFLOW_TICKET_CREATE_INTERVENTION=On ticket creation, automatically create an intervention.
# Autoclassify customer proposal or order
descWORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL=Classify linked source proposal as billed when sales order is set to billed (and if the amount of the order is the same as the total amount of the signed linked proposal)
descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal as billed when customer invoice is validated (and if the amount of the invoice is the same as the total amount of the signed linked proposal)

View File

@ -254,28 +254,6 @@ if (empty($reshook)) {
$result = $object->assignUser($user, $user->id, 1);
$object->add_contact($user->id, "SUPPORTTEC", 'internal');
}
// Auto create fiche intervention
if (!empty($conf->global->TICKET_AUTO_CREATE_FICHINTER_CREATE)) {
$fichinter = new Fichinter($db);
$fichinter->socid = $object->fk_soc;
$fichinter->fk_project = $projectid;
$fichinter->fk_contrat = $object->fk_contract;
$fichinter->author = $user->id;
$fichinter->model_pdf = 'soleil';
$fichinter->origin = $object->element;
$fichinter->origin_id = $object->id;
// Extrafields
$extrafields->fetch_name_optionals_label($fichinter->table_element);
$array_options = $extrafields->getOptionalsFromPost($fichinter->table_element);
$fichinter->array_options = $array_options;
$id = $fichinter->create($user);
if ($id <= 0) {
setEventMessages($fichinter->error, null, 'errors');
}
}
}
if (!$error) {