2011-03-30 13:25:27 +00:00
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv , fields
import time
2011-05-02 09:51:34 +00:00
import datetime
2011-03-30 13:25:27 +00:00
class account_asset_category ( osv . osv ) :
_name = ' account.asset.category '
_description = ' Asset category '
_columns = {
' name ' : fields . char ( ' Asset category ' , size = 64 , required = True , select = 1 ) ,
2011-03-30 13:44:51 +00:00
#'code': fields.char('Reference', size=16, select=1),
2011-03-30 13:25:27 +00:00
' note ' : fields . text ( ' Note ' ) ,
2011-03-30 13:44:51 +00:00
#'type': fields.selection([('direct','Direct'),('indirect','Indirect')], 'Depr. method type', select=2, required=True),
2011-03-30 20:21:06 +00:00
' account_asset_id ' : fields . many2one ( ' account.account ' , ' Asset Account ' , required = True ) ,
' account_depreciation_id ' : fields . many2one ( ' account.account ' , ' Depreciation Account ' , required = True ) ,
2011-03-30 13:25:27 +00:00
' journal_id ' : fields . many2one ( ' account.journal ' , ' Journal ' , required = True ) ,
2011-03-30 20:21:06 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' ) ,
2011-03-30 13:25:27 +00:00
}
account_asset_category ( )
2011-03-30 20:21:06 +00:00
#class one2many_mod_asset(fields.one2many):
#
# def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
2011-03-31 23:43:25 +00:00
# prinasset_property_id if context is None:
2011-03-30 20:21:06 +00:00
# context = {}
# if not values:
# values = {}
# res = {}
# for id in ids:
# res[id] = []
# #compute depreciation board
# depreciation_line_ids = obj.pool.get('account.asset.asset').compute_depreciation_board(cr, user, ids, context=context)
# for key, value in depreciation_line_ids.items():
# #write values on asset
# obj.pool.get(self._obj).write(cr, user, key, {'depreciation_line_ids': [6,0,value]})
# return depreciation_line_ids
2011-03-30 13:25:27 +00:00
class account_asset_asset ( osv . osv ) :
_name = ' account.asset.asset '
_description = ' Asset '
# def _balance(self, cr, uid, ids, field_name, arg, context={}):
# acc_set = ",".join(map(str, ids))
# query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
# cr.execute(("SELECT a.id, COALESCE(SUM((l.debit-l.credit)),0) FROM account_asset_asset a LEFT JOIN account_move_line l ON (a.id=l.asset_account_id) WHERE a.id IN (%s) and "+query+" GROUP BY a.id") % (acc_set,))
# res = {}
# for account_id, sum in cr.fetchall():
# res[account_id] = round(sum,2)
# for id in ids:
# res[id] = round(res.get(id,0.0), 2)
# return res
def _get_period ( self , cr , uid , context = { } ) :
periods = self . pool . get ( ' account.period ' ) . find ( cr , uid )
if periods :
return periods [ 0 ]
else :
return False
2011-05-02 09:51:34 +00:00
##
def compute_depreciation_board ( self , cr , uid , ids , context = None ) :
2011-03-30 20:21:06 +00:00
#FIXME: change into a fields.function
2011-05-02 09:51:34 +00:00
test = 1.0
date_year = 1.0
purchase_value_board = 1.0
amountpro = 1.0
2011-03-30 20:21:06 +00:00
for asset in self . browse ( cr , uid , ids , context = context ) :
#res[asset.id] = []
undone_dotation_number = asset . method_delay - len ( asset . account_move_line_ids ) + 1
amount = asset . value_residual
2011-05-02 09:51:34 +00:00
test = asset . value_residual
purchase_value_board = amount
if asset . prorata == ' false ' :
for i in range ( 1 , undone_dotation_number + 1 ) :
if i == 1 :
amount = asset . value_residual / undone_dotation_number
test = asset . value_residual - amount
#amountpro = ((asset.value_residual / undone_dotation_number
else :
if asset . method == ' linear ' :
if i == undone_dotation_number + 1 :
# amount = amount - amountpro
test = test - amount
else :
amount = asset . value_residual / undone_dotation_number
test = test - amount
elif asset . method == " progressif " :
if i == undone_dotation_number + 1 :
# amount = amount - amountpro
test = test - amount
else :
amount = asset . value_residual * asset . method_progress_factor
test = test - amount
else :
#methods
print " "
else :
deprec_date = time . strftime ( ' % Y ' )
for i in range ( 1 , undone_dotation_number + 2 ) :
date_year = int ( time . strftime ( ' % Y ' ) )
date_year + = i - 1
deprec_date = ' 31/12/ ' , str ( date_year )
if i == 1 :
amount = ( ( asset . value_residual / undone_dotation_number ) * 5 ) / 12
test = asset . value_residual - amount
amountpro = ( ( asset . value_residual / undone_dotation_number ) * 5 ) / 12
else :
if asset . method == ' linear ' :
if i == undone_dotation_number + 1 :
amount = amount - amountpro
test = test - amount
else :
amount = asset . value_residual / undone_dotation_number
test = test - amount
elif asset . method == " progressif " :
if i == undone_dotation_number + 1 :
amount = amount - amountpro
test = test - amount
else :
amount = asset . value_residual * asset . method_progress_factor
test = test - amount
else :
#methods
print " "
#res[asset.id].append([self.pool.get('account.asset.depreciation.line').create(cr, uid, {'amount': amount, 'asset_id': asset.id, 'sequence':i, 'name': str(asset.id) +'/'+ str(i)})])
self . pool . get ( ' account.asset.depreciation.line ' ) . create ( cr , uid , { ' amount ' : amount , ' deprec_value ' : test , ' deprec_date ' : deprec_date , ' purchase_value_board ' : purchase_value_board , ' asset_id ' : asset . id , ' sequence ' : i , ' name ' : str ( asset . id ) + ' / ' + str ( i ) } )
return True
def account_move_line_deprec ( self , cr , uid , ids , context = { } ) :
print " Error !!! "
2011-03-30 20:21:06 +00:00
2011-03-30 13:25:27 +00:00
def validate ( self , cr , uid , ids , context = { } ) :
return self . write ( cr , uid , ids , {
' state ' : ' normal '
} , context )
def _amount_total ( self , cr , uid , ids , name , args , context = { } ) :
2011-03-30 20:21:06 +00:00
#FIXME: function not working²
2011-03-30 13:25:27 +00:00
id_set = " , " . join ( map ( str , ids ) )
cr . execute ( """ SELECT l.asset_id,abs(SUM(l.debit-l.credit)) AS amount FROM
account_move_line l
WHERE l . asset_id IN ( """ +id_set+ " ) GROUP BY l.asset_id " )
res = dict ( cr . fetchall ( ) )
for id in ids :
res . setdefault ( id , 0.0 )
return res
2011-03-30 20:21:06 +00:00
def _amount_residual ( self , cr , uid , ids , name , args , context = { } ) :
2011-03-31 23:43:25 +00:00
#FIXME: function not working OK
2011-03-30 20:21:06 +00:00
id_set = " , " . join ( map ( str , ids ) )
cr . execute ( """ SELECT
r . asset_property_id , SUM ( abs ( l . debit - l . credit ) ) AS amount
FROM
account_move_asset_entry_rel r
LEFT JOIN
account_move_line l on ( r . move_id = l . id )
WHERE
r . asset_property_id IN ( """ +id_set+ " ) GROUP BY r.asset_property_id " )
res = dict ( cr . fetchall ( ) )
for prop in self . browse ( cr , uid , ids , context ) :
res [ prop . id ] = prop . value_total - res . get ( prop . id , 0.0 )
for id in ids :
res . setdefault ( id , 0.0 )
return res
2011-03-30 13:25:27 +00:00
_columns = {
2011-03-31 23:43:25 +00:00
#test
' asset_id ' : fields . many2one ( ' account.asset.asset ' , ' Asset ' , required = True , select = 1 ) ,
' account_asset_id ' : fields . many2one ( ' account.account ' , ' Asset Account ' , required = True ) ,
' account_actif_id ' : fields . many2one ( ' account.account ' , ' Depreciation account ' , required = True ) ,
' journal_analytic_id ' : fields . many2one ( ' account.analytic.journal ' , ' Analytic journal ' ) ,
2011-03-30 13:25:27 +00:00
' name ' : fields . char ( ' Asset ' , size = 64 , required = True , select = 1 ) ,
' code ' : fields . char ( ' Reference ' , size = 16 , select = 1 ) ,
2011-05-02 09:51:34 +00:00
' purchase_value ' : fields . float ( ' Gross value ' , required = True , size = 16 , select = 1 ) ,
2011-03-30 20:21:06 +00:00
' currency_id ' : fields . many2one ( ' res.currency ' , ' Currency ' , required = True , size = 5 , select = 1 ) ,
2011-03-31 23:43:25 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , required = True ) , #FIXME: fields.many2one !! OK
2011-05-02 09:51:34 +00:00
' note ' : fields . text ( ' ' ) ,
2011-03-30 13:25:27 +00:00
' category_id ' : fields . many2one ( ' account.asset.category ' , ' Asset category ' , required = True , change_default = True ) ,
' localisation ' : fields . char ( ' Localisation ' , size = 32 , select = 2 ) ,
2011-03-30 20:21:06 +00:00
' parent_id ' : fields . many2one ( ' account.asset.asset ' , ' Parent Asset ' ) ,
' child_ids ' : fields . one2many ( ' account.asset.asset ' , ' parent_id ' , ' Children Assets ' ) ,
2011-03-31 23:43:25 +00:00
' purchase_date ' : fields . date ( ' Purchase Date ' , required = True ) , #FIXME: date is not displayed currently OK
2011-03-30 13:25:27 +00:00
' period_id ' : fields . many2one ( ' account.period ' , ' Period ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2011-05-02 09:51:34 +00:00
' state ' : fields . selection ( [ ( ' view ' , ' View ' ) , ( ' draft ' , ' Draft ' ) , ( ' normal ' , ' Normal ' ) , ( ' close ' , ' Close ' ) ] , ' state ' , required = True ) ,
2011-03-30 13:25:27 +00:00
' active ' : fields . boolean ( ' Active ' , select = 2 ) ,
2011-03-31 23:43:25 +00:00
' partner_id ' : fields . many2one ( ' res.partner ' , ' Partner ' ) , #FIXME: not displayed OK
2011-03-30 20:21:06 +00:00
' account_move_line_ids ' : fields . one2many ( ' account.move.line ' , ' asset_id ' , ' Entries ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2011-03-31 23:43:25 +00:00
' journal_analytic_id ' : fields . many2one ( ' account.analytic.journal ' , ' Analytic journal ' ) , #FIXME: do not display if not in group analytic accounting OK
' account_analytic_id ' : fields . many2one ( ' account.analytic.account ' , ' Analytic account ' ) , #FIXME: do not display if not in group analytic accounting OK
2011-03-30 20:21:06 +00:00
' method ' : fields . selection ( [ ( ' linear ' , ' Linear ' ) , ( ' progressif ' , ' Progressive ' ) ] , ' Computation method ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2011-03-31 23:43:25 +00:00
' method_delay ' : fields . integer ( ' During (interval) ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) , #FIXME: improve label OK
' method_period ' : fields . integer ( ' Depre. all (period) ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) , #FIXME: improve label OK
2011-03-30 20:21:06 +00:00
' method_end ' : fields . date ( ' Ending date ' ) ,
2011-03-31 23:43:25 +00:00
#he
' entry_asset_ids ' : fields . many2many ( ' account.move.line ' , ' account_move_asset_entry_rel ' , ' asset_property_id ' , ' move_id ' , ' Asset Entries ' ) ,
2011-03-30 20:21:06 +00:00
# 'board_ids': fields.one2many('account.asset.board', 'asset_id', 'Asset board'),
#
' value_total ' : fields . function ( _amount_total , method = True , digits = ( 16 , 2 ) , string = ' Gross Value ' ) ,
2011-03-31 23:43:25 +00:00
#he
' property_ids ' : fields . one2many ( ' account.asset.asset ' , ' asset_id ' , ' Asset method name ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
2011-03-30 20:21:06 +00:00
' method_progress_factor ' : fields . float ( ' Progressif Factor ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' value_residual ' : fields . function ( _amount_residual , method = True , digits = ( 16 , 2 ) , string = ' Residual Value ' ) ,
' method_time ' : fields . selection ( [ ( ' delay ' , ' Delay ' ) , ( ' end ' , ' Ending Period ' ) ] , ' Time Method ' , required = True , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
' prorata ' : fields . boolean ( ' Prorata Temporis ' , Readonly = " True " , help = ' Si l amortissement se realise après le 1 janvier ' ) ,
' history_ids ' : fields . one2many ( ' account.asset.property.history ' , ' asset_id ' , ' History ' , readonly = True ) ,
2011-05-02 09:51:34 +00:00
' depreciation_line_ids ' : fields . one2many ( ' account.asset.depreciation.line ' , ' asset_id ' , ' Depreciation Lines ' , readonly = True , ) ,
2011-03-30 13:25:27 +00:00
}
_defaults = {
' code ' : lambda obj , cr , uid , context : obj . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' account.asset.code ' ) ,
2011-03-31 23:43:25 +00:00
' purchase_date ' : lambda obj , cr , uid , context : time . strftime ( ' % Y- % m- %d ' ) ,
2011-03-30 13:25:27 +00:00
' active ' : lambda obj , cr , uid , context : True ,
' state ' : lambda obj , cr , uid , context : ' draft ' ,
' period_id ' : _get_period ,
2011-03-31 23:43:25 +00:00
' method ' : lambda obj , cr , uid , context : ' linear ' ,
' method_delay ' : lambda obj , cr , uid , context : 5 ,
' method_time ' : lambda obj , cr , uid , context : ' delay ' ,
' method_period ' : lambda obj , cr , uid , context : 12 ,
' method_progress_factor ' : lambda obj , cr , uid , context : 0.3 ,
2011-05-02 09:51:34 +00:00
' currency_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid , c ) . company_id . currency_id . id ,
2011-03-30 13:25:27 +00:00
}
2011-05-02 09:51:34 +00:00
2011-03-30 13:25:27 +00:00
def _compute_period ( self , cr , uid , property , context = { } ) :
if ( len ( property . entry_asset_ids or [ ] ) / 2 ) > = property . method_delay :
return False
if len ( property . entry_asset_ids ) :
cp = property . entry_asset_ids [ - 1 ] . period_id
cpid = self . pool . get ( ' account.period ' ) . next ( cr , uid , cp , property . method_period , context )
current_period = self . pool . get ( ' account.period ' ) . browse ( cr , uid , cpid , context )
else :
current_period = property . asset_id . period_id
return current_period
def _compute_move ( self , cr , uid , property , period , context = { } ) :
2011-03-31 23:43:25 +00:00
#FIXME: fucntion not working OK
2011-03-30 13:25:27 +00:00
result = [ ]
total = 0.0
for move in property . asset_id . entry_ids :
total + = move . debit - move . credit
for move in property . entry_asset_ids :
2011-03-31 23:43:25 +00:00
#he s
2011-03-30 13:25:27 +00:00
if move . account_id == property . account_asset_ids :
total + = move . debit
total + = - move . credit
periods = ( len ( property . entry_asset_ids ) / 2 ) - property . method_delay
2011-03-30 20:21:06 +00:00
2011-03-30 13:25:27 +00:00
if periods == 1 :
amount = total
else :
if property . method == ' linear ' :
amount = total / periods
else :
amount = total * property . method_progress_factor
move_id = self . pool . get ( ' account.move ' ) . create ( cr , uid , {
' journal_id ' : property . journal_id . id ,
' period_id ' : period . id ,
' name ' : property . name or property . asset_id . name ,
' ref ' : property . asset_id . code
} )
result = [ move_id ]
id = self . pool . get ( ' account.move.line ' ) . create ( cr , uid , {
' name ' : property . name or property . asset_id . name ,
' move_id ' : move_id ,
' account_id ' : property . account_asset_id . id ,
' debit ' : amount > 0 and amount or 0.0 ,
' credit ' : amount < 0 and - amount or 0.0 ,
' ref ' : property . asset_id . code ,
' period_id ' : period . id ,
' journal_id ' : property . journal_id . id ,
' partner_id ' : property . asset_id . partner_id . id ,
' date ' : time . strftime ( ' % Y- % m- %d ' ) ,
} )
id2 = self . pool . get ( ' account.move.line ' ) . create ( cr , uid , {
' name ' : property . name or property . asset_id . name ,
' move_id ' : move_id ,
' account_id ' : property . account_actif_id . id ,
' credit ' : amount > 0 and amount or 0.0 ,
' debit ' : amount < 0 and - amount or 0.0 ,
' ref ' : property . asset_id . code ,
' period_id ' : period . id ,
' journal_id ' : property . journal_id . id ,
' partner_id ' : property . asset_id . partner_id . id ,
' date ' : time . strftime ( ' % Y- % m- %d ' ) ,
} )
2011-03-31 23:43:25 +00:00
#
self . pool . get ( ' account.asset.asset ' ) . write ( cr , uid , [ property . id ] , {
2011-03-30 13:25:27 +00:00
' entry_asset_ids ' : [ ( 4 , id2 , False ) , ( 4 , id , False ) ]
} )
if property . method_delay - ( len ( property . entry_asset_ids ) / 2 ) < = 1 :
2011-03-30 20:21:06 +00:00
#self.pool.get('account.asset.property')._close(cr, uid, property, context)
2011-03-30 13:25:27 +00:00
return result
return result
def _compute_entries ( self , cr , uid , asset , period_id , context = { } ) :
2011-03-31 23:43:25 +00:00
#FIXME: function not working CHECK all res
2011-03-30 13:25:27 +00:00
result = [ ]
2011-03-31 23:43:25 +00:00
date_start = self . pool . get ( ' account.period ' ) . browse ( cr , uid , period_id , context ) . date_start
for property in asset . property_ids :
if property . state == ' open ' :
period = self . _compute_period ( cr , uid , property , context )
if period and ( period . date_start < = date_start ) :
result + = self . _compute_move ( cr , uid , property , period , context )
2011-03-30 13:25:27 +00:00
return result
account_asset_asset ( )
2011-03-30 20:21:06 +00:00
class account_asset_depreciation_line ( osv . osv ) :
_name = ' account.asset.depreciation.line '
_description = ' Asset depreciation line '
2011-03-30 13:25:27 +00:00
_columns = {
2011-03-30 20:21:06 +00:00
' name ' : fields . char ( ' Depreciation Name ' , size = 64 , required = True , select = 1 ) ,
' sequence ' : fields . integer ( ' Sequence of the depreciation ' , required = True ) ,
2011-03-30 13:25:27 +00:00
' asset_id ' : fields . many2one ( ' account.asset.asset ' , ' Asset ' , required = True ) ,
2011-03-30 20:21:06 +00:00
' amount ' : fields . float ( ' Depreciation amount ' , required = True ) ,
2011-05-02 09:51:34 +00:00
' deprec_value ' : fields . float ( ' Residual value ' , required = True ) ,
' deprec_date ' : fields . char ( ' Date ' , size = 64 , required = True , select = 1 ) ,
2011-03-30 13:25:27 +00:00
}
2011-03-30 20:21:06 +00:00
account_asset_depreciation_line ( )
#class account_asset_property(osv.osv):
# def _amount_total(self, cr, uid, ids, name, args, context={}):
# id_set=",".join(map(str,ids))
# cr.execute("""SELECT l.asset_id,abs(SUM(l.debit-l.credit)) AS amount FROM
# account_asset_property p
# left join
# account_move_line l on (p.asset_id=l.asset_id)
# WHERE p.id IN ("""+id_set+") GROUP BY l.asset_id ")
# res=dict(cr.fetchall())
# for id in ids:
# res.setdefault(id, 0.0)
# return res
#
# def _close(self, cr, uid, property, context={}):
# if property.state<>'close':
# self.pool.get('account.asset.property').write(cr, uid, [property.id], {
# 'state': 'close'
# })
# property.state='close'
# ok = property.asset_id.state=='open'
# for prop in property.asset_id.property_ids:
# ok = ok and prop.state=='close'
# self.pool.get('account.asset.asset').write(cr, uid, [property.asset_id.id], {
# 'state': 'close'
# }, context)
# return True
#
# _name = 'account.asset.property'
# _description = 'Asset property'
# _columns = {
# 'name': fields.char('Method name', size=64, select=1),
# 'type': fields.selection([('direct','Direct'),('indirect','Indirect')], 'Depr. method type', select=2, required=True),
# 'asset_id': fields.many2one('account.asset.asset', 'Asset', required=True),
# 'account_asset_id': fields.many2one('account.account', 'Asset account', required=True),
# 'account_actif_id': fields.many2one('account.account', 'Depreciation account', required=True),
# 'journal_id': fields.many2one('account.journal', 'Journal', required=True),
# 'journal_analytic_id': fields.many2one('account.analytic.journal', 'Analytic journal'),
# 'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic account'),
#
# 'method': fields.selection([('linear','Linear'),('progressif','Progressive')], 'Computation method', required=True, readonly=True, states={'draft':[('readonly',False)]}),
# 'method_delay': fields.integer('During', readonly=True, states={'draft':[('readonly',False)]}),
# 'method_period': fields.integer('Depre. all', readonly=True, states={'draft':[('readonly',False)]}),
# 'method_end': fields.date('Ending date'),
#
# 'date': fields.date('Date created'),
# #'test': fields.one2many('account.pre', 'asset_id', readonly=True, states={'draft':[('readonly',False)]}),
# 'entry_asset_ids': fields.many2many('account.move.line', 'account_move_asset_entry_rel', 'asset_property_id', 'move_id', 'Asset Entries'),
# 'board_ids': fields.one2many('account.asset.board', 'asset_id', 'Asset board'),
#
# 'value_total': fields.function(_amount_total, method=True, digits=(16,2),string='Gross value'),
# 'state': fields.selection([('draft','Draft'), ('open','Open'), ('close','Close')], 'State', required=True),
# 'history_ids': fields.one2many('account.asset.property.history', 'asset_property_id', 'History', readonly=True)
## 'parent_id': fields.many2one('account.asset.asset', 'Parent asset'),
## 'partner_id': fields.many2one('res.partner', 'Partner'),
## 'note': fields.text('Note'),
#
# }
# _defaults = {
# 'type': lambda obj, cr, uid, context: 'direct',
# 'state': lambda obj, cr, uid, context: 'draft',
# 'method': lambda obj, cr, uid, context: 'linear',
# 'method_time': lambda obj, cr, uid, context: 'delay',
# 'method_progress_factor': lambda obj, cr, uid, context: 0.3,
# 'method_delay': lambda obj, cr, uid, context: 5,
# 'method_period': lambda obj, cr, uid, context: 12,
# 'date': lambda obj, cr, uid, context: time.strftime('%Y-%m-%d')
# }
#account_asset_property()
2011-03-30 13:25:27 +00:00
class account_move_line ( osv . osv ) :
_inherit = ' account.move.line '
_columns = {
' asset_id ' : fields . many2one ( ' account.asset.asset ' , ' Asset ' ) ,
' entry_ids ' : fields . one2many ( ' account.move.line ' , ' asset_id ' , ' Entries ' , readonly = True , states = { ' draft ' : [ ( ' readonly ' , False ) ] } ) ,
}
account_move_line ( )
class account_pre ( osv . osv ) :
_name = ' account.pre '
_columns = {
' name ' : fields . char ( ' Test ' , size = 64 , select = 1 ) ,
' asset_id ' : fields . many2one ( ' account.asset.asset ' , ' Asset ' ) ,
# 'test': fields.one2many('account.pre','asset_id','test', readonly=True,states={'draft':[('readonly',False)]}),
}
account_pre ( )
class account_asset_property_history ( osv . osv ) :
_name = ' account.asset.property.history '
_description = ' Asset history '
_columns = {
' name ' : fields . char ( ' History name ' , size = 64 , select = 1 ) ,
' user_id ' : fields . many2one ( ' res.users ' , ' User ' , required = True ) ,
' date ' : fields . date ( ' Date ' , required = True ) ,
2011-03-30 20:21:06 +00:00
' asset_id ' : fields . many2one ( ' account.asset.asset ' , ' Asset ' , required = True ) ,
2011-03-30 13:25:27 +00:00
' method_delay ' : fields . integer ( ' Number of interval ' ) ,
' method_period ' : fields . integer ( ' Period per interval ' ) ,
' method_end ' : fields . date ( ' Ending date ' ) ,
' note ' : fields . text ( ' Note ' ) ,
}
_defaults = {
' date ' : lambda * args : time . strftime ( ' % Y- % m- %d ' ) ,
' user_id ' : lambda self , cr , uid , ctx : uid
}
account_asset_property_history ( )
class account_asset_board ( osv . osv ) :
_name = ' account.asset.board '
_description = ' Asset board '
_columns = {
' name ' : fields . char ( ' Asset name ' , size = 64 , required = True , select = 1 ) ,
2011-03-30 20:21:06 +00:00
' asset_id ' : fields . many2one ( ' account.asset.asset ' , ' Asset ' , required = True , select = 1 ) ,
2011-03-30 13:25:27 +00:00
' value_gross ' : fields . float ( ' Gross value ' , required = True , select = 1 ) ,
' value_asset ' : fields . float ( ' Asset Value ' , required = True , select = 1 ) ,
' value_asset_cumul ' : fields . float ( ' Cumul. value ' , required = True , select = 1 ) ,
' value_net ' : fields . float ( ' Net value ' , required = True , select = 1 ) ,
}
_auto = False
def init ( self , cr ) :
cr . execute ( """
create or replace view account_asset_board as (
select
min ( l . id ) as id ,
min ( l . id ) as asset_id ,
0.0 as value_gross ,
0.0 as value_asset ,
0.0 as value_asset_cumul ,
0.0 as value_net
from
account_move_line l
where
l . state < > ' draft ' and
l . asset_id = 3
) """ )
account_asset_board ( )
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: