Changeset 400 for trunk/temp/MakeOpenERP.php
- Timestamp:
- Mar 27, 2012, 4:11:51 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/temp/MakeOpenERP.php
r399 r400 37 37 38 38 $Database->select_db('information_schema'); 39 40 // Load all constraints 41 $Constraints = array(); 42 $DbResult = $Database->query('SELECT * FROM `KEY_COLUMN_USAGE` WHERE `TABLE_SCHEMA` = "centrala" AND 43 `REFERENCED_TABLE_NAME` IS NOT NULL'); 44 while($DbRow = $DbResult->fetch_assoc()) 45 { 46 $Constraints[strtolower($DbRow['TABLE_NAME'].'.'.$DbRow['COLUMN_NAME'])] = 47 strtolower($DbRow['REFERENCED_TABLE_NAME'].'.'.$DbRow['REFERENCED_COLUMN_NAME']); 48 } 49 39 50 $DbResult = $Database->query('SELECT * FROM `TABLES` WHERE `TABLE_SCHEMA` = "centrala"'); 40 51 while($DbRow = $DbResult->fetch_assoc()) … … 53 64 $Type = $DbRow2['DATA_TYPE']; 54 65 $Name = $DbRow2['COLUMN_NAME']; 55 56 $ColDef = " '".$Name."': fields."; 66 if($Name != 'Id') 67 { 68 $ColDef = " '".strtolower($Name)."': fields."; 57 69 if($Type == 'varchar') 58 70 $ColDef .= "char('".$Name."', size=".$DbRow2['CHARACTER_MAXIMUM_LENGTH'].", translate=True"; … … 61 73 else if($Type == 'date') 62 74 $ColDef .= "date('".$DbRow2['COLUMN_NAME']."'"; 63 else if($Type == 'int') 64 $ColDef .= "integer('".$DbRow2['COLUMN_NAME']."'"; 65 else if($Type == 'tinyint') 66 $ColDef .= "integer('".$DbRow2['COLUMN_NAME']."'"; 67 else if($Type == 'smallint') 68 $ColDef .= "integer('".$DbRow2['COLUMN_NAME']."'"; 75 else if(($Type == 'int') or ($Type == 'tinyint') or ($Type == 'smallint')) 76 { 77 if(array_key_exists(strtolower($DbRow2['TABLE_NAME'].'.'.$DbRow2['COLUMN_NAME']), $Constraints)) 78 { 79 $Constraint = $Constraints[strtolower($DbRow2['TABLE_NAME'].'.'.$DbRow2['COLUMN_NAME'])]; 80 $SourceTable = substr($Constraint, 0, strpos($Constraint, '.')); 81 $SourceColumn = substr($Constraint, strpos($Constraint, '.') + 1); 82 $ColDef .= "many2one('centrala.".$SourceTable."', '".$DbRow2['COLUMN_NAME']."'"; 83 } else 84 $ColDef .= "integer('".$DbRow2['COLUMN_NAME']."'"; 85 } 69 86 else if($Type == 'enum') 70 87 $ColDef .= "integer('".$DbRow2['COLUMN_NAME']."'"; … … 78 95 $ColDef .= "float('".$DbRow2['COLUMN_NAME']."', digits=(12,6)"; 79 96 else echo('Neznamy typ '.$Type); 97 $ColDef .= "),\n"; 98 $ModelColumns .= $ColDef; 99 $ViewTreeItems .= "\n".' <field name="'.strtolower($Name).'" select="1"/>'; 100 $ViewFormItems .= "\n".' <field name="'.strtolower($Name).'" select="1"/>'; 101 } 102 } 103 // Add one2many relations 104 foreach($Constraints as $Index => $Item) 105 { 106 //echo($Item.'='.strtolower($DbRow['TABLE_NAME']).'.Id '); 107 if($Item == strtolower($DbRow['TABLE_NAME']).'.id') 108 { 109 $SourceTable = substr($Index, 0, strpos($Index, '.')); 110 $SourceColumn = substr($Index, strpos($Index, '.') + 1); 111 $ColDef = " '".strtolower($SourceTable.'_ids')."': fields."; 112 $ColDef .= "one2many('centrala.".$SourceTable."', '".$SourceColumn."', '".$SourceTable."'"; 113 $ColDef .= "),\n"; 114 $ModelColumns .= $ColDef; 115 $ViewFormItems .= "\n".' <field name="'.strtolower($SourceTable.'_ids').'" select="1"/>'; 116 } 117 } 80 118 81 $ColDef .= "),\n";82 $ViewTreeItems .= "\n".' <field name="'.$Name.'" select="1"/>';83 $ViewFormItems .= "\n".' <field name="'.$Name.'" select="1"/>';84 $ModelColumns .= $ColDef;85 }86 119 $ModuleView .= ' 87 120 <record model="ir.actions.act_window" id="action_'.$TableName.'_form">
Note:
See TracChangeset
for help on using the changeset viewer.