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

« back to all changes in this revision

Viewing changes to cci_event/cci_event.py

merging new development from indian accounting

Show diffs side-by-side

added added

removed removed

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