NEW #22370 Modulebuilder supports 'alwayseditable' (like extrafields)

This commit is contained in:
Laurent Destailleur 2022-09-27 01:05:22 +02:00
parent 4167fab963
commit 5e6e6e1c98
8 changed files with 155 additions and 46 deletions

View File

@ -300,8 +300,34 @@ if ($action == 'update' && !empty($permissiontoadd)) {
}
}
// Action to update one modulebuilder field
$reg = array();
if (preg_match('/^set(\w+)$/', $action, $reg) && GETPOST('id', 'int') > 0 && !empty($permissiontoadd)) {
$object->fetch(GETPOST('id', 'int'));
$keyforfield = $reg[1];
if (property_exists($object, $keyforfield)) {
if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield]['type'], array('date', 'datetime', 'timestamp'))) {
$object->$keyforfield = dol_mktime(GETPOST($keyforfield.'hour'), GETPOST($keyforfield.'min'), GETPOST($keyforfield.'sec'), GETPOST($keyforfield.'month'), GETPOST($keyforfield.'day'), GETPOST($keyforfield.'year'));
} else {
$object->$keyforfield = GETPOST($keyforfield);
}
$result = $object->update($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
$action = 'view';
} else {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit'.$reg[1];
}
}
}
// Action to update one extrafield
if ($action == "update_extras" && !empty($permissiontoadd)) {
if ($action == "update_extras" && GETPOST('id', 'int') > 0 && !empty($permissiontoadd)) {
$object->fetch(GETPOST('id', 'int'));
$attributekey = GETPOST('attribute', 'alpha');

View File

@ -211,7 +211,21 @@ class Form
// Check parameters
if (empty($typeofdata)) {
return 'ErrorBadParameter';
return 'ErrorBadParameter typeofdata is empty';
}
// Clean paramater $typeofdata
if ($typeofdata == 'datetime') {
$typeofdata = 'dayhour';
}
$reg = array();
if (preg_match('/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
if ($reg[1] == 'varchar') {
$typeofdata = 'string';
} elseif ($reg[1] == 'int') {
$typeofdata = 'numeric';
} else {
return 'ErrorBadParameter '.$typeofdata;
}
}
// When option to edit inline is activated

View File

@ -95,7 +95,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
// Edit class files
$contentclass = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r');
// Update ->fields (add or remove entries)
// Update ->fields (to add or remove entries defined into $addfieldentry)
if (count($object->fields)) {
if (is_array($addfieldentry) && count($addfieldentry)) {
$name = $addfieldentry['name'];
@ -133,6 +133,9 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
if (!empty($val['noteditable'])) {
$texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',";
}
if (!empty($val['alwayseditable'])) {
$texttoinsert .= " 'alwayseditable'=>'".$val['alwayseditable']."',";
}
if (!empty($val['default']) || (isset($val['default']) && $val['default'] === '0')) {
$texttoinsert .= " 'default'=>'".$val['default']."',";
}
@ -189,6 +192,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
}
$texttoinsert .= "),\n";
//print $texttoinsert;
}
}
@ -212,14 +216,16 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
$texttoinsert .= "\t".'// END MODULEBUILDER PROPERTIES';
//print($texttoinsert);exit;
//print($texttoinsert);
$contentclass = preg_replace('/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass);
//print $contentclass;
dol_mkdir(dirname($pathoffiletoedittarget));
//file_put_contents($pathoffiletoedittmp, $contentclass);
$result = file_put_contents(dol_osencode($pathoffiletoedittarget), $contentclass);
if ($result) {
@chmod($pathoffiletoedittarget, octdec($newmask));
} else {

View File

@ -64,15 +64,23 @@ foreach ($object->fields as $key => $val) {
print ' tdtop';
}
print '">';
$labeltoshow = '';
if (!empty($val['help'])) {
print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
$labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
} else {
if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
$labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
} else {
print $langs->trans($val['label']);
$labeltoshow .= $langs->trans($val['label']);
}
}
if (empty($val['alwayseditable'])) {
print $labeltoshow;
} else {
print $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
}
print '</td>';
print '<td class="valuefield fieldname_'.$key;
if ($val['type'] == 'text') {
@ -82,25 +90,29 @@ foreach ($object->fields as $key => $val) {
print ' '.$val['cssview'];
}
print '">';
if (in_array($val['type'], array('text', 'html'))) {
print '<div class="longmessagecut">';
}
if ($key == 'lang') {
$langs->load("languages");
$labellang = ($value ? $langs->trans('Language_'.$value) : '');
print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
print $labellang;
} else {
if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
$out = $object->showOutputField($val, $key, $value, '', '', '', 0);
print showValueWithClipboardCPButton($out, 0, $out);
} else {
print $object->showOutputField($val, $key, $value, '', '', '', 0);
if (empty($val['alwayseditable'])) {
if (in_array($val['type'], array('text', 'html'))) {
print '<div class="longmessagecut">';
}
}
//print dol_escape_htmltag($object->$key, 1, 1);
if (in_array($val['type'], array('text', 'html'))) {
print '</div>';
if ($key == 'lang') {
$langs->load("languages");
$labellang = ($value ? $langs->trans('Language_'.$value) : '');
print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
print $labellang;
} else {
if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
$out = $object->showOutputField($val, $key, $value, '', '', '', 0);
print showValueWithClipboardCPButton($out, 0, $out);
} else {
print $object->showOutputField($val, $key, $value, '', '', '', 0);
}
}
//print dol_escape_htmltag($object->$key, 1, 1);
if (in_array($val['type'], array('text', 'html'))) {
print '</div>';
}
} else {
print $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
}
print '</td>';
print '</tr>';
@ -144,10 +156,20 @@ foreach ($object->fields as $key => $val) {
$rightpart .= ' tdtop';
}
$rightpart.= '">';
$labeltoshow = '';
if (!empty($val['help'])) {
$rightpart .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
$labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
} else {
$rightpart .= $langs->trans($val['label']);
if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
$labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
} else {
$labeltoshow .= $langs->trans($val['label']);
}
}
if (empty($val['alwayseditable'])) {
$rightpart .= $labeltoshow;
} else {
$rightpart .= $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
}
$rightpart .= '</td>';
$rightpart .= '<td class="valuefield fieldname_'.$key;
@ -158,14 +180,31 @@ foreach ($object->fields as $key => $val) {
$rightpart .= ' '.$val['cssview'];
}
$rightpart .= '">';
if (in_array($val['type'], array('text', 'html'))) {
$rightpart .= '<div class="longmessagecut">';
}
$rightpart .= $object->showOutputField($val, $key, $value, '', '', '', 0);
//$rightpart .= dol_escape_htmltag($object->$key, 1, 1);
if (in_array($val['type'], array('text', 'html'))) {
$rightpart .= '</div>';
if (empty($val['alwayseditable'])) {
if (in_array($val['type'], array('text', 'html'))) {
$rightpart .= '<div class="longmessagecut">';
}
if ($key == 'lang') {
$langs->load("languages");
$labellang = ($value ? $langs->trans('Language_'.$value) : '');
$rightpart .= picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
$rightpart .= $labellang;
} else {
if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
$out = $object->showOutputField($val, $key, $value, '', '', '', 0);
$rightpart .= showValueWithClipboardCPButton($out, 0, $out);
} else {
$rightpart.= $object->showOutputField($val, $key, $value, '', '', '', 0);
}
}
if (in_array($val['type'], array('text', 'html'))) {
$rightpart .= '</div>';
}
} else {
$rightpart .= $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
}
$rightpart .= '</td>';
$rightpart .= '</tr>';
}

View File

@ -913,6 +913,7 @@ if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray',
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
* 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
* 'noteditable' says if field is not editable (1 or 0)
* 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
* 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
* 'index' if we want an index in database.
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
@ -933,7 +934,7 @@ if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray',
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text'),
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text', 'alwayseditable'=>'1'),
'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirdparty'),
'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
@ -1386,14 +1387,19 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
if (!$error) {
// Edit the class file to write properties
$object = rebuildObjectClass($destdir, $module, $objectname, $newmask);
if (is_numeric($object) && $object < 0) {
if (is_numeric($object) && $object <= 0) {
$pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
$error++;
}
}
if (!$error) {
// Edit sql with new properties
$result = rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
if ($result < 0) {
if ($result <= 0) {
setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null);
$error++;
}
}
@ -1503,6 +1509,7 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
'csslist'=>GETPOST('propcsslist', 'alpha'),
'default'=>GETPOST('propdefault', 'restricthtml'),
'noteditable'=>intval(GETPOST('propnoteditable', 'int')),
'alwayseditable'=>intval(GETPOST('propalwayseditable', 'int')),
'validate' => GETPOST('propvalidate', 'int')
);
@ -1528,6 +1535,8 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
$object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
if (is_numeric($object) && $object <= 0) {
$pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
$error++;
}
}
@ -1537,6 +1546,7 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
$result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
if ($result <= 0) {
setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
$error++;
}
}
@ -1568,7 +1578,10 @@ if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) {
// Edit the class file to write properties
if (!$error) {
$object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
if (is_numeric($object) && $object <= 0) {
$pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
$error++;
}
}
@ -1576,7 +1589,9 @@ if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) {
// Edit sql with new properties
if (!$error) {
$result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
if ($result <= 0) {
setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
$error++;
}
}
@ -2911,6 +2926,7 @@ if ($module == 'initmodule') {
print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).'</th>';
print '<th class="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</th>';
print '<th class="center">'.$langs->trans("NotEditable").'</th>';
print '<th class="center">'.$langs->trans("AlwaysEditable").'</th>';
print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
print '<th class="center">'.$langs->trans("CSSClass").'</th>';
@ -2944,6 +2960,7 @@ if ($module == 'initmodule') {
print '<td class="center"><input type="text" class="center maxwidth50" name="propenabled" value="'.dol_escape_htmltag(GETPOST('propenabled', 'alpha')).'"></td>';
print '<td class="center"><input type="text" class="center maxwidth50" name="propvisible" value="'.dol_escape_htmltag(GETPOST('propvisible', 'alpha')).'"></td>';
print '<td class="center"><input type="text" class="center maxwidth50" name="propnoteditable" value="'.dol_escape_htmltag(GETPOST('propnoteditable', 'alpha')).'"></td>';
print '<td class="center"><input type="text" class="center maxwidth50" name="propalwayseditable" value="'.dol_escape_htmltag(GETPOST('propalwayseditable', 'alpha')).'"></td>';
print '<td class="center"><input type="text" class="center maxwidth50" name="propsearchall" value="'.dol_escape_htmltag(GETPOST('propsearchall', 'alpha')).'"></td>';
print '<td class="center"><input type="text" class="center maxwidth50" name="propisameasure" value="'.dol_escape_htmltag(GETPOST('propisameasure', 'alpha')).'"></td>';
print '<td class="center"><input type="text" class="maxwidth50" name="propcss" value="'.dol_escape_htmltag(GETPOST('propcss', 'alpha')).'"></td>';
@ -2986,6 +3003,7 @@ if ($module == 'initmodule') {
$propenabled = $propval['enabled'];
$propvisible = $propval['visible'];
$propnoteditable = !empty($propval['noteditable'])?$propval['noteditable']:0;
$propalwayseditable = !empty($propval['alwayseditable'])?$propval['alwayseditable']:0;
$propsearchall = !empty($propval['searchall'])?$propval['searchall']:0;
$propisameasure = !empty($propval['isameasure'])?$propval['isameasure']:0;
$propcss = !empty($propval['css'])?$propval['css']:'';
@ -3044,6 +3062,9 @@ if ($module == 'initmodule') {
print '<input class="center" name="propnoteditable" size="2" value="'.dol_escape_htmltag($propnoteditable).'">';
print '</td>';
print '<td>';
print '<input class="center" name="propalwayseditable" size="2" value="'.dol_escape_htmltag($propalwayseditable).'">';
print '</td>';
print '<td>';
print '<input class="center" name="propsearchall" size="2" value="'.dol_escape_htmltag($propsearchall).'">';
print '</td>';
print '<td>';
@ -3110,6 +3131,9 @@ if ($module == 'initmodule') {
print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
print '</td>';
print '<td class="center">';
print $propalwayseditable ? dol_escape_htmltag($propalwayseditable) : '';
print '</td>';
print '<td class="center">';
print $propsearchall ? '1' : '';
print '</td>';
print '<td class="center">';

View File

@ -89,6 +89,7 @@ class MyObject extends CommonObject
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
* 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
* 'noteditable' says if field is not editable (1 or 0)
* 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
* 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
* 'index' if we want an index in database.
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).

View File

@ -105,7 +105,7 @@ class Mo extends CommonObject
'mrptype' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'position'=>34, 'notnull'=>1, 'default'=>'0', 'arrayofkeyval'=>array(0=>'Manufacturing', 1=>'Disassemble'), 'css'=>'minwidth150', 'csslist'=>'minwidth150 center'),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:0', 'label'=>'Product', 'enabled'=>'$conf->product->enabled', 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'comment'=>"Product to produce", 'css'=>'maxwidth300', 'csslist'=>'tdoverflowmax100', 'picto'=>'product'),
'qty' => array('type'=>'real', 'label'=>'QtyToProduce', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>1, 'comment'=>"Qty to produce", 'css'=>'width75', 'default'=>1, 'isameasure'=>1),
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>42, 'notnull'=>-1, 'searchall'=>1, 'showoncombobox'=>'2', 'css'=>'maxwidth300', 'csslist'=>'tdoverflowmax200'),
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>42, 'notnull'=>-1, 'searchall'=>1, 'showoncombobox'=>'2', 'css'=>'maxwidth300', 'csslist'=>'tdoverflowmax200', 'alwayseditable'=>1),
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1', 'label'=>'ThirdParty', 'picto'=>'company', 'enabled'=>'$conf->societe->enabled', 'visible'=>-1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'css'=>'maxwidth400', 'csslist'=>'tdoverflowmax150'),
'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1:fk_statut=1', 'label'=>'Project', 'picto'=>'project', 'enabled'=>'$conf->project->enabled', 'visible'=>-1, 'position'=>51, 'notnull'=>-1, 'index'=>1, 'css'=>'minwidth200 maxwidth400', 'csslist'=>'tdoverflowmax100'),
'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php:0', 'label'=>'WarehouseForProduction', 'picto'=>'stock', 'enabled'=>'$conf->stock->enabled', 'visible'=>1, 'position'=>52, 'css'=>'maxwidth400', 'csslist'=>'tdoverflowmax200'),
@ -116,8 +116,8 @@ class Mo extends CommonObject
'date_valid' => array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-2, 'position'=>502,),
'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'user.rowid', 'csslist'=>'tdoverflowmax100'),
'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'position'=>511, 'notnull'=>-1, 'csslist'=>'tdoverflowmax100'),
'date_start_planned' => array('type'=>'datetime', 'label'=>'DateStartPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>55, 'notnull'=>-1, 'index'=>1, 'help'=>'KeepEmptyForAsap'),
'date_end_planned' => array('type'=>'datetime', 'label'=>'DateEndPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>56, 'notnull'=>-1, 'index'=>1,),
'date_start_planned' => array('type'=>'datetime', 'label'=>'DateStartPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>55, 'notnull'=>-1, 'index'=>1, 'help'=>'KeepEmptyForAsap', 'alwayseditable'=>1),
'date_end_planned' => array('type'=>'datetime', 'label'=>'DateEndPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>56, 'notnull'=>-1, 'index'=>1, 'alwayseditable'=>1),
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,),
'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>2, 'position'=>1000, 'default'=>0, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '2'=>'InProgress', '3'=>'StatusMOProduced', '9'=>'Canceled')),
@ -613,11 +613,9 @@ class Mo extends CommonObject
}
if (!$error) {
setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
$this->db->commit();
return 1;
} else {
setEventMessages($this->error, $this->errors, 'errors');
$this->db->rollback();
return -1;
}
@ -636,8 +634,9 @@ class Mo extends CommonObject
$role = "";
if ($this->status != self::STATUS_DRAFT) {
$this->error = 'BadStatus';
return -1;
//$this->error = 'BadStatusForUpdateProduction';
//return -1;
return 1;
}
$this->db->begin();

View File

@ -136,7 +136,7 @@ if (empty($reshook)) {
}
$triggermodname = 'MRP_MO_MODIFY'; // Name of trigger action code to execute when we modify record
//Create MO with Childs
// Create MO with Childs
if ($action == 'add' && empty($id) && !empty($TBomLineId)) {
$noback = 1;
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
@ -165,7 +165,7 @@ if (empty($reshook)) {
$res = $object->add_object_linked('mo', $mo_parent->id);
}
header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.$moline->fk_mo, 1));
header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.((int) $moline->fk_mo), 1));
exit;
}