~jo0thlt/sfsoluciones/mtf

« back to all changes in this revision

Viewing changes to sfs_reconcile_ledger_report/wizard/reconcile_ledger_report.py

  • Committer: contact at zbeanztech
  • Date: 2014-11-07 18:54:14 UTC
  • Revision ID: contact@zbeanztech.com-20141107185414-tzybvn7293tju4ce
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*
 
2
##############################################################################
 
3
#
 
4
#    Copyright (c) 2013 SF Soluciones.
 
5
#    (http://www.sfsoluciones.com)
 
6
#    contacto@sfsoluciones.com
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
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 General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from openerp.osv import osv, fields
 
24
 
 
25
import time
 
26
 
 
27
class reconcile_ledger_report(osv.TransientModel):
 
28
    _name = 'reconcile.ledger.report'
 
29
    _description = 'Model to print partner ledger report'
 
30
    
 
31
    def _get_fiscalyear(self, cr, uid, context=None):
 
32
        if context is None:
 
33
            context = {}
 
34
        now = time.strftime('%Y-%m-%d')
 
35
        company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
 
36
        domain = [('company_id', '=', company_id), ('date_start', '<', now), ('date_stop', '>', now)]
 
37
        fiscalyears = self.pool.get('account.fiscalyear').search(cr, uid, domain, limit=1)
 
38
        return fiscalyears and fiscalyears[0] or False
 
39
    
 
40
    def _get_all_journal(self, cr, uid, context=None):
 
41
        return self.pool.get('account.journal').search(cr, uid ,[])
 
42
    
 
43
    def onchange_filter(self, cr, uid, ids, filter='none', fiscalyear_id=False, context=None):
 
44
        res = {'value': {}}
 
45
        if filter == 'none':
 
46
            res['value'] = {'period_from_id': False, 'period_to_id': False, 'date_from': False ,'date_to': False}
 
47
        if filter == 'date':
 
48
            res['value'] = {'period_from_id': False, 'period_to_id': False, 'date_from': time.strftime('%Y-01-01'), 'date_to': time.strftime('%Y-%m-%d')}
 
49
        if filter == 'period' and fiscalyear_id:
 
50
            start_period = end_period = False
 
51
            cr.execute('''
 
52
                SELECT * FROM (SELECT p.id
 
53
                               FROM account_period p
 
54
                               LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
 
55
                               WHERE f.id = %s
 
56
                               AND p.special = false
 
57
                               ORDER BY p.date_start ASC, p.special ASC
 
58
                               LIMIT 1) AS period_start
 
59
                UNION ALL
 
60
                SELECT * FROM (SELECT p.id
 
61
                               FROM account_period p
 
62
                               LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
 
63
                               WHERE f.id = %s
 
64
                               AND p.date_start < NOW()
 
65
                               AND p.special = false
 
66
                               ORDER BY p.date_stop DESC
 
67
                               LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
 
68
            periods =  [i[0] for i in cr.fetchall()]
 
69
            if periods and len(periods) > 1:
 
70
                start_period = periods[0]
 
71
                end_period = periods[1]
 
72
            res['value'] = {'period_from_id': start_period, 'period_to_id': end_period, 'date_from': False, 'date_to': False}
 
73
        return res
 
74
    
 
75
    _columns = {
 
76
                'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year'),
 
77
                'way': fields.selection([('debit_to_credit', 'Customer Payments'),
 
78
                                         ('credit_to_debit', 'Supplier Payments')], 'Way'),
 
79
                'filter': fields.selection([('none', 'None'), ('date', 'Date'), ('period', 'Period')],
 
80
                                           'Filter By'),
 
81
                'date_from': fields.date('Date From'),
 
82
                'date_to': fields.date('Date To'),
 
83
                'period_from_id': fields.many2one('account.period', 'Period From'),
 
84
                'period_to_id': fields.many2one('account.period', 'Period To'),
 
85
                'journal_ids': fields.many2many('account.journal', 'journal_wizard_rel', 'wizard_id', 'journal_id',
 
86
                                                'Journal')
 
87
                }
 
88
 
 
89
    _defaults = {
 
90
                 'fiscalyear_id': _get_fiscalyear,
 
91
                 'journal_ids': _get_all_journal,
 
92
                 'way': 'debit_to_credit',
 
93
                 'filter': 'none',
 
94
                 'way': 'debit_to_credit'
 
95
                 }
 
96
    
 
97
    def print_report(self, cr, uid, ids, context=None):
 
98
        if context is None:
 
99
            context = {}
 
100
        data = self.read(cr, uid, ids, [], context=context)[0]
 
101
        return {
 
102
                'type': 'ir.actions.report.xml',
 
103
                'report_name': 'reconcile.ledger.jasper.report',
 
104
                'datas': data,
 
105
                'context': context
 
106
                }
 
107
    
 
108
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:-
 
 
b'\\ No newline at end of file'