1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2008 Sandas. (http://www.sandas.eu) All Rights Reserved.
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
29
from osv import fields, osv
30
from base import base_delete_unit_test_records, base_get_default_currency
33
class personal_account_type(osv.osv):
34
_name = "personal.base.account.type"
35
_description = "Account Type"
38
'name': fields.char('Acc. Type Name', size=64, required=True, translate=True),
39
'sign': fields.selection([(-1, 'Negative'), (1, 'Positive')], 'Sign', required=True),
42
('name_uniq', 'unique (name)', 'Name must be unique !')
52
def try_create_demo(self, cr, uid):
54
#if self.search(cr, uid, []) == []:
55
# self.create(cr, uid, {'name': 'Begin balance', 'sign': 1})
56
# self.create(cr, uid, {'name': 'Asset', 'sign': 1})
57
# self.create(cr, uid, {'name': 'Liability', 'sign': -1})
58
# self.create(cr, uid, {'name': 'Income', 'sign': -1})
59
# self.create(cr, uid, {'name': 'Expense', 'sign': 1})
60
#self.pool.get('ir.model.data')._update(cr, uid, self._name, 'personal_base', {'name': 'Begin balance'}, 'TYPE_EQU_ID')
62
personal_account_type()
64
class personal_account(osv.osv):
65
_name = "personal.base.account"
66
_description = "Account"
69
# def _account_type_code_get(self, cr, uid, context={}):
70
# acc_type_obj = self.pool.get('personal.base.account.type')
71
# ids = acc_type_obj.search(cr, uid, [])
72
# res = acc_type_obj.read(cr, uid, ids, ['id', 'name'], context)
73
# return [(r['id'], r['name']) for r in res]
75
def _get_balance_fnc(self, cr, uid, ids, prop, unknow_none, context):
76
currency_pool = self.pool.get('res.currency')
78
cr.execute(("SELECT a.id, " \
79
"SUM(COALESCE(l.amount_base, 0)) " \
80
"FROM personal_base_account a " \
81
"LEFT JOIN personal_base_account_entry_line l " \
82
"ON (a.id=l.account_id) " \
83
"WHERE l.state = 'confirmed' " \
85
"GROUP BY a.id") % (','.join(map(str,ids)),))
88
for account_id, sum in cr.fetchall():
89
account = self.browse(cr, uid, account_id)
90
res[account_id] = currency_pool.round(cr, uid, account.currency_id, sum * account.type_id.sign)
92
#line_pool = self.pool.get('personal.base.account.entry.line')
94
# account = self.browse(cr, uid, id)
96
# for search_line_id in line_pool.search(cr, uid,
97
# [('account_id', '=', id),
98
# ('state', '=', 'confirmed'),]
100
# line = line_pool.browse(cr, uid, search_line_id)
101
# res[id] = res[id] + (line.amount_base * account.type_id.sign)
105
'user_id': fields.many2one('res.users', 'User', required=True),
106
'name': fields.char('Name', size=128, required=True, select=True),
107
'currency_id': fields.many2one('res.currency', 'Currency', required=True),
108
'type_id': fields.many2one('personal.base.account.type', 'Account Type', required=True),
109
'parent_id': fields.many2one('personal.base.account', 'Parent Code', select=True),
110
'child_ids': fields.one2many('personal.base.account', 'parent_id', 'Childs Codes'),
111
'note': fields.text('Note'),
112
'balance': fields.function(_get_balance_fnc, method=True, type="float", digits=(10,2), string='Balance'),
114
#fields for unit_test
115
'unit_test': fields.boolean(string='unit_test')
119
'user_id': lambda self, cr, uid, context: uid,
120
'currency_id': lambda self, cr, uid, context: base_get_default_currency(cr, uid, context),
121
'unit_test': lambda *a: False,
124
def search(self, cr, uid, args, offset=0, limit=2000, order=None, context=None, count=False):
125
args.append(('user_id','=',uid))
126
return osv.orm.orm.search(self, cr, uid, args, offset, limit, order,
130
def try_create_litas(self, cr, uid):
131
cur_pool = self.pool.get('res.currency')
132
cur_rate_pool = self.pool.get('res.currency.rate')
133
if cur_pool.search(cr, uid, [('code','=','LTL')]) == []:
134
cur_id = cur_pool.create(cr, uid, {'code': 'LTL', 'name': 'Litas',
135
'rounding': 0.01, 'accuracy': 4})
136
cur_rate_pool.create(cr, uid, {'currency_id': cur_id, 'rate': 3.4528,
137
'name': datetime.date(2002,2,2)})
139
def delete_unit_test_records(self, cr, uid):
140
base_delete_unit_test_records(self, cr, uid)