1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
23 from openerp.osv import fields, osv
24 from openerp.tools.translate import _
26 class hr_timesheet_invoice_create(osv.osv_memory):
28 _name = 'hr.timesheet.invoice.create'
29 _description = 'Create invoice from timesheet'
31 'date': fields.boolean('Date', help='The real date of each work will be displayed on the invoice'),
32 'time': fields.boolean('Time spent', help='The time of each work done will be displayed on the invoice'),
33 'name': fields.boolean('Description', help='The detail of each work done will be displayed on the invoice'),
34 'price': fields.boolean('Cost', help='The cost of each work done will be displayed on the invoice. You probably don\'t want to check this'),
35 'product': fields.many2one('product.product', 'Force Product', help='Fill this field only if you want to force to use a specific product. Keep empty to use the real product that comes from the cost.'),
43 def view_init(self, cr, uid, fields, context=None):
45 This function checks for precondition before wizard executes
46 @param self: The object pointer
47 @param cr: the current row, from the database cursor,
48 @param uid: the current user’s ID for security checks,
49 @param fields: List of fields for default value
50 @param context: A standard dictionary for contextual values
52 analytic_obj = self.pool.get('account.analytic.line')
53 data = context and context.get('active_ids', [])
54 for analytic in analytic_obj.browse(cr, uid, data, context=context):
55 if analytic.invoice_id:
56 raise osv.except_osv(_('Warning!'), _("Invoice is already linked to some of the analytic line(s)!"))
58 def do_create(self, cr, uid, ids, context=None):
59 data = self.read(cr, uid, ids, [], context=context)[0]
60 # Create an invoice based on selected timesheet lines
61 invs = self.pool.get('account.analytic.line').invoice_cost_create(cr, uid, context['active_ids'], data, context=context)
62 mod_obj = self.pool.get('ir.model.data')
63 act_obj = self.pool.get('ir.actions.act_window')
64 mod_ids = mod_obj.search(cr, uid, [('name', '=', 'action_invoice_tree1')], context=context)[0]
65 res_id = mod_obj.read(cr, uid, mod_ids, ['res_id'], context=context)['res_id']
66 act_win = act_obj.read(cr, uid, res_id, [], context=context)
67 act_win['domain'] = [('id','in',invs),('type','=','out_invoice')]
68 act_win['name'] = _('Invoices')
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: