1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
23 from tools.translate import _
26 class account_move_journal(osv.osv_memory):
27 _name = "account.move.journal"
28 _description = "Move journal"
30 def _get_period(self, cr, uid, context={}):
32 Return default account period value
34 ids = self.pool.get('account.period').find(cr, uid, context=context)
40 def _get_journal(self, cr, uid, context={}):
42 Return journal based on the journal type
47 journal_pool = self.pool.get('account.journal')
48 if context.get('journal_type', False):
49 jids = journal_pool.search(cr, uid, [('type','=', context.get('journal_type'))])
54 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
56 Returns views and fields for current model where view will depend on {view_type}.
57 @param cr: A database cursor
58 @param user: ID of the user currently logged in
59 @param view_id: list of fields, which required to read signatures
60 @param view_type: defines a view type. it can be one of (form, tree, graph, calender, gantt, search, mdx)
61 @param context: context arguments, like lang, time zone
62 @param toolbar: contains a list of reports, wizards, and links related to current model
64 @return: Returns a dict that contains definition for fields, views, and toolbars
67 res = super(account_move_journal, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
72 period_pool = self.pool.get('account.period')
73 journal_pool = self.pool.get('account.journal')
75 journal_id = self._get_journal(cr, uid, context)
76 period_id = self._get_period(cr, uid, context)
80 journal = journal_pool.read(cr, uid, [journal_id], ['name'])[0]['name']
86 period = period_pool.browse(cr, uid, [period_id], ['name'])[0]['name']
88 view = """<?xml version="1.0" encoding="utf-8"?>
89 <form string="Standard entries">
90 <separator string="Open a Journal Items !" colspan="4"/>
92 <label width="300" string="Journal : %s"/>
94 <label width="300" string="Period : %s"/>
96 <group colspan="4" col="4">
97 <label string ="" colspan="2"/>
98 <button icon="terp-gtk-go-back-rtl" string="Ok" name="action_open_window" type="object"/>
100 </form>""" % (str(journal), str(period))
107 def action_open_window(self, cr, uid, ids, context=None):
109 This function Open action move line window on given period and Journal/Payment Mode
110 @param cr: the current row, from the database cursor,
111 @param uid: the current user’s ID for security checks,
112 @param ids: account move journal’s ID or list of IDs
113 @return: dictionary of Open action move line window on given period and Journal/Payment Mode
116 period_pool = self.pool.get('account.journal.period')
117 data_pool = self.pool.get('ir.model.data')
118 journal_pool = self.pool.get('account.journal')
123 journal_id = self._get_journal(cr, uid, context)
124 period_id = self._get_period(cr, uid, context)
126 name = _("Journal Items")
128 ids = period_pool.search(cr, uid, [('journal_id', '=', journal_id), ('period_id', '=', period_id)], context=context)
131 journal = journal_pool.browse(cr, uid, journal_id)
132 period = self.pool.get('account.period').browse(cr, uid, period_id)
138 raise osv.except_osv(_('UserError'), _('This period is already closed !'))
140 company = period.company_id.id
143 'period_id': period_id,
144 'journal_id': journal_id,
145 'company_id': company
147 period_pool.create(cr, uid, res,context=context)
149 ids = period_pool.search(cr, uid, [('journal_id', '=', journal_id), ('period_id', '=', period_id)],context=context)
150 period = period_pool.browse(cr, uid, ids[0], context=context)
151 name = (period.journal_id.code or '') + ':' + (period.period_id.code or '')
153 result = data_pool._get_id(cr, uid, 'account', 'view_account_move_line_filter')
154 res_id = data_pool.browse(cr, uid, result, context=context).res_id
157 # 'domain': str([('journal_id', '=', journal_id), ('period_id', '=', period_id)]),
160 'view_mode': 'tree,graph,form',
161 'res_model': 'account.move.line',
163 'context': "{'visible_id':%s, 'journal_id': %d, 'search_default_journal_id':%d, 'search_default_period_id':%d}" % (journal_id, journal_id, journal_id, period_id),
164 'type': 'ir.actions.act_window',
165 'search_view_id': res_id
168 account_move_journal()
170 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: