~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to account_move_validate_multi_wizard/wizard/wizard.py

  • Committer: jose at vauxoo
  • Date: 2013-07-26 17:56:51 UTC
  • mfrom: (543.7.115 addons-vauxoo)
  • Revision ID: jose@vauxoo.com-20130726175651-kr5u1apz6qpu54qy
 
[MEGER] Merge Serie 7 to add new features in this serie 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
#
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
 
6
#    All Rights Reserved
 
7
#
 
8
#    Coded by: Jorge Naranajo <jorge_nr@vauxoo.com>
 
9
#
 
10
#    This program is free software: you can redistribute it and/or modify
 
11
#    it under the terms of the GNU Affero General Public License as published by
 
12
#    the Free Software Foundation, either version 3 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    This program is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU Affero General Public License for more details.
 
19
#
 
20
#    You should have received a copy of the GNU Affero General Public License
 
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
#
 
23
 
 
24
 
 
25
from openerp.osv import fields, osv
 
26
from openerp.tools.translate import _
 
27
 
 
28
 
 
29
class account_move_multi_wizard(osv.TransientModel):
 
30
    _name = 'account.move.multi.wizard'
 
31
 
 
32
    def default_get(self, cr, uid, fields, context=None):
 
33
        if not context:
 
34
            context = {}
 
35
        moves = context.get('active_ids', False)
 
36
        res = super(account_move_multi_wizard, self).default_get(
 
37
            cr, uid, fields, context=context)
 
38
        res.update({'account_move_ids': moves})
 
39
        return res
 
40
 
 
41
    _columns = {
 
42
        'account_move_ids': fields.many2many('account.move',
 
43
                                             'account_move_wizard_rel', 'wiz_id', 'move_id'),
 
44
        'result': fields.text('Result'),
 
45
    }
 
46
 
 
47
    def validate_moves(self, cr, uid, ids, context=None):
 
48
        if not context:
 
49
            context = {}
 
50
        lista = []
 
51
        obj_account_move = self.pool.get('account.move')
 
52
        for form in self.browse(cr, uid, ids, context=context):
 
53
            for move in form.account_move_ids:
 
54
                try:
 
55
                    obj_account_move.button_validate(
 
56
                        cr, uid, [move.id], context=context)
 
57
                    cr.commit()
 
58
                except:
 
59
                    lista.append(move.id)
 
60
        if lista:
 
61
            pass
 
62
            __, xml_id = self.pool.get('ir.model.data').get_object_reference(
 
63
                cr, uid, 'account_move_validate_multi_wizard', 'account_move_validate_multi_wizard_unbalance')
 
64
            context.update(
 
65
                {'default_result': '''You cannot validate a non-balanced entry. Make sure you have configured payment terms properly.
 
66
The latest payment term line should be of the "Balance" type. \n\n In journal entries: %s''' % (lista)})
 
67
            return {
 
68
                'res_model': 'account.move.multi.wizard',
 
69
                'view_type': 'form',
 
70
                'view_mode': 'form',
 
71
                'view_id': xml_id,
 
72
                'context': context,
 
73
                'type': 'ir.actions.act_window',
 
74
                'target': 'new',
 
75
            }
 
76
        else:
 
77
            return {}