diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index 78576e4c00d..7a708e412c7 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -587,6 +587,7 @@ if ($resql)
$arrayofmassactions=array(
'validate'=>$langs->trans("Validate"),
+ 'generate_doc'=>$langs->trans("Generate"),
'presend'=>$langs->trans("SendByMail"),
'builddoc'=>$langs->trans("PDFMerge"),
);
diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php
index 2bb55264cf9..91ff96a6b00 100644
--- a/htdocs/core/actions_massactions.inc.php
+++ b/htdocs/core/actions_massactions.inc.php
@@ -1130,6 +1130,67 @@ if (! $error && ($massaction == 'delete' || ($action == 'delete' && $confirm ==
//var_dump($listofobjectthirdparties);exit;
}
+// Generate document foreach object according to model linked to object
+// @TODO : propose model selection
+if (! $error && $massaction == 'generate_doc' && $permtoread)
+{
+ $db->begin();
+
+ $objecttmp=new $objectclass($db);
+ $nbok = 0;
+ foreach($toselect as $toselectid)
+ {
+ $result=$objecttmp->fetch($toselectid);
+ if ($result > 0)
+ {
+ $outputlangs = $langs;
+ $newlang='';
+
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang=$objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ...
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang=$objecttmp->default_lang; // for thirdparty
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+
+ // To be sure vars is defined
+ if (empty($hidedetails)) $hidedetails=0;
+ if (empty($hidedesc)) $hidedesc=0;
+ if (empty($hideref)) $hideref=0;
+ if (empty($moreparams)) $moreparams=null;
+
+ $result= $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
+
+ if ($result <= 0)
+ {
+ setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
+ $error++;
+ break;
+ }
+ else $nbok++;
+ }
+ else
+ {
+ setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
+ $error++;
+ break;
+ }
+ }
+
+ if (! $error)
+ {
+ if ($nbok > 1) setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs');
+ else setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs');
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+}
+
$parameters['toselect']=$toselect;
$parameters['uploaddir']=$uploaddir;
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index fb2f2a8e9fb..2846434f460 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -86,6 +86,7 @@ GoToWikiHelpPage=Read online help (Internet access needed)
GoToHelpPage=Read help
RecordSaved=Record saved
RecordDeleted=Record deleted
+RecordGenerated=Record generated
LevelOfFeature=Level of features
NotDefined=Not defined
DolibarrInHttpAuthenticationSoPasswordUseless=Dolibarr authentication mode is set to %s in configuration file conf.php.
This means that the password database is external to Dolibarr, so changing this field may have no effect.
@@ -649,6 +650,7 @@ RecordCreatedSuccessfully=Record created successfully
RecordModifiedSuccessfully=Record modified successfully
RecordsModified=%s record modified
RecordsDeleted=%s record deleted
+RecordsGenerated=%s record generated
AutomaticCode=Automatic code
FeatureDisabled=Feature disabled
MoveBox=Move widget