[MERGE]:merged from trunk
[odoo/odoo.git] / addons / account_reporting / account.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21 import time
22 import netsvc
23 from osv import fields, osv
24
25 from tools.misc import currency
26
27 import mx.DateTime
28 from mx.DateTime import RelativeDateTime, now, DateTime, localtime
29
30
31 class color_rml(osv.osv):
32     _name = "color.rml"
33     _description = "Rml Color"
34     _columns = {
35         'name': fields.char('Name', size=64, required=True),
36         'code': fields.char('code',size=64,required=True),
37         }
38
39 color_rml()
40
41 class account_report_bs(osv.osv):
42     _name = "account.report.bs"
43     _description = "Account reporting for Balance Sheet"
44     _font = [
45              ('',''),
46              ('Courier','Courier'),
47              ('Courier-Bold','Courier-Bold'),
48              ('Courier-BoldOblique','Courier-BoldOblique'),
49              ('Courier-Oblique','Courier-Oblique'),
50              ('Helvetica','Helvetica'),
51              ('Helvetica-Bold','Helvetica-Bold'),
52              ('Helvetica-Oblique','Helvetica-Oblique'),
53              ('Times-Bold','Times-Bold'),
54              ('Times-BoldItalic','Times-BoldItalic'),
55              ('Times-Italic','Times-Italic'),
56              ('Times-Roman','Times-Roman'),
57             ]
58     _color = [
59             ('', ''),
60             ('green','Green'),
61             ('red','Red'),
62             ('pink','Pink'),
63             ('blue','Blue'),
64             ('yellow','Yellow'),
65             ('cyan','Cyan'),
66             ('lightblue','Light Blue'),
67             ('orange','Orange'),
68             ]
69     _style = [
70             ('', ''),
71             ('h1','Header 1'),
72             ('h2','Header 2'),
73             ('h3','Header 3'),
74             ]
75
76     def onchange_parent_id(self, cr, uid, ids, parent_id):
77         v={}
78         if parent_id:
79             acc=self.pool.get('account.report.report').browse(cr, uid, parent_id)
80             v['type']=acc.type
81             if int(acc.style) < 6:
82                 v['style'] = str(int(acc.style)+1)
83         return {'value': v}
84
85     _columns = {
86         'name': fields.char('Name', size=64, required=True),
87         'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of account reporting for balance sheet."),
88         'code': fields.char('Code', size=64, required=True),
89         'account_id': fields.many2many('account.account', 'account_report_rel', 'report_id', 'account_id', 'Accounts'),
90         'note': fields.text('Note'),
91         'color_font' : fields.many2one('color.rml','Font Color'),
92         'color_back' : fields.many2one('color.rml','Back Color'),
93         'font_style' : fields.selection(_font, 'Font'),
94         'parent_id': fields.many2one('account.report.bs', 'Parent'),
95         'child_id': fields.one2many('account.report.bs', 'parent_id', 'Children'),
96         'report_type' : fields.selection([('only_obj', 'Report Objects Only'),('with_account', 'Report Objects With Accounts'),('acc_with_child', 'Report Objects With Accounts and child of Accounts')],"Report Type")
97     }
98     _defaults = {
99         'report_type': lambda *a :'only_obj',
100         'color_font': lambda *a :'',
101         'color_back': lambda *a :'',
102         'font_style': lambda *a :'',
103     }
104
105     def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
106         if not args:
107             args=[]
108         if not context:
109             context={}
110         ids = []
111         if name:
112             ids = self.search(cr, user, [('code','=',name)]+ args, limit=limit, context=context)
113             if not ids:
114                 ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context)
115         else:
116             ids = self.search(cr, user, args, limit=limit, context=context)
117         return self.name_get(cr, user, ids, context=context)
118
119 account_report_bs()
120
121
122 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
123