~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to letter/letter.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# $Id: letter.py 1304 2005-09-08 14:35:42Z nicoe $
 
7
#
 
8
# WARNING: This program as such is intended to be used by professional
 
9
# programmers who take the whole responsability of assessing all potential
 
10
# consequences resulting from its eventual inadequacies and bugs
 
11
# End users who are looking for a ready-to-use solution with commercial
 
12
# garantees and support are strongly adviced to contract a Free Software
 
13
# Service Company
 
14
#
 
15
# This program is Free Software; you can redistribute it and/or
 
16
# modify it under the terms of the GNU General Public License
 
17
# as published by the Free Software Foundation; either version 2
 
18
# of the License, or (at your option) any later version.
 
19
#
 
20
# This program is distributed in the hope that it will be useful,
 
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
# GNU General Public License for more details.
 
24
#
 
25
# You should have received a copy of the GNU General Public License
 
26
# along with this program; if not, write to the Free Software
 
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
28
#
 
29
##############################################################################
 
30
 
 
31
from osv import fields,osv, orm
 
32
import time
 
33
import tools
 
34
import pooler
 
35
 
 
36
 
 
37
class letter_paragraph_type(osv.osv):
 
38
        _name = "letter.paragraph.type"
 
39
        _columns = {
 
40
                'name': fields.char('Paragraph Type', size=60, required=True),
 
41
                'sequence': fields.integer('Sequence', required=True),
 
42
        }
 
43
letter_paragraph_type()
 
44
 
 
45
class letter_paragraph(osv.osv):
 
46
        _name = "letter.paragraph"
 
47
        _columns = {
 
48
                'name': fields.char('Paragraph Name', size=60, required=True),
 
49
                'sequence': fields.integer('Sequence'),
 
50
                'type_id': fields.many2one('letter.paragraph.type', 'Paragraph Type'),
 
51
                'content': fields.text('Content'),
 
52
        }
 
53
letter_paragraph()
 
54
 
 
55
class letter_letter_type(osv.osv):
 
56
        _name = "letter.letter.type"
 
57
        _columns = {
 
58
                'name': fields.char('Name', size=60, required=True),
 
59
                'template': fields.selection([('default','Default Template')], 'Template', required=True),
 
60
                'paragraph_ids': fields.many2many('letter.paragraph', 'letter_letter_paragraph_rel', 'letter_id','paragraph_id', 'Defaults Paragraphs')
 
61
        }
 
62
letter_letter_type()
 
63
 
 
64
class letter_letter(osv.osv):
 
65
        _name = "letter.letter"
 
66
        _columns = {
 
67
                'name': fields.char('Name', size=60, required=True),
 
68
                'partner_id': fields.many2one('res.partner', 'Partner', required=True),
 
69
                'type_id': fields.many2one('letter.letter.type', 'Letter Type', required=True),
 
70
                'state': fields.selection([('draft', 'Draft'),('confirmed','Confirmed')], 'State', required=True),
 
71
                'paragraph_ids': fields.one2many('letter.letter.paragraph','letter_id', 'Letter')
 
72
        }
 
73
        _defaults = {
 
74
                'state': lambda *a: 'draft',
 
75
        }
 
76
 
 
77
        def onchange_type_id(self, cr, uid, ids, type_id):
 
78
                if type_id:
 
79
                        letter = pooler.get_pool(cr.dbname).get('letter.letter.type').browse(cr, uid, type_id)[0]
 
80
                        return {'value':{'paragraph_ids': [x.id for x in letter.paragraph_ids]}}
 
81
                else:
 
82
                        return  {'value':{'paragraph_ids': []}}
 
83
 
 
84
letter_letter()
 
85
 
 
86
class letter_letter_paragraph(osv.osv):
 
87
        _name = "letter.letter.paragraph"
 
88
        _columns = {
 
89
                'sequence': fields.integer('Sequence'),
 
90
                'name': fields.char('Paragraph Name', size=60, required=True),
 
91
                'letter_id': fields.many2one('letter.letter', 'Letter'),
 
92
                'type_id': fields.many2one('letter.paragraph.type', 'Paragraph Type'),
 
93
                'content': fields.text('Content'),
 
94
        }
 
95
letter_letter_paragraph()
 
96
 
 
97