2
#-*- encoding:utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 MSF, TeMPO Consulting.
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
22
from osv import fields, osv
24
from tools.translate import _
26
class account_bank_statement_line(osv.osv):
27
_inherit = "account.bank.statement.line"
28
_name = "account.bank.statement.line"
30
def _display_analytic_button(self, cr, uid, ids, name, args, context=None):
32
Return True for all element that correspond to some criteria:
33
- The entry state is draft
34
- The account is an expense account
37
for absl in self.browse(cr, uid, ids, context=context):
39
# False if st_line is hard posted
40
if absl.state == 'hard':
42
# False if account not an expense account
43
if absl.account_id.user_type.code not in ['expense']:
48
'analytic_distribution_id': fields.many2one('analytic.distribution', 'Analytic Distribution'),
49
'display_analytic_button': fields.function(_display_analytic_button, method=True, string='Display analytic button?', type='boolean', readonly=True,
50
help="This informs system that we can display or not an analytic button", store=False),
54
'display_analytic_button': lambda *a: True,
57
def button_analytic_distribution(self, cr, uid, ids, context=None):
59
Launch analytic distribution wizard from a statement line
64
if isinstance(ids, (int, long)):
67
absl = self.browse(cr, uid, ids[0], context=context)
68
amount = absl.amount * -1 or 0.0
69
# Search elements for currency
70
company_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
71
currency = absl.statement_id.journal_id.currency and absl.statement_id.journal_id.currency.id or company_currency
72
# Get analytic distribution id from this line
73
distrib_id = absl.analytic_distribution_id and absl.analytic_distribution_id.id or False
74
# Prepare values for wizard
76
'total_amount': amount,
77
'register_line_id': absl.id,
78
'currency_id': currency or False,
80
'account_id': absl.account_id and absl.account_id.id or False,
83
vals.update({'distribution_id': distrib_id,})
85
wiz_obj = self.pool.get('analytic.distribution.wizard')
86
wiz_id = wiz_obj.create(cr, uid, vals, context=context)
87
# Update some context values
94
'name': 'Analytic distribution',
95
'type': 'ir.actions.act_window',
96
'res_model': 'analytic.distribution.wizard',
104
account_bank_statement_line()
105
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: