[IMP] website crawler log show query/s
[odoo/odoo.git] / addons / hr_timesheet_invoice / wizard / hr_timesheet_final_invoice_create.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 openerp.osv import fields, osv
25 from openerp.tools.translate import _
26
27 #
28 # Create an final invoice based on selected timesheet lines
29 #
30
31 #
32 # TODO: check unit of measure !!!
33 #
34 class final_invoice_create(osv.osv_memory):
35     _name = 'hr.timesheet.invoice.create.final'
36     _description = 'Create invoice from timesheet final'
37     _columns = {
38         'date': fields.boolean('Date', help='Display date in the history of works'),
39         'time': fields.boolean('Time Spent', help='Display time in the history of works'),
40         'name': fields.boolean('Log of Activity', help='Display detail of work in the invoice line.'),
41         'price': fields.boolean('Cost', help='Display cost of the item you reinvoice'),
42         'product': fields.many2one('product.product', 'Product', help='The product that will be used to invoice the remaining amount'),
43     }
44
45     def do_create(self, cr, uid, ids, context=None):
46         data = self.read(cr, uid, ids, [], context=context)[0]
47         # hack for fixing small issue (context should not propagate implicitly between actions)
48         if 'default_type' in context:
49             del context['default_type']
50         ids = self.pool.get('account.analytic.line').search(cr, uid, [('invoice_id','=',False),('to_invoice','<>', False), ('account_id', 'in', context['active_ids'])], context=context)
51         invs = self.pool.get('account.analytic.line').invoice_cost_create(cr, uid, ids, data, context=context)
52         mod_obj = self.pool.get('ir.model.data')
53         act_obj = self.pool.get('ir.actions.act_window')
54         mod_ids = mod_obj.search(cr, uid, [('name', '=', 'action_invoice_tree1')], context=context)[0]
55         res_id = mod_obj.read(cr, uid, mod_ids, ['res_id'], context=context)['res_id']
56         act_win = act_obj.read(cr, uid, res_id, [], context=context)
57         act_win['domain'] = [('id','in',invs),('type','=','out_invoice')]
58         act_win['name'] = _('Invoices')
59         return act_win
60
61
62 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: