[IMP] sale modules : Cleaning modules
[odoo/odoo.git] / addons / account_reporting / account_reporting.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
22 import time
23
24 import netsvc
25 from osv import fields, osv
26 from tools.misc import currency
27
28 class color_rml(osv.osv):
29     _name = "color.rml"
30     _description = "Rml Color"
31     _columns = {
32         'name': fields.char('Name', size=64, required=True),
33         'code': fields.char('code', size=64, required=True),
34         }
35
36 color_rml()
37
38 class account_report_bs(osv.osv):
39     _name = "account.report.bs"
40     _description = "Account reporting for Balance Sheet"
41     _font = [
42              ('', ''),
43              ('Courier', 'Courier'),
44              ('Courier-Bold', 'Courier-Bold'),
45              ('Courier-BoldOblique', 'Courier-BoldOblique'),
46              ('Courier-Oblique', 'Courier-Oblique'),
47              ('Helvetica', 'Helvetica'),
48              ('Helvetica-Bold', 'Helvetica-Bold'),
49              ('Helvetica-Oblique', 'Helvetica-Oblique'),
50              ('Times-Bold', 'Times-Bold'),
51              ('Times-BoldItalic', 'Times-BoldItalic'),
52              ('Times-Italic', 'Times-Italic'),
53              ('Times-Roman', 'Times-Roman'),
54             ]
55     _color = [
56             ('', ''),
57             ('green', 'Green'),
58             ('red', 'Red'),
59             ('pink', 'Pink'),
60             ('blue', 'Blue'),
61             ('yellow', 'Yellow'),
62             ('cyan', 'Cyan'),
63             ('lightblue', 'Light Blue'),
64             ('orange', 'Orange'),
65             ]
66     _style = [
67             ('', ''),
68             ('h1', 'Header 1'),
69             ('h2', 'Header 2'),
70             ('h3', 'Header 3'),
71             ]
72
73     def onchange_parent_id(self, cr, uid, ids, parent_id):
74         v = {}
75         if parent_id:
76             acc = self.pool.get('account.report.report').browse(cr, uid, parent_id)
77             v['type'] = acc.type
78             if int(acc.style) < 6:
79                 v['style'] = str(int(acc.style) + 1)
80         return {'value': v}
81
82     _columns = {
83         'name': fields.char('Name', size=64, required=True),
84         'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of account reporting for balance sheet."),
85         'code': fields.char('Code', size=64, required=True),
86         'account_id': fields.many2many('account.account', 'account_report_rel', 'report_id', 'account_id', 'Accounts'),
87         'note': fields.text('Note'),
88         'color_font': fields.many2one('color.rml', 'Font Color'),
89         'color_back': fields.many2one('color.rml', 'Back Color'),
90         'font_style': fields.selection(_font, 'Font'),
91         'parent_id': fields.many2one('account.report.bs', 'Parent'),
92         'child_id': fields.one2many('account.report.bs', 'parent_id', 'Children'),
93         '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")
94     }
95     _defaults = {
96         'report_type': 'only_obj',
97         'color_font': '',
98         'color_back': '',
99         'font_style': '',
100     }
101
102     def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
103         if not args:
104             args = []
105         if not context:
106             context = {}
107         ids = []
108         if name:
109             ids = self.search(cr, user, [('code', '=', name)]+ args, limit=limit, context=context)
110             if not ids:
111                 ids = self.search(cr, user, [('name', operator, name)]+ args, limit=limit, context=context)
112         else:
113             ids = self.search(cr, user, args, limit=limit, context=context)
114         return self.name_get(cr, user, ids, context=context)
115
116 account_report_bs()
117
118 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
119