~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to cci_event/cci_event.py

  • Committer: Fabien Pinckaers
  • Date: 2008-11-12 06:43:12 UTC
  • Revision ID: fp@tinyerp.com-20081112064312-fp85io97i1e95tuz
moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import fields,osv
 
24
from osv import orm
 
25
import netsvc
 
26
import pooler
 
27
 
 
28
class event_meeting_table(osv.osv):
 
29
    _name="event.meeting.table"
 
30
    _description="event.meeting.table"
 
31
    _columns={
 
32
        'partner_id1':fields.many2one('res.partner','First Partner',required=True),
 
33
        'partner_id2':fields.many2one('res.partner','Second Partner', required=True),
 
34
        'event_id':fields.many2one('event.event','Related Event', required=True),
 
35
        'contact_id1':fields.many2one('res.partner.contact','First Contact',required=True),
 
36
        'contact_id2':fields.many2one('res.partner.contact','Second Contact', required=True),
 
37
        'service':fields.integer('Service', required=True),
 
38
        'table':fields.char('Table',size=10,required=True),
 
39
        }
 
40
event_meeting_table()
 
41
 
 
42
 
 
43
class event_check_type(osv.osv):
 
44
    _name="event.check.type"
 
45
    _description="event.check.type"
 
46
    _columns={
 
47
        'name':fields.char('Name',size=20,required=True),
 
48
        }
 
49
event_check_type()
 
50
 
 
51
class event(osv.osv):
 
52
 
 
53
    def cci_event_fixed(self, cr, uid, ids, *args):
 
54
        self.write(cr, uid, ids, {'state':'fixed',})
 
55
        return True
 
56
 
 
57
    def cci_event_open(self, cr, uid, ids, *args):
 
58
        self.write(cr, uid, ids, {'state':'open',})
 
59
        return True
 
60
 
 
61
    def cci_event_confirm(self, cr, uid, ids, *args):
 
62
        self.write(cr, uid, ids, {'state':'confirm',})
 
63
        return True
 
64
 
 
65
    def cci_event_running(self, cr, uid, ids, *args):
 
66
        self.write(cr, uid, ids, {'state':'running',})
 
67
        return True
 
68
 
 
69
    def cci_event_done(self, cr, uid, ids, *args):
 
70
        self.write(cr, uid, ids, {'state':'done',})
 
71
        return True
 
72
 
 
73
    def cci_event_closed(self, cr, uid, ids, *args):
 
74
        self.write(cr, uid, ids, {'state':'closed',})
 
75
        return True
 
76
 
 
77
    def cci_event_cancel(self, cr, uid, ids, *args):
 
78
        self.write(cr, uid, ids, {'state':'cancel',})
 
79
        return True
 
80
 
 
81
    def onchange_check_type(self, cr, uid, id, type):
 
82
        if not type:
 
83
            return {}
 
84
        tmp=self.pool.get('event.type').browse(cr, uid, type)
 
85
        return {'value':{'check_type' : tmp.check_type.id}}
 
86
 
 
87
    def _group_names(self, cr, uid, ids):
 
88
        cr.execute('''
 
89
        SELECT distinct name
 
90
        FROM event_group
 
91
        ''')
 
92
        res = cr.fetchall()
 
93
        temp=[]
 
94
        for r in res:
 
95
            temp.append((r[0],r[0]))
 
96
        return temp
 
97
 
 
98
    _inherit="event.event"
 
99
    _description="event.event"
 
100
    _columns={
 
101
            'state': fields.selection([('draft','Draft'),('fixed','Fixed'),('open','Open'),('confirm','Confirmed'),('running','Running'),('done','Done'),('cancel','Canceled'),('closed','Closed')], 'State', readonly=True, required=True),
 
102
            'agreement_nbr':fields.char('Agreement Nbr',size=16),
 
103
            'note':fields.text('Note'),
 
104
            'fse_code':fields.char('FSE code',size=64),
 
105
            'fse_hours':fields.integer('FSE Hours'),
 
106
            'signet_type':fields.selection(_group_names, 'Signet type'),
 
107
            'localisation':fields.char('Localisation',size=20),
 
108
            'account_analytic_id':fields.many2one('account.analytic.account','Analytic Account'),
 
109
            'check_type': fields.many2one('event.check.type','Check Type'),
 
110
            }
 
111
event()
 
112
 
 
113
class event_check(osv.osv):
 
114
    _name="event.check"
 
115
    _description="event.check"
 
116
 
 
117
    def cci_event_check_block(self, cr, uid, ids, *args):
 
118
        self.write(cr, uid, ids, {'state':'block',})
 
119
        return True
 
120
 
 
121
    def cci_event_check_confirm(self, cr, uid, ids, *args):
 
122
        self.write(cr, uid, ids, {'state':'confirm',})
 
123
        return True
 
124
 
 
125
    def cci_event_check_cancel(self, cr, uid, ids, *args):
 
126
        self.write(cr, uid, ids, {'state':'cancel',})
 
127
        return True
 
128
 
 
129
    _columns={
 
130
        "name": fields.char('Name', size=128, required=True),
 
131
        "code": fields.char('Code', size=64),
 
132
        "reg_id": fields.many2one('event.registration','Inscriptions',required=True),
 
133
        "state": fields.selection([('draft','Draft'),('block','Blocked'),('confirm','Confirm'),('cancel','Cancel'),('asked','Asked')], 'State', readonly=True),#should be check (previous states :('open','Open'),('block','Blocked'),('paid','Paid'),('refused','Refused'),('asked','Asked')])
 
134
        "unit_nbr": fields.float('Value'),
 
135
        "type_id":fields.many2one('event.check.type','Type'),
 
136
        "date_reception":fields.date("Reception Date"),
 
137
        "date_limit":fields.date('Limit Date'),
 
138
        "date_submission":fields.date("Submission Date"),
 
139
        }
 
140
    _defaults = {
 
141
        'state': lambda *args: 'draft',
 
142
        'name': lambda *args: 'cheque',
 
143
    }
 
144
 
 
145
event_check()
 
146
 
 
147
class event_type(osv.osv):
 
148
    _inherit = 'event.type'
 
149
    _description= 'Event type'
 
150
    _columns = {
 
151
        'check_type': fields.many2one('event.check.type','Default Check Type'),
 
152
    }
 
153
event_type()
 
154
 
 
155
class event_group(osv.osv):
 
156
    _name= 'event.group'
 
157
    _description = 'event.group'
 
158
    _columns = {
 
159
        "name":fields.char('Group Name',size=20,required=True),
 
160
        "bookmark_name":fields.char('Value',size=128),
 
161
        "picture":fields.binary('Picture'),
 
162
        "type":fields.selection([('image','Image'),('text','Text')], 'Type',required=True)
 
163
        }
 
164
    _defaults = {
 
165
        'type': lambda *args: 'text',
 
166
    }
 
167
 
 
168
event_group()
 
169
 
 
170
class event_registration(osv.osv):
 
171
 
 
172
    def cci_event_reg_open(self, cr, uid, ids, *args):
 
173
        self.write(cr, uid, ids, {'state':'open',})
 
174
        self.pool.get('event.registration').mail_user(cr,uid,ids)
 
175
        self.pool.get('event.registration')._history(cr, uid, ids, 'Open', history=True)
 
176
        return True
 
177
 
 
178
    def cci_event_reg_done(self, cr, uid, ids, *args):
 
179
        self.write(cr, uid, ids, {'state':'done',})
 
180
        self.pool.get('event.registration')._history(cr, uid, ids, 'Done', history=True)
 
181
        return True
 
182
 
 
183
    def cci_event_reg_cancel(self, cr, uid, ids, *args):
 
184
        self.write(cr, uid, ids, {'state':'cancel',})
 
185
        self.pool.get('event.registration')._history(cr, uid, ids, 'Cancel', history=True)
 
186
        return True
 
187
 
 
188
    def cal_check_amount(self, cr, uid, ids, name, arg, context={}):
 
189
        res = {}
 
190
        data_reg = self.browse(cr,uid,ids)
 
191
        for reg in data_reg:
 
192
            total = 0
 
193
            for check in reg.check_ids:
 
194
                total = total + check.unit_nbr
 
195
            res[reg.id] = total
 
196
        return res
 
197
 
 
198
    _inherit = 'event.registration'
 
199
    _description="event.registration"
 
200
    _columns={
 
201
            "contact_order_id":fields.many2one('res.partner.contact','Contact Order'),
 
202
            "group_id": fields.many2one('event.group','Event Group'),
 
203
            "cavalier": fields.boolean('Cavalier',help="Check if we should print papers with participant name"),
 
204
            "payment_mode":fields.many2one('payment.mode',"Payment Mode"),#should be check (m2o ?)
 
205
            "check_mode":fields.boolean('Check Mode'),
 
206
            "check_ids":fields.one2many('event.check','reg_id',"Check ids"),
 
207
            "payment_ids":fields.many2many("account.move.line","move_line_registration", "reg_id", "move_line_id","Payment", readonly=True),
 
208
            "training_authorization":fields.char('Training Auth.',size=12,help='Formation Checks Authorization number',readonly=True),
 
209
            "check_amount":fields.function(cal_check_amount,method=True,type='float', string='Check Amount')
 
210
    }
 
211
    _defaults = {
 
212
        'name': lambda *a: 'Registration',
 
213
    }
 
214
 
 
215
    def write(self, cr, uid, *args, **argv):
 
216
        if 'partner_invoice_id' in args[1] and args[1]['partner_invoice_id']:
 
217
            data_partner = self.pool.get('res.partner').browse(cr,uid,args[1]['partner_invoice_id'])
 
218
            if data_partner:
 
219
                args[1]['training_authorization'] = data_partner.training_authorization
 
220
        return super(event_registration, self).write(cr, uid, *args, **argv)
 
221
 
 
222
    def onchange_partner_id(self, cr, uid, ids, part, event_id, email=False):#override function for partner name.
 
223
        if part:
 
224
            data_partner = self.pool.get('res.partner').browse(cr,uid,part)
 
225
            if data_partner.alert_events:
 
226
                raise osv.except_osv('Error!',data_partner.alert_explanation or 'Partner is not valid')
 
227
        return super(event_registration,self).onchange_partner_id(cr, uid, ids, part, event_id, email)
 
228
 
 
229
    def onchange_partner_invoice_id(self, cr, uid, ids, event_id, partner_invoice_id):
 
230
        data={}
 
231
        context={}
 
232
        data['training_authorization']=data['unit_price']=False
 
233
        if partner_invoice_id:
 
234
            data_partner = self.pool.get('res.partner').browse(cr,uid,partner_invoice_id)
 
235
            data['training_authorization']=data_partner.training_authorization
 
236
        if not event_id:
 
237
            return {'value':data}
 
238
        data_event =  self.pool.get('event.event').browse(cr,uid,event_id)
 
239
 
 
240
        if data_event.product_id:
 
241
            if not partner_invoice_id:
 
242
                data['training_authorization']=False
 
243
                data['unit_price']=self.pool.get('product.product').price_get(cr, uid, [data_event.product_id.id],context=context)[data_event.product_id.id]
 
244
                return {'value':data}
 
245
            data_partner = self.pool.get('res.partner').browse(cr,uid,partner_invoice_id)
 
246
            context.update({'partner_id':data_partner})
 
247
            data['unit_price']=self.pool.get('product.product').price_get(cr, uid, [data_event.product_id.id],context=context)[data_event.product_id.id]
 
248
            return {'value':data}
 
249
        return {'value':data}
 
250
 
 
251
#   def pay_and_recon(self,cr,uid,reg,inv_obj,inv_id,context={}):
 
252
#
 
253
#       if reg.check_ids:
 
254
#           total = 0
 
255
#           writeoff_account_id = False # should be check
 
256
#           writeoff_journal_id = False # should be check
 
257
#           data_inv = inv_obj.browse(cr,uid,inv_id)
 
258
#           journal_obj = self.pool.get('account.journal')
 
259
#           wf_service = netsvc.LocalService('workflow')
 
260
#
 
261
#           for check in reg.check_ids:
 
262
#               total = total + check.unit_nbr
 
263
 
 
264
#           ids = self.pool.get('account.period').find(cr, uid, context=context)
 
265
#           period_id = False
 
266
#           if len(ids):
 
267
#               period_id = ids[0]
 
268
#
 
269
#           cash_id = journal_obj.search(cr, uid, [('type', '=', 'cash')])
 
270
#           acc_id = journal_obj.browse(cr, uid, cash_id[0], context).default_credit_account_id.id
 
271
#           wf_service.trg_validate(uid, 'account.invoice', inv_id, 'invoice_open', cr)
 
272
#           inv_obj.pay_and_reconcile(cr,uid,[inv_id],total, acc_id, period_id, cash_id[0], writeoff_account_id, period_id, writeoff_journal_id, context)
 
273
 
 
274
 
 
275
event_registration()
 
276
 
 
277
 
 
278
class account_move_line(osv.osv):
 
279
    _inherit = 'account.move.line'
 
280
    _columns={
 
281
        "case_id" : fields.many2many("event.registration","move_line_registration", "move_line_id", "reg_id","Registration"),
 
282
    }
 
283
account_move_line()
 
284
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
285