1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from lxml import etree
25
from osv import osv, fields
27
def roundNumber(num, r):
28
return round(num / r) * r
30
class asset_modify(osv.osv_memory):
31
_inherit = 'asset.modify'
32
_description = 'Modify Asset'
35
'revaluation': fields.boolean('Do revaluation?'),
36
'revaluation_amount': fields.float('Revaluation Amount'),
37
'revaluation_account': fields.many2one('account.account', 'Revaluation Account', domain=[('type','not in',('view','consolidation'))]),
38
'current_amount': fields.float('Current Gross Value'),
39
'change_depreciate': fields.boolean('Revaluation on depreciate?')
42
def default_get(self, cr, uid, fields, context=None):
43
""" To get default values for the object.
44
@param self: The object pointer.
45
@param cr: A database cursor
46
@param uid: ID of the user currently logged in
47
@param fields: List of fields for which we want default values
48
@param context: A standard dictionary
49
@return: A dictionary which of fields with values.
53
asset_obj = self.pool.get('account.asset.asset')
54
res = super(asset_modify, self).default_get(cr, uid, fields, context=context)
55
asset_id = context.get('active_id', False)
56
asset = asset_obj.browse(cr, uid, asset_id, context=context)
57
if 'current_amount' in fields:
58
res.update({'current_amount': asset.purchase_value})
61
def modify(self, cr, uid, ids, context=None):
62
""" Modifies the duration of asset for calculating depreciation
63
and maintains the history of old values.
64
@param self: The object pointer.
65
@param cr: A database cursor
66
@param uid: ID of the user currently logged in
67
@param ids: List of Ids
68
@param context: A standard dictionary
69
@return: Close the wizard.
73
asset_obj = self.pool.get('account.asset.asset')
74
history_obj = self.pool.get('account.asset.history')
75
asset_id = context.get('active_id', False)
76
asset = asset_obj.browse(cr, uid, asset_id, context=context)
77
data = self.browse(cr, uid, ids[0], context=context)
81
'method_time': asset.method_time,
82
'method_number': asset.method_number,
83
'method_period': asset.method_period,
84
'method_end': asset.method_end,
86
'date': time.strftime('%Y-%m-%d'),
88
'partner_id': asset.partner_id.id
91
'method_number': data.method_number,
92
'method_period': data.method_period,
93
'method_end': data.method_end,
95
if data.revaluation and data.revaluation_amount:
96
history_vals.update({'purchase_value': asset.purchase_value})
97
purchase_value = asset.purchase_value + data.revaluation_amount
98
asset_vals.update({'purchase_value':purchase_value})
99
history_obj.create(cr, uid, history_vals, context=context)
100
asset_obj.write(cr, uid, [asset_id], asset_vals, context=context)
101
# Дахин үнэлгээ хийх шаардлагатай эсэх
102
if data.revaluation and data.revaluation_amount:
103
period_id = self.pool.get('account.period').find(cr, uid, context=context)[0]
104
# Хөрөнгийн өртөг болон элэгдлийг нэмэгдүүлэх эсвэл хорогдуулах дүнг тооцоолох
105
revaluation_amount = data.revaluation_amount
106
cr.execute("SELECT round(SUM(abs(l.debit-l.credit))) AS amount "
107
"FROM account_move_line l "
108
"WHERE l.asset_id = %s and l.account_id = %s ",
109
(asset.id, asset.category_id.account_expense_depreciation_id.id))
115
move_obj = self.pool.get('account.move')
116
move_line_obj = self.pool.get('account.move.line')
117
asset_name_ref = asset.name_get()[0][1]
118
move_id = move_obj.create(cr, uid, {
120
'journal_id': asset.category_id.journal_id.id,
121
'period_id': period_id,
123
'date': time.strftime('%Y-%m-%d'),
124
'narration': data.note or (u'%s хөрөнгийн дахин үнэлгээ' % (asset_name_ref,))
127
# Анхны өртөгийн нэмэгдэл хорогдлын хувийг тодорхойлох
129
if data.change_depreciate and depreciated:
130
diff_factor = roundNumber(abs(revaluation_amount) / (asset.purchase_value * 0.01), 0.0001)
131
diff_depr = roundNumber(depreciated * (0.01 * diff_factor), 0.01)
132
# Хуримтлагдсан элэгдлийн дебит or кредит
133
move_line_obj.create(cr, uid, {
134
'name': asset_name_ref,
135
'debit': (revaluation_amount < 0 and diff_depr) or 0,
136
'credit': (revaluation_amount > 0 and diff_depr) or 0,
137
'account_id': asset.category_id.account_depreciation_id.id,
138
'date': time.strftime('%Y-%m-%d'),
140
'partner_id': asset.partner_id.id,
142
'period_id': period_id,
145
move_line_obj.create(cr, uid, {
146
'name': asset_name_ref,
147
'debit': (revaluation_amount > 0 and revaluation_amount) or 0,
148
'credit': (revaluation_amount < 0 and -revaluation_amount) or 0,
149
'account_id': asset.category_id.account_asset_id.id,
150
'date': time.strftime('%Y-%m-%d'),
151
'asset_id': asset.id,
154
'partner_id': asset.partner_id.id,
155
'period_id': period_id
157
# Дахин үнэлгээний нэмэгдүүлгэ, хасагдуулга
158
move_line_obj.create(cr, uid, {
159
'name': asset_name_ref,
160
'debit': (revaluation_amount < 0 and (-revaluation_amount - diff_depr)) or 0,
161
'credit': (revaluation_amount > 0 and (revaluation_amount - diff_depr)) or 0,
162
'account_id': data.revaluation_account.id,
163
'period_id': period_id,
164
'date': time.strftime('%Y-%m-%d'),
166
'partner_id': asset.partner_id.id,
170
# Журналын бичилтийг батлах
171
#move_obj.post(cr, uid, [move_id], context=context)
173
asset_obj.compute_depreciation_board(cr, uid, [asset_id], context=context)
174
return {'type': 'ir.actions.act_window_close'}
178
###############################################################################################
179
#Хөрөнгийн дахин үнэлгээний дүнгийн зөрүүгээр журналын бичилт хийнэ.
180
# Мөн элэгдэх хугацааг сунгаж түүх хөтөлнө.
181
# Анхны өртөгийг хувь тэнцүүлэн дахин үнэлэх жишээ. deprecaition_amount
182
# 1.0 сая төгрөгийн анхны өртөгтэй, 0.4 сая төгрөгийн хуримтлагдсан элэгдэлтэй
183
# тоног төхөөрөмжийн анхны өртгийг 2.0 сая төгрөгөөр дахин үнэлсэн гэвэл анхны
184
# өртөг 100 хувь нэмэгдсэн учир түүний хуримтлагдсан элэгдэл түүнтэй ижил хувиар
185
# буюу 100 хувь нэмэгдэж 0.8 сая төгрөг болно. Дахин үнэлгээний үр дүнг дараах
186
# байдлаар дансанд тусгана.
187
# Дт Хөрөнгө 1,000,000
188
# Кт Хуримтлагдсан элэгдэл 400,000
189
# Кт Дахин үнэлгээний нэмэгдэл 600,000
190
# Үлдэх өртөгийг дахин үнэлэх жишээ. gross_amount
191
# 1.0 сая төгрөгийн анхны өртөгтэй 0.4 сая төгрөгийн хуримтлагдсан элэгдэлтэй
192
# тоног төхөөрөмжийн үлдэгдэл өртөг буюу 0.6 сая өртөгийг 0.3 сая төгрөгөөр дахин
193
# үнэлсэн гэвэл дахин үнэлгээний үр дүнг дараах байдлаар дансанд тусгана.
194
# Дт Хуримтлагдсан элэгдэл 400.00
195
# Дт Дахин үнэлгээний нэмэгдэл 300,00
198
###############################################################################################
200
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'