~technofluid-team/openobject-addons/technofluid_multiple_installations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from osv import osv, fields
from datetime import datetime, timedelta
from tools.translate import _

class cpi_be_type(osv.osv):
    _name = 'cpi.be.type'
    
    _columns = {
        'name':fields.char("Name", size=255),
        'description':fields.char("Description", size=1024),  
        'entries':fields.one2many('cpi.be.entry','type_id', string='Entries')
    }
cpi_be_type()


class cpi_be_entry(osv.osv):
    _name = 'cpi.be.entry'
    
    _order = 'type_id, year desc, month desc, value' 
    
    def name_get(self, cr, uid, ids, context=None):
        if not ids:
            return []
        result = []
        for entry in self.browse(cr, uid, ids, context=context):
            result.append((entry.id,str(entry.year)+'/'+str(entry.month)))
        return result
    
    _columns = {
        'type_id':fields.many2one('cpi.be.type', string="Type"),
        'year':fields.integer("Year"), 
        'month':fields.integer("Month"), 
        'value':fields.float("Value")
    }
    
    def _check_date(self, cr, uid, ids):
        for cpi in self.browse(cr, uid, ids):
            if cpi.month < 1 or cpi.month > 12:
                return False 
        return True
    
    _constraints = [(_check_date, 'Error: invalid month', ['month']), ]
    
    _sql_constraints = [
        ('cpi_be_entry_unique', 'unique(type_id,year,month)', 'For the same type, year and month must be unique')
    ]
    
     
    
cpi_be_entry()

class cpi_be_update_wizard(osv.osv_memory):
    _name = 'cpi.be.update.wizard'
    
    def action_update(self, cr, uid, ids, context):
        self.pool.get("scheduler.cpi_be").import_cpi_be_all(cr, uid, context=context)
        return {'type': 'ir.actions.act_window_close'}
    
cpi_be_update_wizard()