4eaca49e2ca22ff1b000ce41c09d11025044fcec
[odoo/odoo.git] / addons / account_analytic_plans / wizard / account_crossovered_analytic.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 from osv import osv, fields
25 from tools.translate import _
26
27 class account_crossovered_analytic(osv.osv_memory):
28     _name = "account.crossovered.analytic"
29     _description = "Print Crossovered Analytic"
30     _columns = {
31         'date1': fields.date('Start Date', required=True),
32         'date2': fields.date('End Date', required=True),
33         'journal_ids': fields.many2many('account.analytic.journal', 'crossovered_journal_rel', 'crossover_id', 'journal_id', 'Analytic Journal'),
34         'ref': fields.many2one('account.analytic.account', 'Analytic Account Reference', required=True),
35         'empty_line': fields.boolean('Dont show empty lines'),
36     }
37     _defaults = {
38          'date1': lambda *a: time.strftime('%Y-01-01'),
39          'date2': lambda *a: time.strftime('%Y-%m-%d'),
40     }
41
42     def print_report(self, cr, uid, ids, context=None):
43         cr.execute('SELECT account_id FROM account_analytic_line')
44         res = cr.fetchall()
45         acc_ids = [x[0] for x in res]
46
47         data = self.read(cr, uid, ids, [], context=context)[0]
48
49         obj_acc = self.pool.get('account.analytic.account').browse(cr, uid, data['ref'], context=context)
50         name = obj_acc.name
51
52         account_ids = self.pool.get('account.analytic.account').search(cr, uid, [('parent_id', 'child_of', [data['ref']])], context=context)
53
54         flag = True
55         for acc in account_ids:
56             if acc in acc_ids:
57                 flag = False
58                 break
59         if flag:
60             raise osv.except_osv(_('User Error'),_('There are no Analytic lines related to Account %s' % name))
61
62         datas = {
63              'ids': [],
64              'model': 'account.analytic.account',
65              'form': data
66         }
67         return {
68             'type': 'ir.actions.report.xml',
69             'report_name': 'account.analytic.account.crossovered.analytic',
70             'datas': datas,
71         }
72
73 account_crossovered_analytic()
74
75 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: