2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2008-11-03 19:18:56 +00:00
##############################################################################
2010-03-25 14:17:36 +00:00
#
2009-10-14 11:15:34 +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
2010-03-25 14:17:36 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-11-03 19:18:56 +00:00
#
##############################################################################
2009-10-14 11:15:34 +00:00
2010-08-17 05:48:28 +00:00
from osv import fields , osv
2008-08-24 14:45:43 +00:00
class notify_message ( osv . osv ) :
_name = ' notify.message '
_description = ' Notify By Messages '
_columns = {
2010-08-17 05:48:28 +00:00
' name ' : fields . char ( ' Title ' , size = 64 , required = True ) ,
' msg ' : fields . text ( ' Special Message ' , size = 128 , required = True , help = ' This notification will appear at the bottom of the Invoices when printed. ' , translate = True )
2008-08-24 14:45:43 +00:00
}
notify_message ( )
class account_invoice_line ( osv . osv ) :
2010-08-17 05:48:28 +00:00
def move_line_get_item ( self , cr , uid , line , context = None ) :
2008-08-24 14:45:43 +00:00
if line . state != ' article ' :
return None
return super ( account_invoice_line , self ) . move_line_get_item ( cr , uid , line , context )
def fields_get ( self , cr , uid , fields = None , context = None ) :
article = {
' article ' : [ ( ' readonly ' , False ) , ( ' invisible ' , False ) ] ,
' text ' : [ ( ' readonly ' , True ) , ( ' invisible ' , True ) , ( ' required ' , False ) ] ,
' subtotal ' : [ ( ' readonly ' , True ) , ( ' invisible ' , True ) , ( ' required ' , False ) ] ,
' title ' : [ ( ' readonly ' , True ) , ( ' invisible ' , True ) , ( ' required ' , False ) ] ,
' break ' : [ ( ' readonly ' , True ) , ( ' invisible ' , True ) , ( ' required ' , False ) ] ,
' line ' : [ ( ' readonly ' , True ) , ( ' invisible ' , True ) , ( ' required ' , False ) ] ,
}
states = {
' name ' : {
' break ' : [ ( ' readonly ' , True ) , ( ' required ' , False ) , ( ' invisible ' , True ) ] ,
' line ' : [ ( ' readonly ' , True ) , ( ' required ' , False ) , ( ' invisible ' , True ) ] ,
} ,
' product_id ' : article ,
' account_id ' : article ,
' quantity ' : article ,
' uos_id ' : article ,
' price_unit ' : article ,
' discount ' : article ,
' invoice_line_tax_id ' : article ,
' account_analytic_id ' : article ,
}
res = super ( account_invoice_line , self ) . fields_get ( cr , uid , fields , context )
for field in res :
if states . has_key ( field ) :
for key , value in states [ field ] . items ( ) :
res [ field ] . setdefault ( ' states ' , { } )
res [ field ] [ ' states ' ] [ key ] = value
return res
2010-08-17 05:48:28 +00:00
def onchange_invoice_line_view ( self , cr , uid , id , type , context = None , * args ) :
2008-08-24 14:45:43 +00:00
if ( not type ) :
return { }
if type != ' article ' :
temp = { ' value ' : {
' product_id ' : False ,
' uos_id ' : False ,
' account_id ' : False ,
' price_unit ' : False ,
' price_subtotal ' : False ,
' quantity ' : 0 ,
' discount ' : False ,
' invoice_line_tax_id ' : False ,
' account_analytic_id ' : False ,
} ,
}
if type == ' line ' :
temp [ ' value ' ] [ ' name ' ] = ' '
if type == ' break ' :
temp [ ' value ' ] [ ' name ' ] = ' '
if type == ' subtotal ' :
temp [ ' value ' ] [ ' name ' ] = ' Sub Total '
return temp
return { }
def create ( self , cr , user , vals , context = None ) :
if vals . has_key ( ' state ' ) :
if vals [ ' state ' ] == ' line ' :
vals [ ' name ' ] = ' '
if vals [ ' state ' ] == ' break ' :
vals [ ' name ' ] = ' '
if vals [ ' state ' ] != ' article ' :
vals [ ' quantity ' ] = 0
vals [ ' account_id ' ] = self . _default_account ( cr , user , None )
return super ( account_invoice_line , self ) . create ( cr , user , vals , context )
def write ( self , cr , user , ids , vals , context = None ) :
if vals . has_key ( ' state ' ) :
if vals [ ' state ' ] != ' article ' :
vals [ ' product_id ' ] = False
vals [ ' uos_id ' ] = False
vals [ ' account_id ' ] = self . _default_account ( cr , user , None )
vals [ ' price_unit ' ] = False
vals [ ' price_subtotal ' ] = False
vals [ ' quantity ' ] = 0
vals [ ' discount ' ] = False
vals [ ' invoice_line_tax_id ' ] = False
vals [ ' account_analytic_id ' ] = False
if vals [ ' state ' ] == ' line ' :
vals [ ' name ' ] = ' '
if vals [ ' state ' ] == ' break ' :
vals [ ' name ' ] = ' '
return super ( account_invoice_line , self ) . write ( cr , user , ids , vals , context )
2009-02-04 13:12:10 +00:00
def copy_data ( self , cr , uid , id , default = None , context = None ) :
2008-08-24 14:45:43 +00:00
if default is None :
default = { }
2010-11-19 13:48:01 +00:00
default [ ' state ' ] = self . browse ( cr , uid , id , context = context ) . state
2009-02-04 13:12:10 +00:00
return super ( account_invoice_line , self ) . copy_data ( cr , uid , id , default , context )
2008-08-24 14:45:43 +00:00
2010-10-04 10:05:30 +00:00
def _fnct ( self , cr , uid , ids , name , args , context = None ) :
2008-08-24 14:45:43 +00:00
res = { }
2010-11-19 13:48:01 +00:00
lines = self . browse ( cr , uid , ids , context = context )
2010-10-04 10:05:30 +00:00
account_ids = [ line . account_id . id for line in lines ]
account_names = dict ( self . pool . get ( ' account.account ' ) . name_get ( cr , uid , account_ids , context = context ) )
for line in lines :
if line . state != ' article ' :
if line . state == ' line ' :
res [ line . id ] = ' ----------------------------------------- '
elif line . state == ' break ' :
res [ line . id ] = ' PAGE BREAK '
2008-08-24 14:45:43 +00:00
else :
2010-10-04 10:05:30 +00:00
res [ line . id ] = ' '
2008-08-24 14:45:43 +00:00
else :
2010-10-04 10:05:30 +00:00
res [ line . id ] = account_names . get ( line . account_id . id , ' ' )
2008-08-24 14:45:43 +00:00
return res
_name = " account.invoice.line "
_order = " invoice_id, sequence asc "
_description = " Invoice Line "
_inherit = " account.invoice.line "
_columns = {
' state ' : fields . selection ( [
( ' article ' , ' Product ' ) ,
( ' title ' , ' Title ' ) ,
( ' text ' , ' Note ' ) ,
( ' subtotal ' , ' Sub Total ' ) ,
( ' line ' , ' Separator Line ' ) ,
( ' break ' , ' Page Break ' ) , ]
, ' Type ' , select = True , required = True ) ,
2009-12-21 13:14:12 +00:00
' sequence ' : fields . integer ( ' Sequence Number ' , help = " Gives the sequence order when displaying a list of invoice lines. " ) ,
2011-07-01 23:41:24 +00:00
' functional_field ' : fields . function ( _fnct , arg = None , fnct_inv = None , fnct_inv_arg = None , type = ' char ' , fnct_search = None , obj = None , store = False , string = " Source Account " ) ,
2008-08-24 14:45:43 +00:00
}
2008-09-23 13:28:07 +00:00
2008-08-24 14:45:43 +00:00
def _default_account ( self , cr , uid , context = None ) :
2008-09-23 13:28:07 +00:00
cr . execute ( " select id from account_account where parent_id IS NULL LIMIT 1 " )
2010-08-17 05:48:28 +00:00
res = cr . fetchone ( )
2008-08-24 14:45:43 +00:00
return res [ 0 ]
2008-09-23 13:28:07 +00:00
2008-08-24 14:45:43 +00:00
_defaults = {
2010-08-17 05:48:28 +00:00
' state ' : ' article ' ,
' sequence ' : 0 ,
2008-08-24 14:45:43 +00:00
}
2010-08-17 05:48:28 +00:00
account_invoice_line ( )
2008-08-24 14:45:43 +00:00
class one2many_mod2 ( fields . one2many ) :
2010-08-17 05:48:28 +00:00
2008-08-24 14:45:43 +00:00
def get ( self , cr , obj , ids , name , user = None , offset = 0 , context = None , values = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2008-08-24 14:45:43 +00:00
context = { }
if not values :
values = { }
res = { }
for id in ids :
res [ id ] = [ ]
ids2 = obj . pool . get ( self . _obj ) . search ( cr , user , [ ( self . _fields_id , ' in ' , ids ) , ( ' state ' , ' = ' , ' article ' ) ] , limit = self . _limit )
for r in obj . pool . get ( self . _obj ) . _read_flat ( cr , user , ids2 , [ self . _fields_id ] , context = context , load = ' _classic_write ' ) :
res [ r [ self . _fields_id ] ] . append ( r [ ' id ' ] )
return res
class account_invoice ( osv . osv ) :
def copy ( self , cr , uid , id , default = None , context = None ) :
if default is None :
default = { }
default [ ' invoice_line ' ] = False
return super ( account_invoice , self ) . copy ( cr , uid , id , default , context )
_inherit = " account.invoice "
_columns = {
' abstract_line_ids ' : fields . one2many ( ' account.invoice.line ' , ' invoice_id ' , ' Invoice Lines ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' invoice_line ' : one2many_mod2 ( ' account.invoice.line ' , ' invoice_id ' , ' Invoice Lines ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
}
2010-08-17 05:48:28 +00:00
2008-08-24 14:45:43 +00:00
account_invoice ( )
2010-10-04 10:05:30 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: