~vauxoo/openerp-mexico-localization/l10n_mx_facturae_ir_approval_sequence_dev_carlos

« back to all changes in this revision

Viewing changes to account_aged_partner_balance_vw/wizard/wizard_open_move_line.py

  • Committer: moylop260
  • Date: 2012-09-09 23:47:31 UTC
  • mfrom: (181.2.17 addons-mx-trunk)
  • Revision ID: moylop260@vauxoo.com-20120909234731-1tp1zww18ydo4r0r
[MERGE] Merge from trunk

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) 2011 Vauxoo - http://www.vauxoo.com/
6
 
#    All Rights Reserved.
7
 
#    info Vauxoo (info@vauxoo.com)
8
 
############################################################################
9
 
#    Coded by: moylop260 (moylop260@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
 
 
27
 
import wizard
28
 
import pooler
29
 
 
30
 
class wizard_open_move_line(wizard.interface):
31
 
    def _open_window(self, cr, uid, data, context={}):
32
 
        if not context:
33
 
            context = {}
34
 
        mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
35
 
        act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
36
 
        aged_partner_balance_vw_obj = pooler.get_pool(cr.dbname).get('account.aged.partner.balance.vw')
37
 
        partner_ids = [aged_partner_balance_vw.partner_id and aged_partner_balance_vw.partner_id.id or False for aged_partner_balance_vw in aged_partner_balance_vw_obj.browse(cr, uid, data['ids'], context=context)]
38
 
        #result = mod_obj._get_id(cr, uid, 'account', 'action_account_moves_all_a')
39
 
        result = mod_obj._get_id(cr, uid, 'account', 'action_move_line_select')
40
 
        id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
41
 
        result = act_obj.read(cr, uid, [id])[0]
42
 
        #result['context'] = {'partner_id': partner_ids}
43
 
        #result['domain'] = [('partner_id','in',partner_ids), ('account_id.type','=','receivable')]
44
 
        where_query = []
45
 
        days_due_start = context.get('days_due_start', False)
46
 
        if not days_due_start is False:
47
 
            where_query.append( 'days_due >= %d'%( days_due_start ) )
48
 
 
49
 
        days_due_end = context.get('days_due_end', False)
50
 
        if not days_due_end is False:
51
 
            where_query.append( 'days_due <= %d'%( days_due_end ) )
52
 
        #where_query_str = (where_query and ' WHERE ' or '') + ' AND '.join( where_query )
53
 
        where_query_str = (where_query and ' AND ' or '') + ' AND '.join( where_query )
54
 
        query = """SELECT l.id as id--, l.partner_id, l.company_id
55
 
            FROM account_move_line l
56
 
            INNER JOIN
57
 
               (
58
 
                   SELECT id, EXTRACT(DAY FROM (now() - COALESCE(lt.date_maturity,lt.date))) AS days_due
59
 
                   FROM account_move_line lt
60
 
               ) l2
61
 
               ON l2.id = l.id
62
 
            INNER JOIN account_account
63
 
               ON account_account.id = l.account_id
64
 
            INNER JOIN res_company
65
 
               ON account_account.company_id = res_company.id
66
 
            INNER JOIN account_move
67
 
               ON account_move.id = l.move_id
68
 
            WHERE account_account.active
69
 
                  AND (account_account.type IN ('receivable'))
70
 
                  AND (l.reconcile_id IS NULL)
71
 
                  AND account_move.state = 'posted'
72
 
               AND l.reconcile_id is null --and l.currency_id is null
73
 
       """+where_query_str
74
 
        cr.execute(query)
75
 
        res = cr.fetchall()
76
 
        move_ids = [r[0] for r in res]
77
 
        result['domain'] = [('partner_id','in',partner_ids), ('id','in',move_ids)]
78
 
        return result
79
 
 
80
 
    states = {
81
 
        'init': {
82
 
            'actions': [],
83
 
            'result': {'type': 'action', 'action': _open_window, 'state': 'end'}
84
 
        }
85
 
    }
86
 
wizard_open_move_line('wizard.open.move.line')
87
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: