~openupgrade-committers/openupgrade-server/5.0

« back to all changes in this revision

Viewing changes to bin/addons/openupgrade_records/model/openupgrade_record.py

  • Committer: Stefan Rijnhart
  • Date: 2012-05-27 12:24:43 UTC
  • mfrom: (2175.1.3 openupgrade-server)
  • Revision ID: stefan@therp.nl-20120527122443-7lh1cvrm26wt8u6e
[MRG] Add openupgrade development module for easy analysis file generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    This module Copyright (C) 2012 OpenUpgrade community
 
6
#    https://launchpad.net/~openupgrade-committers
 
7
#
 
8
#    Contributors:
 
9
#    Therp BV <http://therp.nl>
 
10
#
 
11
#    This program is free software: you can redistribute it and/or modify
 
12
#    it under the terms of the GNU Affero General Public License as
 
13
#    published by the Free Software Foundation, either version 3 of the
 
14
#    License, or (at your option) any later version.
 
15
#
 
16
#    This program is distributed in the hope that it will be useful,
 
17
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
#    GNU Affero General Public License for more details.
 
20
#
 
21
#    You should have received a copy of the GNU Affero General Public License
 
22
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
23
#
 
24
##############################################################################
 
25
 
 
26
from osv import osv, fields
 
27
 
 
28
# Cannot use forward references in 6.0
 
29
class openupgrade_record(osv.osv):
 
30
    _name = 'openupgrade.record'
 
31
openupgrade_record()
 
32
 
 
33
class openupgrade_attribute(osv.osv):
 
34
    _name = 'openupgrade.attribute'
 
35
    _rec_name = 'attribute_id'
 
36
    _columns = {
 
37
        'name': fields.char(
 
38
            'Name', size=24,
 
39
            readonly=True,
 
40
            ),
 
41
        'value': fields.char(
 
42
            'Value',
 
43
            size=4096,
 
44
            readonly=True,
 
45
            ),
 
46
        'record_id': fields.many2one(
 
47
            'openupgrade.record', ondelete='CASCADE',
 
48
            readonly=True,
 
49
            ),
 
50
        }
 
51
openupgrade_attribute()
 
52
 
 
53
class openupgrade_record(osv.osv):
 
54
    _inherit = 'openupgrade.record'
 
55
 
 
56
    _columns = {
 
57
        'name': fields.char('Name', size=256, readonly=True),
 
58
        'module': fields.char('Module', size=128, readonly=True),
 
59
        'model': fields.char('Model', size=128, readonly=True),
 
60
        'field': fields.char('Field', size=128, readonly=True),
 
61
        'mode': fields.selection(
 
62
            [('create', 'Create'), ('modify', 'Modify')],
 
63
            'Mode',
 
64
            help='Set to Create if a field is newly created '
 
65
            'in this module. If this module modifies an attribute of an '
 
66
            'exting field, set to Modify.',
 
67
            readonly=True,
 
68
             ),
 
69
        'type': fields.selection(
 
70
            [('field', 'Field'), ('xmlid', 'XML ID')],
 
71
            'Type',
 
72
            readonly=True,
 
73
            ),
 
74
        'attribute_ids': fields.one2many(
 
75
            'openupgrade.attribute', 'record_id', 'Attributes',
 
76
            readonly=True,
 
77
            ),
 
78
        }
 
79
    def field_dump(self, cr, uid, context=None):
 
80
        keys = [
 
81
            'module',
 
82
            'mode',
 
83
            'model',
 
84
            'field',
 
85
            'type',
 
86
            'isfunction',
 
87
            'relation',
 
88
            'required',
 
89
            'selection_keys',
 
90
            'req_default',
 
91
            'inherits',
 
92
            ]
 
93
 
 
94
        template = dict([(x, False) for x in keys])
 
95
        ids = self.search(cr, uid, [('type', '=', 'field')], context=context)
 
96
        records = self.browse(cr, uid, ids, context=context)
 
97
        data = []
 
98
        for record in records:
 
99
            repr = template.copy()
 
100
            repr.update({
 
101
                    'module': record.module,
 
102
                    'model': record.model,
 
103
                    'field': record.field,
 
104
                    'mode': record.mode,
 
105
                    })
 
106
            repr.update(
 
107
                dict([(x.name, x.value) for x in record.attribute_ids]))
 
108
            data.append(repr)
 
109
        return data
 
110
 
 
111
openupgrade_record()