2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2009-11-26 07:07:14 +00:00
#
2009-01-20 08:48:19 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2008-11-03 19:18:56 +00:00
#
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2008-11-03 19:18:56 +00:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2008-11-03 19:18:56 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-11-26 07:07:14 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
2010-04-22 10:34:40 +00:00
2012-12-06 14:56:32 +00:00
from openerp . osv import fields , osv
from openerp . tools . translate import _
2006-12-07 13:41:40 +00:00
2011-11-16 14:59:58 +00:00
class hr_timesheet_invoice_create ( osv . osv_memory ) :
_name = ' hr.timesheet.invoice.create '
_description = ' Create invoice from timesheet '
_columns = {
' date ' : fields . boolean ( ' Date ' , help = ' The real date of each work will be displayed on the invoice ' ) ,
' time ' : fields . boolean ( ' Time spent ' , help = ' The time of each work done will be displayed on the invoice ' ) ,
' name ' : fields . boolean ( ' Description ' , help = ' The detail of each work done will be displayed on the invoice ' ) ,
' 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 ' ) ,
2012-07-26 11:35:30 +00:00
' 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. ' ) ,
2011-11-16 14:59:58 +00:00
}
_defaults = {
2012-11-27 12:07:37 +00:00
' date ' : 1 ,
' name ' : 1 ,
2011-11-16 14:59:58 +00:00
}
def view_init ( self , cr , uid , fields , context = None ) :
"""
This function checks for precondition before wizard executes
@param self : The object pointer
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param fields : List of fields for default value
@param context : A standard dictionary for contextual values
"""
analytic_obj = self . pool . get ( ' account.analytic.line ' )
data = context and context . get ( ' active_ids ' , [ ] )
for analytic in analytic_obj . browse ( cr , uid , data , context = context ) :
if analytic . invoice_id :
2012-10-30 11:26:32 +00:00
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " Invoice is already linked to some of the analytic line(s)! " ) )
2011-11-16 14:59:58 +00:00
def do_create ( self , cr , uid , ids , context = None ) :
2014-07-06 14:44:26 +00:00
data = self . read ( cr , uid , ids , context = context ) [ 0 ]
2012-11-27 12:07:37 +00:00
# Create an invoice based on selected timesheet lines
2011-11-16 14:59:58 +00:00
invs = self . pool . get ( ' account.analytic.line ' ) . invoice_cost_create ( cr , uid , context [ ' active_ids ' ] , data , context = context )
2010-04-22 10:34:40 +00:00
mod_obj = self . pool . get ( ' ir.model.data ' )
act_obj = self . pool . get ( ' ir.actions.act_window ' )
2014-07-06 14:44:26 +00:00
mod_ids = mod_obj . search ( cr , uid , [ ( ' name ' , ' = ' , ' action_invoice_tree1 ' ) ] , context = context )
res_id = mod_obj . read ( cr , uid , mod_ids , [ ' res_id ' ] , context = context ) [ 0 ] [ ' res_id ' ]
act_win = act_obj . read ( cr , uid , [ res_id ] , context = context ) [ 0 ]
2011-11-16 14:59:58 +00:00
act_win [ ' domain ' ] = [ ( ' id ' , ' in ' , invs ) , ( ' type ' , ' = ' , ' out_invoice ' ) ]
2009-05-12 06:50:06 +00:00
act_win [ ' name ' ] = _ ( ' Invoices ' )
return act_win
2009-11-26 07:07:14 +00:00
2010-04-22 10:34:40 +00:00
2008-07-23 14:41:47 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: