1
# -*- encoding: utf-8 -*
2
##############################################################################
4
# Copyright (c) 2013 SF Soluciones.
5
# (http://www.sfsoluciones.com)
6
# contacto@sfsoluciones.com
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.
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.
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/>.
21
##############################################################################
23
from openerp.osv import osv, fields
27
class reconcile_ledger_report(osv.TransientModel):
28
_name = 'reconcile.ledger.report'
29
_description = 'Model to print partner ledger report'
31
def _get_fiscalyear(self, cr, uid, context=None):
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
40
def _get_all_journal(self, cr, uid, context=None):
41
return self.pool.get('account.journal').search(cr, uid ,[])
43
def onchange_filter(self, cr, uid, ids, filter='none', fiscalyear_id=False, context=None):
46
res['value'] = {'period_from_id': False, 'period_to_id': False, 'date_from': False ,'date_to': False}
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
52
SELECT * FROM (SELECT p.id
54
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
57
ORDER BY p.date_start ASC, p.special ASC
58
LIMIT 1) AS period_start
60
SELECT * FROM (SELECT p.id
62
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
64
AND p.date_start < NOW()
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}
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')],
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',
90
'fiscalyear_id': _get_fiscalyear,
91
'journal_ids': _get_all_journal,
92
'way': 'debit_to_credit',
94
'way': 'debit_to_credit'
97
def print_report(self, cr, uid, ids, context=None):
100
data = self.read(cr, uid, ids, [], context=context)[0]
102
'type': 'ir.actions.report.xml',
103
'report_name': 'reconcile.ledger.jasper.report',
108
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:-
b'\\ No newline at end of file'