mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Merge branch 'acsone-7.0-asset-management-fix3-sbi' into 7.0
This commit is contained in:
@@ -697,35 +697,13 @@ class account_asset_asset(orm.Model):
|
||||
table_i_start = table_i
|
||||
line_i_start = line_i
|
||||
|
||||
# check via initial_balance and accounting entries
|
||||
# if residual value corresponds with table
|
||||
# check if residual value corresponds with table
|
||||
# and adjust table when needed
|
||||
# we base the calculation on accounting entries
|
||||
# in stead of depreciation lines since this is
|
||||
# the most reliable source of information
|
||||
# (in previous versions of the account_asset module
|
||||
# there was no constraint to prevent inconsistencies
|
||||
# between depreciation lines and accounting entries).
|
||||
exp_acc_id = \
|
||||
asset.category_id.account_expense_depreciation_id.id
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT SUM(sq.amount) AS depreciated_value FROM
|
||||
(SELECT
|
||||
CASE
|
||||
WHEN (aadl.type = 'depreciate' AND aadl.init_entry = TRUE)
|
||||
THEN aadl.amount
|
||||
WHEN aml.account_id=%s
|
||||
THEN (COALESCE(aml.debit,0.0) - COALESCE(aml.credit,0.0))
|
||||
ELSE 0.0
|
||||
END AS amount
|
||||
FROM account_asset_depreciation_line aadl
|
||||
LEFT OUTER JOIN account_move am ON aadl.move_id=am.id
|
||||
LEFT OUTER JOIN account_move_line aml
|
||||
ON aml.move_id=am.id
|
||||
WHERE aadl.id IN %s) sq
|
||||
""",
|
||||
(exp_acc_id, tuple(posted_depreciation_line_ids)))
|
||||
"SELECT COALESCE(SUM(amount), 0.0) "
|
||||
"FROM account_asset_depreciation_line "
|
||||
"WHERE id IN %s",
|
||||
(tuple(posted_depreciation_line_ids),))
|
||||
res = cr.fetchone()
|
||||
depreciated_value = res[0]
|
||||
residual_amount = asset.asset_value - depreciated_value
|
||||
@@ -735,16 +713,13 @@ class account_asset_asset(orm.Model):
|
||||
entry = table[table_i_start]
|
||||
if entry['fy_id']:
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT COALESCE(SUM(aml.debit) -SUM(aml.credit), 0.0) AS depreciated_value
|
||||
FROM account_asset_depreciation_line aadl
|
||||
INNER JOIN account_move am ON aadl.move_id=am.id
|
||||
INNER JOIN account_move_line aml ON aml.move_id=am.id
|
||||
INNER JOIN account_period ap ON am.period_id=ap.id
|
||||
WHERE aadl.id in %s AND aml.account_id=%s AND ap.fiscalyear_id=%s
|
||||
""",
|
||||
"SELECT COALESCE(SUM(amount), 0.0) "
|
||||
"FROM account_asset_depreciation_line "
|
||||
"WHERE id in %s "
|
||||
" AND line_date >= %s and line_date <= %s",
|
||||
(tuple(posted_depreciation_line_ids),
|
||||
exp_acc_id, entry['fy_id']))
|
||||
entry['date_start'],
|
||||
entry['date_stop']))
|
||||
res = cr.fetchone()
|
||||
fy_amount_check = res[0]
|
||||
else:
|
||||
|
||||
@@ -23,12 +23,15 @@
|
||||
|
||||
import openerp.tests.common as common
|
||||
|
||||
import time
|
||||
|
||||
|
||||
class TestAssetManagement(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAssetManagement, self).setUp()
|
||||
self.asset_model = self.registry('account.asset.asset')
|
||||
self.dl_model = self.registry('account.asset.depreciation.line')
|
||||
|
||||
def test_1(self):
|
||||
""" Compute depreciation boards and post assets for first year,
|
||||
@@ -116,3 +119,90 @@ class TestAssetManagement(common.TransactionCase):
|
||||
self.assertEquals(vehicle.value_residual, 9000)
|
||||
self.assertEquals(fa.value_depreciated, 2500)
|
||||
self.assertEquals(fa.value_residual, 9000)
|
||||
|
||||
def test_2(self):
|
||||
""" prorata temporis depreciation """
|
||||
asset_id = self.asset_model.create(self.cr, self.uid, {
|
||||
'name': 'test asset',
|
||||
'category_id': self.ref('account_asset_management.'
|
||||
'account_asset_category_car_5Y'),
|
||||
'purchase_value': 3333,
|
||||
'salvage_value': 0,
|
||||
'date_start': time.strftime('%Y-07-07'),
|
||||
'method_number': 5,
|
||||
'method_period': 'month',
|
||||
'prorata': True,
|
||||
})
|
||||
asset = self.asset_model.browse(self.cr, self.uid, asset_id)
|
||||
self.asset_model.compute_depreciation_board(
|
||||
self.cr, self.uid, [asset.id])
|
||||
asset.refresh()
|
||||
self.assertEquals(asset.depreciation_line_ids[1].amount, 47.33)
|
||||
self.assertEquals(asset.depreciation_line_ids[2].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[3].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[4].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[5].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[6].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[-1].amount, 8.22)
|
||||
|
||||
def test_3(self):
|
||||
""" prorata temporis depreciation with initial value in
|
||||
previous year """
|
||||
asset_id = self.asset_model.create(self.cr, self.uid, {
|
||||
'name': 'test asset',
|
||||
'category_id': self.ref('account_asset_management.'
|
||||
'account_asset_category_car_5Y'),
|
||||
'purchase_value': 3333,
|
||||
'salvage_value': 0,
|
||||
'date_start': time.strftime('2013-07-07'),
|
||||
'method_number': 5,
|
||||
'method_period': 'month',
|
||||
'prorata': True,
|
||||
})
|
||||
self.dl_model.create(self.cr, self.uid, {
|
||||
'asset_id': asset_id,
|
||||
'amount': 325.08,
|
||||
'line_date': time.strftime('2013-12-31'),
|
||||
'type': 'depreciate',
|
||||
'init_entry': True,
|
||||
})
|
||||
asset = self.asset_model.browse(self.cr, self.uid, asset_id)
|
||||
self.assertEquals(len(asset.depreciation_line_ids), 2)
|
||||
self.asset_model.compute_depreciation_board(
|
||||
self.cr, self.uid, [asset.id])
|
||||
asset.refresh()
|
||||
self.assertEquals(asset.value_depreciated, 325.08)
|
||||
self.assertEquals(asset.depreciation_line_ids[2].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[3].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[-1].amount, 8.22)
|
||||
|
||||
def test_4(self):
|
||||
""" prorata temporis depreciation with initial value in
|
||||
curent year """
|
||||
asset_id = self.asset_model.create(self.cr, self.uid, {
|
||||
'name': 'test asset',
|
||||
'category_id': self.ref('account_asset_management.'
|
||||
'account_asset_category_car_5Y'),
|
||||
'purchase_value': 3333,
|
||||
'salvage_value': 0,
|
||||
'date_start': time.strftime('%Y-07-07'),
|
||||
'method_number': 5,
|
||||
'method_period': 'month',
|
||||
'prorata': True,
|
||||
})
|
||||
self.dl_model.create(self.cr, self.uid, {
|
||||
'asset_id': asset_id,
|
||||
'amount': 279.44,
|
||||
'line_date': time.strftime('%Y-11-30'),
|
||||
'type': 'depreciate',
|
||||
'init_entry': True,
|
||||
})
|
||||
asset = self.asset_model.browse(self.cr, self.uid, asset_id)
|
||||
self.assertEquals(len(asset.depreciation_line_ids), 2)
|
||||
self.asset_model.compute_depreciation_board(
|
||||
self.cr, self.uid, [asset.id])
|
||||
asset.refresh()
|
||||
self.assertEquals(asset.value_depreciated, 279.44)
|
||||
self.assertEquals(asset.depreciation_line_ids[2].amount, 45.64)
|
||||
self.assertEquals(asset.depreciation_line_ids[3].amount, 55.55)
|
||||
self.assertEquals(asset.depreciation_line_ids[-1].amount, 8.22)
|
||||
|
||||
Reference in New Issue
Block a user