~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to pxgo_cash_statement_analytic/cash_statement.py

  • Committer: Borja L.S.
  • Date: 2010-06-18 08:47:07 UTC
  • Revision ID: borjals@pexego.es-20100618084707-q2cf4nczjaqbx6fl
[ADD] pxgo_cash_statement_analytic: New module to create analytic entries from cash statements.

Extends the Cash Statements* to add support for analytic accounting.

(* See pxgo_cash_statement module)

A analytic account field will be added to cash statement line types, allowing
the user to preset analytic accounts for the line types.
Extends the Bank Statements to add support for analytic accounting.

Thanks to Igalia (http://www.igalia.com/) for sponsoring this module :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (C) 2004-2010 Pexego Sistemas Informáticos. All Rights Reserved
 
5
#
 
6
#    This program is free software: you can redistribute it and/or modify
 
7
#    it under the terms of the GNU General Public License as published by
 
8
#    the Free Software Foundation, either version 3 of the License, or
 
9
#    (at your option) any later version.
 
10
#
 
11
#    This program is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU General Public License
 
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
##############################################################################
 
20
"""
 
21
Extensions to the cash statements to add analytical accounting features.
 
22
"""
 
23
 
 
24
__authors__ = [
 
25
    "Borja López Soilán (Pexego) <borjals@pexego.es>"
 
26
]
 
27
 
 
28
from osv import osv, fields
 
29
 
 
30
 
 
31
class cash_statement_line_type(osv.osv):
 
32
    """
 
33
    Extend the Cash Statement Line Type to add the analytic account.
 
34
    """
 
35
    _inherit = 'account.bank.statement.line.type'
 
36
 
 
37
    _columns = {
 
38
        'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account'),
 
39
    }
 
40
 
 
41
cash_statement_line_type()
 
42
 
 
43
 
 
44
 
 
45
class cash_statement_line(osv.osv):
 
46
    """
 
47
    Extend the cash statement lines to add the analytic-related behaviour.
 
48
    """
 
49
    _inherit = 'account.bank.statement.line'
 
50
 
 
51
 
 
52
    def cash_line_on_change_line_type_id(self, cr, uid, line_id, partner_id, original_type, line_type_id, context=None):
 
53
        """
 
54
        Update the analytic account when the line type changes.
 
55
        """
 
56
        res = super(cash_statement_line, self).cash_line_on_change_line_type_id(cr, uid, line_id, partner_id, original_type, line_type_id, context=context)
 
57
 
 
58
        if line_type_id:
 
59
            line_type = self.pool.get('account.bank.statement.line.type').browse(cr, uid, line_type_id)
 
60
 
 
61
            #
 
62
            # Set the analytic account
 
63
            #
 
64
            if line_type.analytic_account_id:
 
65
                res['value']['analytic_account_id'] = line_type.analytic_account_id.id
 
66
        
 
67
        return res
 
68
cash_statement_line()
 
69