[MERGE] Merged with addons/trunk.
[odoo/odoo.git] / addons / analytic_contract_project / analytic_contract_project.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 from osv import fields, osv
23 from tools.translate import _
24
25 class project_project(osv.osv):
26     _inherit = 'project.project'
27
28     _defaults = {
29         'use_timesheets': True,
30     }
31
32     def open_sale_order_lines(self,cr,uid,ids,context=None):
33         account_ids = [x.analytic_account_id.id for x in self.browse(cr, uid, ids, context=context)]
34         return self.pool.get('account.analytic.account').open_sale_order_lines(cr, uid, account_ids, context=context)
35
36     def open_timesheets_to_invoice(self,cr,uid,ids,context=None):
37         if context is None:
38             context = {}
39         analytic_account_id = self.browse(cr, uid, ids[0], context=context).analytic_account_id.id
40         context.update({'search_default_account_id': analytic_account_id, 'default_account_id': analytic_account_id, 'search_default_to_invoice': 1})
41         return {
42             'type': 'ir.actions.act_window',
43             'name': _('Timesheet Lines to Invoice'),
44             'view_type': 'form',
45             'view_mode': 'tree,form',
46             'context': context,
47             'domain' : [('invoice_id','=',False),('to_invoice','!=',False), ('journal_id.type', '=', 'general')],
48             'res_model': 'account.analytic.line',
49             'nodestroy': True,
50         }
51
52     def open_timesheets(self, cr, uid, ids, context=None):
53         """ open Timesheets view """
54         project = self.browse(cr, uid, ids[0], context)
55         try:
56             journal_id = self.pool.get('ir.model.data').get_object(cr, uid, 'hr_timesheet', 'analytic_journal').id
57         except ValueError:
58             journal_id = False
59         view_context = {
60             'search_default_account_id': [project.analytic_account_id.id],
61             'default_account_id': project.analytic_account_id.id,
62             'default_journal_id': journal_id,
63         }
64         return {
65             'type': 'ir.actions.act_window',
66             'name': _('Bill Tasks Works'),
67             'res_model': 'account.analytic.line',
68             'view_type': 'form',
69             'view_mode': 'tree,form',
70             'context': view_context,
71             'nodestroy': True,
72         }
73 project_project()
74
75 class task(osv.osv):
76     _inherit = "project.task"
77     
78     def create(self, cr, uid, vals, context=None):
79         task_id = super(task, self).create(cr, uid, vals, context=context)
80         task_browse = self.browse(cr, uid, task_id, context=context)
81         if task_browse.project_id.analytic_account_id:
82             self.pool.get('account.analytic.account').message_append_note(cr, uid, [task_browse.project_id.analytic_account_id.id], body=_("Task <em>%s</em> has been <b>created</b>.") % (task_browse.name), context=context)
83         return task_id
84 task()