~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to account_analytic_required/account.py

  • Committer: Sabrina Romero
  • Date: 2013-08-20 21:10:39 UTC
  • mto: (543.7.272 vaddddddd)
  • mto: This revision was merged to the branch mainline in revision 840.
  • Revision ID: sabrina@vauxoo.com-20130820211039-9jqrffvg2nz8q3vx

[ADD] Module product_do_merge added

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/
 
6
#    All Rights Reserved.
 
7
#    info Vauxoo (info@vauxoo.com)
 
8
############################################################################
 
9
#    Coded by: Luis Torres (luis_t@vauxoo.com)
 
10
############################################################################
 
11
#
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as
 
14
#    published by the Free Software Foundation, either version 3 of the
 
15
#    License, or (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
#
 
25
##############################################################################
 
26
from openerp.osv import osv, fields
 
27
from openerp.tools.translate import _
 
28
 
 
29
 
 
30
class account_account(osv.Model):
 
31
    _inherit = 'account.account'
 
32
 
 
33
    _columns = {
 
34
        'analytic_required': fields.boolean('Analytic Required'),
 
35
    }
 
36
 
 
37
 
 
38
class account_move(osv.Model):
 
39
    _inherit = 'account.move'
 
40
 
 
41
    def button_validate(self, cursor, user, ids, context=None):
 
42
        account_move_obj = self.pool.get('account.move.line')
 
43
        account_obj = self.pool.get('account.account')
 
44
        moves = account_move_obj.search(cursor, user, [('move_id', 'in', ids)])
 
45
        if moves:
 
46
            for move_id in moves:
 
47
                move = account_move_obj.browse(cursor, user, move_id)
 
48
                name_move = move.name or ''
 
49
                analytic_st = move.account_id and\
 
50
                    move.account_id.analytic_required or False
 
51
                if analytic_st is True:
 
52
                    account_move_id = move.account_id and\
 
53
                        move.account_id.id or False
 
54
                    analytic_acc_move = move.analytic_account_id and\
 
55
                        move.analytic_account_id.id or False
 
56
                    if analytic_acc_move is False:
 
57
                        raise osv.except_osv(_('Error'), _(
 
58
                            'Need add analytic account in move whit name '
 
59
                                             + name_move + '.'))
 
60
        res = super(account_move, self).button_validate(
 
61
            cursor, user, ids, context=context)
 
62
        return res