Debug modulebuilder

This commit is contained in:
Laurent Destailleur 2019-06-03 18:11:53 +02:00
parent 6c6c353177
commit 72f55e1d81
6 changed files with 92 additions and 72 deletions

View File

@ -141,6 +141,7 @@ if (empty($reshook))
if ($result <= 0)
{
setEventMessages($bomline->error, $bomline->errors, 'errors');
$action = '';
}
}
}
@ -386,7 +387,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if (! empty($object->lines))
{
// $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
$object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
}
// Form to add new line
@ -395,7 +396,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if ($action != 'editline')
{
// Add products/services form
$object->formAddObjectLine(1, $mysoc, $soc, '/bom/tpl');
$object->formAddObjectLine(1, $mysoc, null, '/bom/tpl');
$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

View File

@ -94,9 +94,9 @@ class BOM extends CommonObject
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'noteditable'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of BOM", 'showoncombobox'=>'1',),
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'notnull'=>1, 'searchall'=>1, 'showoncombobox'=>'1',),
'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'notnull'=>-1,),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>50, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp'),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp'),
'qty' => array('type'=>'real', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>55, 'notnull'=>1, 'isameasure'=>'1', 'css'=>'maxwidth75imp'),
'efficiency' => array('type'=>'real', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>100, 'notnull'=>0, 'css'=>'maxwidth50imp', 'help'=>'ValueOfMeansLoss'),
'efficiency' => array('type'=>'real', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>-1, 'default'=>1, 'position'=>100, 'notnull'=>0, 'css'=>'maxwidth50imp', 'help'=>'ValueOfMeansLoss'),
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>-1, 'position'=>161, 'notnull'=>-1,),
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>-1, 'position'=>162, 'notnull'=>-1,),
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>300, 'notnull'=>1,),
@ -291,27 +291,8 @@ class BOM extends CommonObject
{
$this->lines=array();
// Load lines with object BOMLine
$sql = 'SELECT rowid, fk_product, description, qty, rank WHERE fk_bom = '.$this->id;
$resql=$this->db->query($sql);
if ($resql)
{
$obj = $this->db->fetch_object($resql);
if ($obj)
{
$newline = new BOMLine($this->db);
$newline->id = $obj->rowid;
$newline->fk_product = $obj->fk_product;
$newline->description = $obj->description;
$newline->qty = $obj->qty;
$newline->rank = $obj->rank;
$this->lines[] = $newline;
}
}
return count($this->lines)?1:0;
$result = $this->fetchLinesCommon();
return $result;
}
/**
@ -333,11 +314,11 @@ class BOM extends CommonObject
$records=array();
$sql = 'SELECT';
$sql .= ' t.rowid';
// TODO Get all fields
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' WHERE t.entity = '.$conf->entity;
if ($this->ismultientitymanaged) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
@ -374,11 +355,8 @@ class BOM extends CommonObject
while ($obj = $this->db->fetch_object($resql))
{
$record = new self($this->db);
$record->setVarsFromFetchObj($obj);
$record->id = $obj->rowid;
// TODO Get other fields
//var_dump($record->id);
$records[$record->id] = $record;
}
$this->db->free($resql);
@ -858,7 +836,7 @@ class BOM extends CommonObject
$this->lines=array();
$objectline = new BOMLine($this->db);
$result = $objectline->fetchAll('', '', 0, 0, array('fk_bom'=>$this->id));
$result = $objectline->fetchAll('', '', 0, 0, array('customsql'=>'fk_bom = '.$this->id));
if (is_numeric($result))
{
@ -869,7 +847,7 @@ class BOM extends CommonObject
else
{
$this->lines = $result;
return $this->lines();
return $this->lines;
}
}
@ -1139,11 +1117,11 @@ class BOMLine extends CommonObject
$records=array();
$sql = 'SELECT';
$sql .= ' t.rowid';
// TODO Get all fields
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' WHERE t.entity = '.$conf->entity;
if ($this->ismultientitymanaged) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
@ -1180,11 +1158,8 @@ class BOMLine extends CommonObject
while ($obj = $this->db->fetch_object($resql))
{
$record = new self($this->db);
$record->setVarsFromFetchObj($obj);
$record->id = $obj->rowid;
// TODO Get other fields
//var_dump($record->id);
$records[$record->id] = $record;
}
$this->db->free($resql);

View File

@ -32,8 +32,8 @@ if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtas
{
if (($id > 0 && is_numeric($id)) || ! empty($ref)) // To discard case when id is list of ids like '1,2,3...'
{
$ret = $object->fetch($id, $ref);
if ($ret > 0)
$ret = $object->fetch($id, $ref);
if ($ret > 0)
{
$object->fetch_thirdparty();
$id = $object->id;

View File

@ -4103,7 +4103,7 @@ abstract class CommonObject
// Define output language and label
if (! empty($conf->global->MAIN_MULTILANGS))
{
if (! is_object($this->thirdparty))
if (property_exists($this, 'socid') && ! is_object($this->thirdparty))
{
dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
return;
@ -4115,7 +4115,7 @@ abstract class CommonObject
$outputlangs = $langs;
$newlang='';
if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang=GETPOST('lang_id', 'aZ09');
if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer
if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) $newlang=$this->thirdparty->default_lang; // To use language of customer
if (! empty($newlang))
{
$outputlangs = new Translate("", $conf);
@ -7370,6 +7370,56 @@ abstract class CommonObject
}
}
/**
* Load object in memory from the database
*
* @param string $morewhere More SQL filters (' AND ...')
* @return int <0 if KO, 0 if not found, >0 if OK
*/
public function fetchLinesCommon($morewhere = '')
{
$objectlineclassname = get_class($this).'Line';
if (! class_exists($objectlineclassname))
{
$this->error = 'Error, class '.$objectlineclassname.' not found during call of fetchLinesCommon';
return -1;
}
$objectline = new $objectlineclassname($this->db);
$sql = 'SELECT '.$objectline->getFieldList();
$sql.= ' FROM '.MAIN_DB_PREFIX.$objectline->table_element;
$sql.=' WHERE fk_'.$this->element.' = '.$this->id;
if ($morewhere) $sql.= $morewhere;
$resql = $this->db->query($sql);
if ($resql)
{
$num_rows = $this->db->num_rows($resql);
$i = 0;
while ($i < $num_rows)
{
$obj = $this->db->fetch_object($resql);
if ($obj)
{
$newline = new $objectlineclassname($this->db);
$newline->setVarsFromFetchObj($obj);
$this->lines[] = $newline;
}
$i++;
}
return 1;
}
else
{
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
return -1;
}
}
/**
* Update object into database
*

View File

@ -42,6 +42,11 @@ class MyObject extends CommonObject
*/
public $table_element = 'mymodule_myobject';
/**
* @var string Name of subtable if this object has sub lines
*/
//public $table_element_line = 'mymodule_myobjectline';
/**
* @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
*/
@ -327,14 +332,14 @@ class MyObject extends CommonObject
*
* @return int <0 if KO, 0 if not found, >0 if OK
*/
/*public function fetchLines()
public function fetchLines()
{
$this->lines=array();
// Load lines with object MyObjectLine
$result = $this->fetchLinesCommon();
return $result;
}
return count($this->lines)?1:0;
}*/
/**
* Load list of objects in memory from the database.
@ -355,11 +360,11 @@ class MyObject extends CommonObject
$records=array();
$sql = 'SELECT';
$sql .= ' t.rowid';
// TODO Get all fields
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' WHERE t.entity = '.$conf->entity;
if ($this->ismultientitymanaged) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
@ -398,11 +403,8 @@ class MyObject extends CommonObject
$obj = $this->db->fetch_object($resql);
$record = new self($this->db);
$record->setVarsFromFetchObj($obj);
$record->id = $obj->rowid;
// TODO Get other fields
//var_dump($record->id);
$records[$record->id] = $record;
$i++;
@ -649,8 +651,8 @@ class MyObject extends CommonObject
{
$this->lines=array();
$objectline = new BOMLine($this->db);
$result = $objectline->fetchAll('', '', 0, 0, array('fk_myobject'=>$this->id));
$objectline = new MyObjectLine($this->db);
$result = $objectline->fetchAll('', '', 0, 0, array('customsql'=>'fk_myobject = '.$this->id));
if (is_numeric($result))
{
@ -661,7 +663,7 @@ class MyObject extends CommonObject
else
{
$this->lines = $result;
return $this->lines();
return $this->lines;
}
}
@ -699,14 +701,7 @@ class MyObject extends CommonObject
/**
* Class MyObjectLine. You can also remove this and generate a CRUD class for lines objects.
*/
/*
class MyObjectLine
{
// @var int ID
public $id;
// @var mixed Sample line property 1
public $prop1;
// @var mixed Sample line property 2
public $prop2;
// To complete with content of an object MyObjectLine
}
*/

View File

@ -389,8 +389,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if (! empty($object->lines))
{
// printObjectLines return void
$object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
$object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
}
// Form to add new line