from datetime import datetime
from dateutil.relativedelta import relativedelta
-from osv import osv, fields
-import decimal_precision as dp
+from openerp.osv import fields, osv
+import openerp.addons.decimal_precision as dp
+from tools.translate import _
class account_asset_category(osv.osv):
_name = 'account.asset.category'
'name': fields.char('Name', size=64, required=True, select=1),
'note': fields.text('Note'),
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic account'),
- 'account_asset_id': fields.many2one('account.account', 'Asset Account', required=True),
- 'account_depreciation_id': fields.many2one('account.account', 'Depreciation Account', required=True),
- 'account_expense_depreciation_id': fields.many2one('account.account', 'Depr. Expense Account', required=True),
+ 'account_asset_id': fields.many2one('account.account', 'Asset Account', required=True, domain=[('type','=','other')]),
+ 'account_depreciation_id': fields.many2one('account.account', 'Depreciation Account', required=True, domain=[('type','=','other')]),
+ 'account_expense_depreciation_id': fields.many2one('account.account', 'Depr. Expense Account', required=True, domain=[('type','=','other')]),
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'method': fields.selection([('linear','Linear'),('degressive','Degressive')], 'Computation Method', required=True, help="Choose the method to use to compute the amount of depreciation lines.\n"\
" * Linear: Calculated on basis of: Gross Value / Number of Depreciations\n" \
- " * Degressive: Calculated on basis of: Remaining Value * Degressive Factor"),
- 'method_number': fields.integer('Number of Depreciations'),
+ " * Degressive: Calculated on basis of: Residual Value * Degressive Factor"),
+ 'method_number': fields.integer('Number of Depreciations', help="The number of depreciations needed to depreciate your asset"),
'method_period': fields.integer('Period Length', help="State here the time between 2 depreciations, in months", required=True),
'method_progress_factor': fields.float('Degressive Factor'),
'method_time': fields.selection([('number','Number of Depreciations'),('end','Ending Date')], 'Time Method', required=True,
_name = 'account.asset.asset'
_description = 'Asset'
+ def unlink(self, cr, uid, ids, context=None):
+ for asset in self.browse(cr, uid, ids, context=context):
+ if asset.account_move_line_ids:
+ raise osv.except_osv(_('Error!'), _('You cannot delete an asset that contains posted depreciation lines.'))
+ return super(account_asset_asset, self).unlink(cr, uid, ids, context=context)
+
def _get_period(self, cr, uid, context=None):
- periods = self.pool.get('account.period').find(cr, uid)
+ ctx = dict(context or {}, account_period_prefer_normal=True)
+ periods = self.pool.get('account.period').find(cr, uid, context=ctx)
if periods:
return periods[0]
else:
'amount': amount,
'asset_id': asset.id,
'sequence': i,
- 'name': str(asset.id) +'/' + str(i),
+ 'name': "%s/%s" %(i, undone_dotation_number),
'remaining_value': residual_amount,
'depreciated_value': (asset.purchase_value - asset.salvage_value) - (residual_amount + amount),
'depreciation_date': depreciation_date.strftime('%Y-%m-%d'),
else:
val['currency_id'] = company.currency_id.id
return {'value': val}
+
+ def onchange_purchase_salvage_value(self, cr, uid, ids, purchase_value, salvage_value, context=None):
+ val = {}
+ for asset in self.browse(cr, uid, ids, context=context):
+ if purchase_value:
+ val['value_residual'] = purchase_value - salvage_value
+ if salvage_value:
+ val['value_residual'] = purchase_value - salvage_value
+ return {'value': val}
_columns = {
'account_move_line_ids': fields.one2many('account.move.line', 'asset_id', 'Entries', readonly=True, states={'draft':[('readonly',False)]}),
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True, states={'draft':[('readonly',False)]}),
'method': fields.selection([('linear','Linear'),('degressive','Degressive')], 'Computation Method', required=True, readonly=True, states={'draft':[('readonly',False)]}, help="Choose the method to use to compute the amount of depreciation lines.\n"\
" * Linear: Calculated on basis of: Gross Value / Number of Depreciations\n" \
- " * Degressive: Calculated on basis of: Remaining Value * Degressive Factor"),
- 'method_number': fields.integer('Number of Depreciations', readonly=True, states={'draft':[('readonly',False)]}, help="Calculates Depreciation within specified interval"),
- 'method_period': fields.integer('Number of Months in a Period', required=True, readonly=True, states={'draft':[('readonly',False)]}, help="State here the time during 2 depreciations, in months"),
+ " * Degressive: Calculated on basis of: Residual Value * Degressive Factor"),
+ 'method_number': fields.integer('Number of Depreciations', readonly=True, states={'draft':[('readonly',False)]}, help="The number of depreciations needed to depreciate your asset"),
+ 'method_period': fields.integer('Number of Months in a Period', required=True, readonly=True, states={'draft':[('readonly',False)]}, help="The amount of time between two depreciations, in months"),
'method_end': fields.date('Ending Date', readonly=True, states={'draft':[('readonly',False)]}),
'method_progress_factor': fields.float('Degressive Factor', readonly=True, states={'draft':[('readonly',False)]}),
'value_residual': fields.function(_amount_residual, method=True, digits_compute=dp.get_precision('Account'), string='Residual Value'),
default = {}
if context is None:
context = {}
- default.update({'depreciation_line_ids': [], 'state': 'draft'})
+ default.update({'depreciation_line_ids': [], 'account_move_line_ids': [], 'history_ids': [], 'state': 'draft'})
return super(account_asset_asset, self).copy(cr, uid, id, default, context=context)
def _compute_entries(self, cr, uid, ids, period_id, context=None):
depreciation_obj = self.pool.get('account.asset.depreciation.line')
period = period_obj.browse(cr, uid, period_id, context=context)
depreciation_ids = depreciation_obj.search(cr, uid, [('asset_id', 'in', ids), ('depreciation_date', '<=', period.date_stop), ('depreciation_date', '>=', period.date_start), ('move_check', '=', False)], context=context)
+ if context is None:
+ context = {}
+ context.update({'depreciation_date':period.date_stop})
return depreciation_obj.create_move(cr, uid, depreciation_ids, context=context)
def create(self, cr, uid, vals, context=None):
_columns = {
'name': fields.char('Depreciation Name', size=64, required=True, select=1),
'sequence': fields.integer('Sequence', required=True),
- 'asset_id': fields.many2one('account.asset.asset', 'Asset', required=True),
+ 'asset_id': fields.many2one('account.asset.asset', 'Asset', required=True, ondelete='cascade'),
'parent_state': fields.related('asset_id', 'state', type='char', string='State of Asset'),
- 'amount': fields.float('Depreciation Amount', digits_compute=dp.get_precision('Account'), required=True),
- 'remaining_value': fields.float('Amount to Depreciate', digits_compute=dp.get_precision('Account'),required=True),
+ 'amount': fields.float('Current Depreciation', digits_compute=dp.get_precision('Account'), required=True),
+ 'remaining_value': fields.float('Next Period Depreciation', digits_compute=dp.get_precision('Account'),required=True),
'depreciated_value': fields.float('Amount Already Depreciated', required=True),
'depreciation_date': fields.date('Depreciation Date', select=1),
'move_id': fields.many2one('account.move', 'Depreciation Entry'),
created_move_ids = []
asset_ids = []
for line in self.browse(cr, uid, ids, context=context):
- depreciation_date = time.strftime('%Y-%m-%d')
- period_ids = period_obj.find(cr, uid, depreciation_date, context=context)
+ depreciation_date = context.get('depreciation_date') or time.strftime('%Y-%m-%d')
+ ctx = dict(context, account_period_prefer_normal=True)
+ period_ids = period_obj.find(cr, uid, depreciation_date, context=ctx)
company_currency = line.asset_id.company_id.currency_id.id
current_currency = line.asset_id.currency_id.id
context.update({'date': depreciation_date})
asset_name = line.asset_id.name
reference = line.name
move_vals = {
- 'name': asset_name,
'date': depreciation_date,
- 'ref': reference,
+ 'ref': "%s %s" %(line.asset_id.code or line.asset_id.name, line.name),
'period_id': period_ids and period_ids[0] or False,
'journal_id': line.asset_id.category_id.journal_id.id,
}
class account_move_line(osv.osv):
_inherit = 'account.move.line'
_columns = {
- 'asset_id': fields.many2one('account.asset.asset', 'Asset'),
+ 'asset_id': fields.many2one('account.asset.asset', 'Asset', ondelete="restrict"),
'entry_ids': fields.one2many('account.move.line', 'asset_id', 'Entries', readonly=True, states={'draft':[('readonly',False)]}),
}
help="The method to use to compute the dates and number of depreciation lines.\n"\
"Number of Depreciations: Fix the number of depreciation lines and the time between 2 depreciations.\n" \
"Ending Date: Choose the time between 2 depreciations and the date the depreciations won't go beyond."),
- 'method_number': fields.integer('Number of Depreciations'),
+ 'method_number': fields.integer('Number of Depreciations', help="The number of depreciations needed to depreciate your asset"),
'method_period': fields.integer('Period Length', help="Time in month between two depreciations"),
'method_end': fields.date('Ending date'),
'note': fields.text('Note'),