~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to cpi_be/cpi_be.py

  • Committer: cth at technofluid
  • Date: 2013-08-01 07:00:41 UTC
  • Revision ID: cth@technofluid.be-20130801070041-umbk0u1zuck4jlcw
Ajout du module IPC

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from osv import osv, fields
 
2
from datetime import datetime, timedelta
 
3
from tools.translate import _
 
4
 
 
5
class cpi_be_type(osv.osv):
 
6
    _name = 'cpi.be.type'
 
7
    
 
8
    _columns = {
 
9
        'name':fields.char("Name", size=255),
 
10
        'description':fields.char("Description", size=1024),  
 
11
        'entries':fields.one2many('cpi.be.entry','type_id', string='Entries')
 
12
    }
 
13
cpi_be_type()
 
14
 
 
15
 
 
16
class cpi_be_entry(osv.osv):
 
17
    _name = 'cpi.be.entry'
 
18
    
 
19
    _order = 'type_id, year desc, month desc, value' 
 
20
    
 
21
    def name_get(self, cr, uid, ids, context=None):
 
22
        if not ids:
 
23
            return []
 
24
        result = []
 
25
        for entry in self.browse(cr, uid, ids, context=context):
 
26
            result.append((entry.id,str(entry.year)+'/'+str(entry.month)))
 
27
        return result
 
28
    
 
29
    _columns = {
 
30
        'type_id':fields.many2one('cpi.be.type', string="Type"),
 
31
        'year':fields.integer("Year"), 
 
32
        'month':fields.integer("Month"), 
 
33
        'value':fields.float("Value")
 
34
    }
 
35
    
 
36
    def _check_date(self, cr, uid, ids):
 
37
        for cpi in self.browse(cr, uid, ids):
 
38
            if cpi.month < 1 or cpi.month > 12:
 
39
                return False 
 
40
        return True
 
41
    
 
42
    _constraints = [(_check_date, 'Error: invalid month', ['month']), ]
 
43
    
 
44
    _sql_constraints = [
 
45
        ('cpi_be_entry_unique', 'unique(type_id,year,month)', 'For the same type, year and month must be unique')
 
46
    ]
 
47
    
 
48
     
 
49
    
 
50
cpi_be_entry()
 
51
 
 
52
class cpi_be_update_wizard(osv.osv_memory):
 
53
    _name = 'cpi.be.update.wizard'
 
54
    
 
55
    def action_update(self, cr, uid, ids, context):
 
56
        self.pool.get("scheduler.cpi_be").import_cpi_be_all(cr, uid, context=context)
 
57
        return {'type': 'ir.actions.act_window_close'}
 
58
    
 
59
cpi_be_update_wizard()